From patchwork Thu Oct 25 20:09:44 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prasad Pandit X-Patchwork-Id: 989326 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42gz032g0xz9sCV for ; Fri, 26 Oct 2018 07:15:47 +1100 (AEDT) Received: from localhost ([::1]:56754 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFm2i-0001fo-Me for incoming@patchwork.ozlabs.org; Thu, 25 Oct 2018 16:15:44 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39626) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFm1v-0001Vp-7c for qemu-devel@nongnu.org; Thu, 25 Oct 2018 16:15:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gFlz0-00058w-Ad for qemu-devel@nongnu.org; Thu, 25 Oct 2018 16:11:59 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38986) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gFlz0-00056g-4t for qemu-devel@nongnu.org; Thu, 25 Oct 2018 16:11:54 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7B43A7DD26; Thu, 25 Oct 2018 20:11:52 +0000 (UTC) Received: from localhost.localdomain (ovpn-116-43.phx2.redhat.com [10.3.116.43]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7F8C95D9C5; Thu, 25 Oct 2018 20:11:47 +0000 (UTC) From: P J P To: Qemu Developers Date: Fri, 26 Oct 2018 01:39:44 +0530 Message-Id: <20181025200944.12113-1-ppandit@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Thu, 25 Oct 2018 20:11:52 +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: [Qemu-devel] [PATCH] lsi53c895a: check message length value 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: Fam Zheng , Paolo Bonzini , Ameya More , Prasad J Pandit Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Prasad J Pandit While writing a message in 'lsi_do_msgin', message length value in msg_len could be invalid, add check to avoid OOB access issue. Reported-by: Ameya More Signed-off-by: Prasad J Pandit --- hw/scsi/lsi53c895a.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/hw/scsi/lsi53c895a.c b/hw/scsi/lsi53c895a.c index d1e6534311..a266c5a113 100644 --- a/hw/scsi/lsi53c895a.c +++ b/hw/scsi/lsi53c895a.c @@ -205,7 +205,7 @@ typedef struct { /* Action to take at the end of a MSG IN phase. 0 = COMMAND, 1 = disconnect, 2 = DATA OUT, 3 = DATA IN. */ int msg_action; - int msg_len; + uint8_t msg_len; uint8_t msg[LSI_MAX_MSGIN_LEN]; /* 0 if SCRIPTS are running or stopped. * 1 if a Wait Reselect instruction has been issued. @@ -861,12 +861,15 @@ static void lsi_do_status(LSIState *s) static void lsi_do_msgin(LSIState *s) { - int len; + uint8_t len; trace_lsi_do_msgin(s->dbc, s->msg_len); s->sfbr = s->msg[0]; len = s->msg_len; if (len > s->dbc) len = s->dbc; + if (len > LSI_MAX_MSGIN_LEN) { + len = LSI_MAX_MSGIN_LEN; + } pci_dma_write(PCI_DEVICE(s), s->dnad, s->msg, len); /* Linux drivers rely on the last byte being in the SIDL. */ s->sidl = s->msg[len - 1]; @@ -2114,7 +2117,7 @@ static const VMStateDescription vmstate_lsi_scsi = { VMSTATE_INT32(carry, LSIState), VMSTATE_INT32(status, LSIState), VMSTATE_INT32(msg_action, LSIState), - VMSTATE_INT32(msg_len, LSIState), + VMSTATE_UINT8(msg_len, LSIState), VMSTATE_BUFFER(msg, LSIState), VMSTATE_INT32(waiting, LSIState),