From nobody Thu Nov 6 08:19:38 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1540583231468463.78691786265665; Fri, 26 Oct 2018 12:47:11 -0700 (PDT) Received: from localhost ([::1]:33963 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gG84b-00037d-Un for importer@patchew.org; Fri, 26 Oct 2018 15:47:09 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36032) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gG83e-0002od-8A for qemu-devel@nongnu.org; Fri, 26 Oct 2018 15:46:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gG83Z-00051g-Fy for qemu-devel@nongnu.org; Fri, 26 Oct 2018 15:46:10 -0400 Received: from mx1.redhat.com ([209.132.183.28]:37892) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gG83B-0004rw-5Q for qemu-devel@nongnu.org; Fri, 26 Oct 2018 15:46:05 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2AF023097082; Fri, 26 Oct 2018 19:45:30 +0000 (UTC) Received: from localhost.localdomain (ovpn-116-26.sin2.redhat.com [10.67.116.26]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A746967159; Fri, 26 Oct 2018 19:45:17 +0000 (UTC) From: P J P To: Qemu Developers Date: Sat, 27 Oct 2018 01:13:14 +0530 Message-Id: <20181026194314.18663-1-ppandit@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Fri, 26 Oct 2018 19:45:30 +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 v1] lsi53c895a: check message length value is valid 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: Thomas Huth , Fam Zheng , Prasad J Pandit , Ameya More , Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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. Signed-off-by: Prasad J Pandit --- hw/scsi/lsi53c895a.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) Update v1: add .post_load routine and an assert() call -> https://lists.gnu.org/archive/html/qemu-devel/2018-10/msg05730.html diff --git a/hw/scsi/lsi53c895a.c b/hw/scsi/lsi53c895a.c index d1e6534311..3a40e62853 100644 --- a/hw/scsi/lsi53c895a.c +++ b/hw/scsi/lsi53c895a.c @@ -861,12 +861,13 @@ static void lsi_do_status(LSIState *s) =20 static void lsi_do_msgin(LSIState *s) { - int len; + uint8_t len; trace_lsi_do_msgin(s->dbc, s->msg_len); s->sfbr =3D s->msg[0]; len =3D s->msg_len; if (len > s->dbc) len =3D s->dbc; + assert(len <=3D 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 =3D s->msg[len - 1]; @@ -2103,11 +2104,23 @@ static int lsi_pre_save(void *opaque) return 0; } =20 +static int lsi_post_load(void *opaque, int version_id) +{ + LSIState *s =3D opaque; + + if (s->msg_len < 0 || s->msg_len > LSI_MAX_MSGIN_LEN) { + return -EINVAL; + } + + return 0; +} + static const VMStateDescription vmstate_lsi_scsi =3D { .name =3D "lsiscsi", .version_id =3D 0, .minimum_version_id =3D 0, .pre_save =3D lsi_pre_save, + .post_load =3D lsi_post_load, .fields =3D (VMStateField[]) { VMSTATE_PCI_DEVICE(parent_obj, LSIState), =20 --=20 2.17.2