dcavalca / rpms / qemu

Forked from rpms/qemu a year ago
Clone

Blame 0025-scsi-esp-make-cmdbuf-big-enough-for-maximum-CDB-size.patch

cf91b1
From: Prasad J Pandit <pjp@fedoraproject.org>
cf91b1
Date: Thu, 16 Jun 2016 00:22:35 +0200
cf91b1
Subject: [PATCH] scsi: esp: make cmdbuf big enough for maximum CDB size
cf91b1
cf91b1
While doing DMA read into ESP command buffer 's->cmdbuf', it could
cf91b1
write past the 's->cmdbuf' area, if it was transferring more than 16
cf91b1
bytes.  Increase the command buffer size to 32, which is maximum when
cf91b1
's->do_cmd' is set, and add a check on 'len' to avoid OOB access.
cf91b1
cf91b1
Reported-by: Li Qiang <liqiang6-s@360.cn>
cf91b1
Signed-off-by: Prasad J Pandit <pjp@fedoraproject.org>
cf91b1
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
cf91b1
(cherry picked from commit 926cde5f3e4d2504ed161ed0cb771ac7cad6fd11)
cf91b1
---
cf91b1
 hw/scsi/esp.c         | 6 ++++--
cf91b1
 include/hw/scsi/esp.h | 3 ++-
cf91b1
 2 files changed, 6 insertions(+), 3 deletions(-)
cf91b1
cf91b1
diff --git a/hw/scsi/esp.c b/hw/scsi/esp.c
cf91b1
index 68d3e4d..b4601ad 100644
cf91b1
--- a/hw/scsi/esp.c
cf91b1
+++ b/hw/scsi/esp.c
cf91b1
@@ -248,6 +248,8 @@ static void esp_do_dma(ESPState *s)
cf91b1
     len = s->dma_left;
cf91b1
     if (s->do_cmd) {
cf91b1
         trace_esp_do_dma(s->cmdlen, len);
cf91b1
+        assert (s->cmdlen <= sizeof(s->cmdbuf) &&
cf91b1
+                len <= sizeof(s->cmdbuf) - s->cmdlen);
cf91b1
         s->dma_memory_read(s->dma_opaque, &s->cmdbuf[s->cmdlen], len);
cf91b1
         return;
cf91b1
     }
cf91b1
@@ -345,7 +347,7 @@ static void handle_ti(ESPState *s)
cf91b1
     s->dma_counter = dmalen;
cf91b1
 
cf91b1
     if (s->do_cmd)
cf91b1
-        minlen = (dmalen < 32) ? dmalen : 32;
cf91b1
+        minlen = (dmalen < ESP_CMDBUF_SZ) ? dmalen : ESP_CMDBUF_SZ;
cf91b1
     else if (s->ti_size < 0)
cf91b1
         minlen = (dmalen < -s->ti_size) ? dmalen : -s->ti_size;
cf91b1
     else
cf91b1
@@ -451,7 +453,7 @@ void esp_reg_write(ESPState *s, uint32_t saddr, uint64_t val)
cf91b1
         break;
cf91b1
     case ESP_FIFO:
cf91b1
         if (s->do_cmd) {
cf91b1
-            if (s->cmdlen < TI_BUFSZ) {
cf91b1
+            if (s->cmdlen < ESP_CMDBUF_SZ) {
cf91b1
                 s->cmdbuf[s->cmdlen++] = val & 0xff;
cf91b1
             } else {
cf91b1
                 trace_esp_error_fifo_overrun();
cf91b1
diff --git a/include/hw/scsi/esp.h b/include/hw/scsi/esp.h
cf91b1
index 6c79527..d2c4886 100644
cf91b1
--- a/include/hw/scsi/esp.h
cf91b1
+++ b/include/hw/scsi/esp.h
cf91b1
@@ -14,6 +14,7 @@ void esp_init(hwaddr espaddr, int it_shift,
cf91b1
 
cf91b1
 #define ESP_REGS 16
cf91b1
 #define TI_BUFSZ 16
cf91b1
+#define ESP_CMDBUF_SZ 32
cf91b1
 
cf91b1
 typedef struct ESPState ESPState;
cf91b1
 
cf91b1
@@ -31,7 +32,7 @@ struct ESPState {
cf91b1
     SCSIBus bus;
cf91b1
     SCSIDevice *current_dev;
cf91b1
     SCSIRequest *current_req;
cf91b1
-    uint8_t cmdbuf[TI_BUFSZ];
cf91b1
+    uint8_t cmdbuf[ESP_CMDBUF_SZ];
cf91b1
     uint32_t cmdlen;
cf91b1
     uint32_t do_cmd;
cf91b1