dcavalca / rpms / qemu

Forked from rpms/qemu a year ago
Clone

Blame 0008-esp-check-dma-length-before-reading-scsi-command-CVE.patch

f0208c
From: Prasad J Pandit <pjp@fedoraproject.org>
f0208c
Date: Thu, 19 May 2016 16:09:31 +0530
f0208c
Subject: [PATCH] esp: check dma length before reading scsi
f0208c
 command(CVE-2016-4441)
f0208c
f0208c
The 53C9X Fast SCSI Controller(FSC) comes with an internal 16-byte
f0208c
FIFO buffer. It is used to handle command and data transfer.
f0208c
Routine get_cmd() uses DMA to read scsi commands into this buffer.
f0208c
Add check to validate DMA length against buffer size to avoid any
f0208c
overrun.
f0208c
f0208c
Fixes CVE-2016-4441.
f0208c
f0208c
Reported-by: Li Qiang <liqiang6-s@360.cn>
f0208c
Cc: qemu-stable@nongnu.org
f0208c
Signed-off-by: Prasad J Pandit <pjp@fedoraproject.org>
f0208c
Message-Id: <1463654371-11169-3-git-send-email-ppandit@redhat.com>
f0208c
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
f0208c
(cherry picked from commit 6c1fef6b59563cc415f21e03f81539ed4b33ad90)
f0208c
---
f0208c
 hw/scsi/esp.c | 11 +++++++----
f0208c
 1 file changed, 7 insertions(+), 4 deletions(-)
f0208c
f0208c
diff --git a/hw/scsi/esp.c b/hw/scsi/esp.c
f0208c
index 01497e6..591c817 100644
f0208c
--- a/hw/scsi/esp.c
f0208c
+++ b/hw/scsi/esp.c
f0208c
@@ -82,7 +82,7 @@ void esp_request_cancelled(SCSIRequest *req)
f0208c
     }
f0208c
 }
f0208c
 
f0208c
-static uint32_t get_cmd(ESPState *s, uint8_t *buf)
f0208c
+static uint32_t get_cmd(ESPState *s, uint8_t *buf, uint8_t buflen)
f0208c
 {
f0208c
     uint32_t dmalen;
f0208c
     int target;
f0208c
@@ -92,6 +92,9 @@ static uint32_t get_cmd(ESPState *s, uint8_t *buf)
f0208c
         dmalen = s->rregs[ESP_TCLO];
f0208c
         dmalen |= s->rregs[ESP_TCMID] << 8;
f0208c
         dmalen |= s->rregs[ESP_TCHI] << 16;
f0208c
+        if (dmalen > buflen) {
f0208c
+            return 0;
f0208c
+        }
f0208c
         s->dma_memory_read(s->dma_opaque, buf, dmalen);
f0208c
     } else {
f0208c
         dmalen = s->ti_size;
f0208c
@@ -166,7 +169,7 @@ static void handle_satn(ESPState *s)
f0208c
         s->dma_cb = handle_satn;
f0208c
         return;
f0208c
     }
f0208c
-    len = get_cmd(s, buf);
f0208c
+    len = get_cmd(s, buf, sizeof(buf));
f0208c
     if (len)
f0208c
         do_cmd(s, buf);
f0208c
 }
f0208c
@@ -180,7 +183,7 @@ static void handle_s_without_atn(ESPState *s)
f0208c
         s->dma_cb = handle_s_without_atn;
f0208c
         return;
f0208c
     }
f0208c
-    len = get_cmd(s, buf);
f0208c
+    len = get_cmd(s, buf, sizeof(buf));
f0208c
     if (len) {
f0208c
         do_busid_cmd(s, buf, 0);
f0208c
     }
f0208c
@@ -192,7 +195,7 @@ static void handle_satn_stop(ESPState *s)
f0208c
         s->dma_cb = handle_satn_stop;
f0208c
         return;
f0208c
     }
f0208c
-    s->cmdlen = get_cmd(s, s->cmdbuf);
f0208c
+    s->cmdlen = get_cmd(s, s->cmdbuf, sizeof(s->cmdbuf));
f0208c
     if (s->cmdlen) {
f0208c
         trace_esp_handle_satn_stop(s->cmdlen);
f0208c
         s->do_cmd = 1;