cf91b1d
From: Prasad J Pandit <pjp@fedoraproject.org>
cf91b1d
Date: Tue, 31 May 2016 23:23:27 +0530
cf91b1d
Subject: [PATCH] scsi: esp: check buffer length before reading scsi command
cf91b1d
cf91b1d
The 53C9X Fast SCSI Controller(FSC) comes with an internal 16-byte
cf91b1d
FIFO buffer. It is used to handle command and data transfer.
cf91b1d
Routine get_cmd() in non-DMA mode, uses 'ti_size' to read scsi
cf91b1d
command into a buffer. Add check to validate command length against
cf91b1d
buffer size to avoid any overrun.
cf91b1d
cf91b1d
Reported-by: Li Qiang <liqiang6-s@360.cn>
cf91b1d
Signed-off-by: Prasad J Pandit <pjp@fedoraproject.org>
cf91b1d
Message-Id: <1464717207-7549-1-git-send-email-ppandit@redhat.com>
cf91b1d
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
cf91b1d
(cherry picked from commit d3cdc49138c30be1d3c2f83d18f85d9fdee95f1a)
cf91b1d
---
cf91b1d
 hw/scsi/esp.c | 3 +++
cf91b1d
 1 file changed, 3 insertions(+)
cf91b1d
cf91b1d
diff --git a/hw/scsi/esp.c b/hw/scsi/esp.c
cf91b1d
index 591c817..c2f6f8f 100644
cf91b1d
--- a/hw/scsi/esp.c
cf91b1d
+++ b/hw/scsi/esp.c
cf91b1d
@@ -98,6 +98,9 @@ static uint32_t get_cmd(ESPState *s, uint8_t *buf, uint8_t buflen)
cf91b1d
         s->dma_memory_read(s->dma_opaque, buf, dmalen);
cf91b1d
     } else {
cf91b1d
         dmalen = s->ti_size;
cf91b1d
+        if (dmalen > TI_BUFSZ) {
cf91b1d
+            return 0;
cf91b1d
+        }
cf91b1d
         memcpy(buf, s->ti_buf, dmalen);
cf91b1d
         buf[0] = buf[2] >> 5;
cf91b1d
     }