dcavalca / rpms / qemu

Forked from rpms/qemu a year ago
Clone

Blame 0022-scsi-esp-check-buffer-length-before-reading-scsi-com.patch

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