f37f50b
------------------------------------------------------------------------
f37f50b
*From*: 	P J P
f37f50b
*Subject*: 	[Qemu-devel] [PATCH 2/2] scsi: check dma length before
f37f50b
reading scsi command(CVE-2016-4441)
f37f50b
*Date*: 	Thu, 19 May 2016 16:09:31 +0530
f37f50b
f37f50b
------------------------------------------------------------------------
f37f50b
f37f50b
From: Prasad J Pandit <address@hidden>
f37f50b
f37f50b
The 53C9X Fast SCSI Controller(FSC) comes with an internal 16-byte
f37f50b
FIFO buffer. It is used to handle command and data transfer.
f37f50b
Routine get_cmd() uses DMA to read scsi commands into this buffer.
f37f50b
Add check to validate DMA length against buffer size to avoid any
f37f50b
overrun.
f37f50b
f37f50b
Fixes CVE-2016-4441
f37f50b
Reported-by: Li Qiang <address@hidden>
f37f50b
f37f50b
Signed-off-by: Prasad J Pandit <address@hidden>
f37f50b
---
f37f50b
 hw/scsi/esp.c | 11 +++++++----
f37f50b
 1 file changed, 7 insertions(+), 4 deletions(-)
f37f50b
f37f50b
diff --git a/tools/qemu-xen-traditional/hw/esp.c b/tools/qemu-xen-traditional/hw/esp.c
f37f50b
index 01497e6..591c817 100644
f37f50b
--- a/tools/qemu-xen-traditional/hw/esp.c
f37f50b
+++ b/tools/qemu-xen-traditional/hw/esp.c
f37f50b
@@ -82,7 +82,7 @@ void esp_request_cancelled(SCSIRequest *req)
f37f50b
     }
f37f50b
 }
f37f50b
 
f37f50b
-static uint32_t get_cmd(ESPState *s, uint8_t *buf)
f37f50b
+static uint32_t get_cmd(ESPState *s, uint8_t *buf, uint8_t buflen)
f37f50b
 {
f37f50b
     uint32_t dmalen;
f37f50b
     int target;
f37f50b
@@ -92,6 +92,9 @@ static uint32_t get_cmd(ESPState *s, uint8_t *buf)
f37f50b
     target = s->wregs[ESP_WBUSID] & BUSID_DID;
f37f50b
     if (s->dma) {
f37f50b
         dmalen = s->rregs[ESP_TCLO] | (s->rregs[ESP_TCMID] << 8);
f37f50b
+        if (dmalen > buflen) {
f37f50b
+            return 0;
f37f50b
+        }
f37f50b
         s->dma_memory_read(s->dma_opaque, buf, dmalen);
f37f50b
     } else {
f37f50b
         dmalen = s->ti_size;
f37f50b
@@ -166,7 +169,7 @@ static void handle_satn(ESPState *s)
f37f50b
     uint8_t buf[32];
f37f50b
     int len;
f37f50b
 
f37f50b
-    len = get_cmd(s, buf);
f37f50b
+    len = get_cmd(s, buf, sizeof(buf));
f37f50b
     if (len)
f37f50b
         do_cmd(s, buf);
f37f50b
 }
f37f50b
@@ -192,7 +195,7 @@ static void handle_satn_stop(ESPState *s)
f37f50b
 
f37f50b
 static void handle_satn_stop(ESPState *s)
f37f50b
 {
f37f50b
-    s->cmdlen = get_cmd(s, s->cmdbuf);
f37f50b
+    s->cmdlen = get_cmd(s, s->cmdbuf, sizeof(s->cmdbuf));
f37f50b
     if (s->cmdlen) {
f37f50b
         DPRINTF("Set ATN & Stop: cmdlen %d\n", s->cmdlen);
f37f50b
         s->do_cmd = 1;
f37f50b
-- 
f37f50b
2.5.5
f37f50b