Received: from eggs.gnu.org ([2001:4830:134:3::10]:45193) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bDp1u-0002ug-IO for qemu-devel@nongnu.org; Fri, 17 Jun 2016 04:21:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bDp1s-0007KM-7i for qemu-devel@nongnu.org; Fri, 17 Jun 2016 04:21:29 -0400 Received: from mail-wm0-x244.google.com ([2a00:1450:400c:c09::244]:35115) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bDp1s-0007KH-0C for qemu-devel@nongnu.org; Fri, 17 Jun 2016 04:21:28 -0400 Received: by mail-wm0-x244.google.com with SMTP id k184so16784404wme.2 for ; Fri, 17 Jun 2016 01:21:27 -0700 (PDT) Sender: Paolo Bonzini References: <1466012179-31839-1-git-send-email-ppandit@redhat.com> <20160617041952.GG29599@grmbl.mre> From: Paolo Bonzini Message-ID: Date: Fri, 17 Jun 2016 10:21:23 +0200 MIME-Version: 1.0 In-Reply-To: <20160617041952.GG29599@grmbl.mre> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH v4] scsi: esp: check length before dma read List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Amit Shah , P J P Cc: Li Qiang , Qemu Developers , Laszlo Ersek , Prasad J Pandit On 17/06/2016 06:19, Amit Shah wrote: > Hi, > > On (Wed) 15 Jun 2016 [23:06:19], P J P wrote: >> From: Prasad J Pandit >> >> While doing DMA read into ESP command buffer 's->cmdbuf', it could >> write past the 's->cmdbuf' area, if it was partially filled; >> ie. 's->cmdlen' wasn't set at the start of the buffer. >> Check 'len' to avoid OOB access. Also increase the command buffer >> size to 32, which is maximum when 's->do_cmd' is set. >> >> Reported-by: Li Qiang >> Signed-off-by: Prasad J Pandit > > [...] > >> diff --git a/include/hw/scsi/esp.h b/include/hw/scsi/esp.h >> index 6c79527..d2c4886 100644 >> --- a/include/hw/scsi/esp.h >> +++ b/include/hw/scsi/esp.h >> @@ -14,6 +14,7 @@ void esp_init(hwaddr espaddr, int it_shift, >> >> #define ESP_REGS 16 >> #define TI_BUFSZ 16 >> +#define ESP_CMDBUF_SZ 32 >> >> typedef struct ESPState ESPState; >> >> @@ -31,7 +32,7 @@ struct ESPState { >> SCSIBus bus; >> SCSIDevice *current_dev; >> SCSIRequest *current_req; >> - uint8_t cmdbuf[TI_BUFSZ]; >> + uint8_t cmdbuf[ESP_CMDBUF_SZ]; > > This was flagged as an incompatibility in the vmstate by a nightly run > of the vmstate checker: > > Section "esp" Description "esp" Field "cmdbuf" size mismatch: 16 , 32 > Section "dc390" Description "esp" Field "cmdbuf" size mismatch: 16 , 32 > Section "am53c974" Description "esp" Field "cmdbuf" size mismatch: 16 , 32 Oh, good catch. But from reading the spec the implementation was completely busted. Let's just drop handle_satn_stop, cmdbuf, cmdlen and do_cmd. Paolo