From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60022) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b7nrM-00061y-2n for qemu-devel@nongnu.org; Tue, 31 May 2016 13:53:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b7nrI-0006zT-0Q for qemu-devel@nongnu.org; Tue, 31 May 2016 13:53:43 -0400 Received: from mx1.redhat.com ([209.132.183.28]:48513) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b7nrH-0006zH-R4 for qemu-devel@nongnu.org; Tue, 31 May 2016 13:53:39 -0400 From: P J P Date: Tue, 31 May 2016 23:23:27 +0530 Message-Id: <1464717207-7549-1-git-send-email-ppandit@redhat.com> Subject: [Qemu-devel] [PATCH] scsi: check buffer length before reading scsi command List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Qemu Developers Cc: Paolo Bonzini , Li Qiang , Prasad J Pandit From: Prasad J Pandit The 53C9X Fast SCSI Controller(FSC) comes with an internal 16-byte FIFO buffer. It is used to handle command and data transfer. Routine get_cmd() in non-DMA mode, uses 'ti_size' to read scsi command into a buffer. Add check to validate command length against buffer size to avoid any overrun. Reported-by: Li Qiang Signed-off-by: Prasad J Pandit --- hw/scsi/esp.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/hw/scsi/esp.c b/hw/scsi/esp.c index 60c1b28..953027a 100644 --- a/hw/scsi/esp.c +++ b/hw/scsi/esp.c @@ -98,6 +98,9 @@ static uint32_t get_cmd(ESPState *s, uint8_t *buf, uint8_t buflen) s->dma_memory_read(s->dma_opaque, buf, dmalen); } else { dmalen = s->ti_size; + if (dmalen > TI_BUFSZ) { + return 0; + } memcpy(buf, s->ti_buf, dmalen); buf[0] = buf[2] >> 5; } -- 2.5.5