From nobody Wed Nov 5 02:31:21 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 1531763003625186.8312489632558; Mon, 16 Jul 2018 10:43:23 -0700 (PDT) Received: from localhost ([::1]:53030 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ff7Ws-0001vX-Go for importer@patchew.org; Mon, 16 Jul 2018 13:43:22 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34253) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ff7Rc-0007TI-0n for qemu-devel@nongnu.org; Mon, 16 Jul 2018 13:37:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ff7RX-0003AH-2D for qemu-devel@nongnu.org; Mon, 16 Jul 2018 13:37:55 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:33474 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ff7RW-00039T-Su for qemu-devel@nongnu.org; Mon, 16 Jul 2018 13:37:50 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 02DC8808255B; Mon, 16 Jul 2018 17:37:48 +0000 (UTC) Received: from dgilbert-t530.redhat.com (ovpn-117-185.ams2.redhat.com [10.36.117.185]) by smtp.corp.redhat.com (Postfix) with ESMTP id D19162156893; Mon, 16 Jul 2018 17:37:46 +0000 (UTC) From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, stefanha@redhat.com, mst@redhat.com, famz@redhat.com, amit@kernel.org Date: Mon, 16 Jul 2018 18:37:41 +0100 Message-Id: <20180716173743.133393-3-dgilbert@redhat.com> In-Reply-To: <20180716173743.133393-1-dgilbert@redhat.com> References: <20180716173743.133393-1-dgilbert@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Mon, 16 Jul 2018 17:37:48 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Mon, 16 Jul 2018 17:37:48 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'dgilbert@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH for 3.1 2/4] virtio: Check qemu_get_virtqueue_element returns 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: "Dr. David Alan Gilbert" Check calls to qemu_get_virtqueue_element for NULL and pass up the chain. Signed-off-by: Dr. David Alan Gilbert Reviewed-by: Cornelia Huck --- hw/block/virtio-blk.c | 4 ++++ hw/char/virtio-serial-bus.c | 4 ++++ hw/scsi/virtio-scsi.c | 4 ++++ 3 files changed, 12 insertions(+) diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c index 50b5c869e3..324c6b2b27 100644 --- a/hw/block/virtio-blk.c +++ b/hw/block/virtio-blk.c @@ -888,6 +888,10 @@ static int virtio_blk_load_device(VirtIODevice *vdev, = QEMUFile *f, } =20 req =3D qemu_get_virtqueue_element(vdev, f, sizeof(VirtIOBlockReq)= ); + if (!req) { + error_report("%s: Bad vq element %u", __func__, vq_idx); + return -EINVAL; + } virtio_blk_init_request(s, virtio_get_queue(vdev, vq_idx), req); req->next =3D s->rq; s->rq =3D req; diff --git a/hw/char/virtio-serial-bus.c b/hw/char/virtio-serial-bus.c index d2dd8ab502..e99dc9bf59 100644 --- a/hw/char/virtio-serial-bus.c +++ b/hw/char/virtio-serial-bus.c @@ -781,6 +781,10 @@ static int fetch_active_ports_list(QEMUFile *f, =20 port->elem =3D qemu_get_virtqueue_element(vdev, f, sizeof(VirtQueueElemen= t)); + if (!port->elem) { + error_report("%s: Bad vq element", __func__); + return -EINVAL; + } =20 /* * Port was throttled on source machine. Let's diff --git a/hw/scsi/virtio-scsi.c b/hw/scsi/virtio-scsi.c index 3aa99717e2..6301af76ad 100644 --- a/hw/scsi/virtio-scsi.c +++ b/hw/scsi/virtio-scsi.c @@ -207,6 +207,10 @@ static void *virtio_scsi_load_request(QEMUFile *f, SCS= IRequest *sreq) assert(n < vs->conf.num_queues); req =3D qemu_get_virtqueue_element(vdev, f, sizeof(VirtIOSCSIReq) + vs->cdb_size); + if (!req) { + error_report("%s: Bad vq element", __func__); + return NULL; + } virtio_scsi_init_req(s, vs->cmd_vqs[n], req); =20 if (virtio_scsi_parse_req(req, sizeof(VirtIOSCSICmdReq) + vs->cdb_size, --=20 2.17.1