From patchwork Wed Jun 1 13:10:16 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 9147407 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id DF43460757 for ; Wed, 1 Jun 2016 13:10:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D124925819 for ; Wed, 1 Jun 2016 13:10:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C61D2269DA; Wed, 1 Jun 2016 13:10:46 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 8611225819 for ; Wed, 1 Jun 2016 13:10:45 +0000 (UTC) Received: from localhost ([::1]:42118 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b85v1-0003by-TS for patchwork-qemu-devel@patchwork.kernel.org; Wed, 01 Jun 2016 09:10:43 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55515) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b85uo-0003br-GE for qemu-devel@nongnu.org; Wed, 01 Jun 2016 09:10:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b85uj-0000l5-AR for qemu-devel@nongnu.org; Wed, 01 Jun 2016 09:10:29 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43051) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b85uj-0000kl-4B for qemu-devel@nongnu.org; Wed, 01 Jun 2016 09:10:25 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A6F0A85543; Wed, 1 Jun 2016 13:10:23 +0000 (UTC) Received: from [10.32.176.49] (dhcp-176-49.mxp.redhat.com [10.32.176.49]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u51DAHmO028468 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Wed, 1 Jun 2016 09:10:18 -0400 To: P J P , Qemu Developers References: <1464717207-7549-1-git-send-email-ppandit@redhat.com> From: Paolo Bonzini Message-ID: <8c6531e9-6c5a-9e9a-e8d6-d9fd30d85b15@redhat.com> Date: Wed, 1 Jun 2016 15:10:16 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.1.0 MIME-Version: 1.0 In-Reply-To: <1464717207-7549-1-git-send-email-ppandit@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Wed, 01 Jun 2016 13:10:24 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: Re: [Qemu-devel] [PATCH] scsi: check buffer length before reading scsi command X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?Q?Herv=c3=a9_Poussineau?= , Li Qiang , Prasad J Pandit Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP On 31/05/2016 19:53, P J P wrote: > 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; > } > In theory this shouldn't happen, but I agree that it is better to be defensive. I'm queuing this patch. At least the following patch is needed to ensure that ti_size always matches ti_rptr/ti_wptr (Hervé, what do you think about it? should I resubmit it formally?). Also, things are more complicated than necessary due to ti_size being used for both DMA and FIFO transfers. Paolo diff --git a/hw/scsi/esp.c b/hw/scsi/esp.c index c2f6f8f..6407844 100644 --- a/hw/scsi/esp.c +++ b/hw/scsi/esp.c @@ -222,7 +222,7 @@ static void write_response(ESPState *s) } else { s->ti_size = 2; s->ti_rptr = 0; - s->ti_wptr = 0; + s->ti_wptr = 2; s->rregs[ESP_RFLAGS] = 2; } esp_raise_irq(s);