From nobody Sun Jul 12 00:42:31 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1783679422; cv=none; d=zohomail.com; s=zohoarc; b=HDNsakT/AwaIG3YY5UNlFiu9M46z5Y8aQTUWro/QVz1XC28BMnwGJU9c72ysc2DfBqmjxy2JDccAK63fGsF9zWf1+WxxNgwU09kWI3bih2ErGta9E5+vHI82Pen+oTXbWC2RgkdfLCQMaQT8DVkJKraAjXaAmxo7glJxaTdQxLs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1783679422; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=itSmT4dNttaxIulYwVEw4nRScMcnSaXcZ40WtiNAk/o=; b=jdmBZKt2BXw4pqha6LyFDBvTLbS5swQnvXqCyiGCGuTHnuol/7TUJdw6Hjf8PjQWFy5gNMXlLSMJsGtZMpZeOpLjQ1abZw6mVTJUpoL7XwY3R8En/+T4dQnv4OuNdcdYWqNbzIY7iQO2j3g6kjNmf+9q6hea/yDNlK03lb/KPxQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 178367942241416.331846390898477; Fri, 10 Jul 2026 03:30:22 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wi8Ty-0006Jh-4M; Fri, 10 Jul 2026 06:29:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wi8Tv-0006Hy-VH for qemu-devel@nongnu.org; Fri, 10 Jul 2026 06:29:19 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wi8Tu-0003yz-E8 for qemu-devel@nongnu.org; Fri, 10 Jul 2026 06:29:19 -0400 Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-65-jT_GNggRPXyat_l0cM7BjQ-1; Fri, 10 Jul 2026 06:29:09 -0400 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id E0F4E1956094; Fri, 10 Jul 2026 10:29:07 +0000 (UTC) Received: from lenovo-t14s.redhat.corp (headnet03.pony-001.prod.iad2.dc.redhat.com [10.2.32.114]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 4361D1800348; Fri, 10 Jul 2026 10:29:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1783679352; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=itSmT4dNttaxIulYwVEw4nRScMcnSaXcZ40WtiNAk/o=; b=HjvSotGmkS9IydfxgSxyvt8w0aBtPJpI7mLBo1OZZBf0NLPK4cXfagl9ha7Kl70D1PBfLR xEMRXEVzgJQgxWV9YFPvzzDj4SDiNTx794dFY0/z6ijRwMcW/znJmdy6MSPpkX6fsMO5ko MVjWdZskkEd4kEFGMnpJ1x0REcmEYS8= X-MC-Unique: jT_GNggRPXyat_l0cM7BjQ-1 X-Mimecast-MFC-AGG-ID: jT_GNggRPXyat_l0cM7BjQ_1783679348 From: Laurent Vivier To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Hanna Reitz , Fam Zheng , qemu-block@nongnu.org, "Michael S. Tsirkin" , Kevin Wolf , Laurent Vivier , Stefan Hajnoczi , Paolo Bonzini , Amit Shah , qemu-stable@nongnu.org, =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Thomas Huth Subject: [PATCH 1/3] hw/char/virtio-serial-bus: validate nr_active_ports from migration stream Date: Fri, 10 Jul 2026 12:28:57 +0200 Message-ID: <20260710102859.1967551-2-lvivier@redhat.com> In-Reply-To: <20260710102859.1967551-1-lvivier@redhat.com> References: <20260710102859.1967551-1-lvivier@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=lvivier@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 8 X-Spam_score: 0.8 X-Spam_bar: / X-Spam_report: (0.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.445, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1783679423209158500 The migration restore path reads nr_active_ports from the incoming stream and passes it directly to fetch_active_ports_list(), which uses it to size a heap allocation. A crafted migration stream can set this field to a very large value, causing QEMU to attempt a multi-gigabyte allocation and abort. Fix this by checking nr_active_ports against the configured max_virtserial_ports before calling fetch_active_ports_list(). Cc: qemu-stable@nongnu.org Fixes: 6663a1956eb6 ("virtio-serial-bus: Maintain guest and host port open/= close state") Resolves: https://gitlab.com/qemu-project/qemu/-/issues/3801 Signed-off-by: Laurent Vivier Reviewed-by: Daniel P. Berrang=C3=A9 Reviewed-by: Thomas Huth Acked-by: Michael S. Tsirkin --- hw/char/virtio-serial-bus.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/hw/char/virtio-serial-bus.c b/hw/char/virtio-serial-bus.c index c1973f0248fc..80f1b308aa53 100644 --- a/hw/char/virtio-serial-bus.c +++ b/hw/char/virtio-serial-bus.c @@ -804,6 +804,10 @@ static int virtio_serial_load_device(VirtIODevice *vde= v, QEMUFile *f, =20 qemu_get_be32s(f, &nr_active_ports); =20 + if (nr_active_ports > max_nr_ports) { + return -EINVAL; + } + if (nr_active_ports) { ret =3D fetch_active_ports_list(f, s, nr_active_ports); if (ret) { --=20 2.54.0 From nobody Sun Jul 12 00:42:31 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1783679423; cv=none; d=zohomail.com; s=zohoarc; b=JEkxC7oAol/RL9Pvv9wg/y7T7nDPNoghWlPQQ5BTvDFbMgktKjg7NAh0i1liG9DcZrELiUXo3PyhZWy/Yd4mOmoVpVdthilo7TKirTGOstfrYsb5+V8bZs7Fx20i0+THyU+vr7REfAEO+nsNvkEMP1R2jwCMu/LZDDxaQndPLIA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1783679423; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=V65MtKYOelNwC5jxg2RR9OmQsOPF4vi++7yT+hFE7y4=; b=I1/vnvg5KyoEUn7X+9GfSKIC16zoVhlKmS4z23BPxrC1gSQJylfkW1kI9JzguOP6Flf6l5nub/krrCSpWr80xToIY7/2BmJoq5HmmlOG3SUs1KTsDbMFDgAFCMjer6ZmlCnkIEUzCxfrlcb2sCZQubYEXcnVSQNkYNTzQAnG5Fo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1783679423055935.7490204452229; Fri, 10 Jul 2026 03:30:23 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wi8U1-0006Pc-7K; Fri, 10 Jul 2026 06:29:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wi8Tx-0006In-LW for qemu-devel@nongnu.org; Fri, 10 Jul 2026 06:29:21 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wi8Tu-0003zF-HT for qemu-devel@nongnu.org; Fri, 10 Jul 2026 06:29:21 -0400 Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-661-yIw7wIy5O1WoAA6iWGQrZA-1; Fri, 10 Jul 2026 06:29:12 -0400 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 6FC711800BDF; Fri, 10 Jul 2026 10:29:11 +0000 (UTC) Received: from lenovo-t14s.redhat.corp (headnet03.pony-001.prod.iad2.dc.redhat.com [10.2.32.114]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 4396A180056E; Fri, 10 Jul 2026 10:29:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1783679355; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=V65MtKYOelNwC5jxg2RR9OmQsOPF4vi++7yT+hFE7y4=; b=GojIxRm/LXS9BCQSHoFu/gSiKT6jxtF28b5t6DQp9do9hbZDE5UnMD9Kc2vQqhStrpigqE XMRUUbomd9baheTpYQUafQp1syy4+8XSmTte41ZEpI5NNEFkKpKNWw1CUarq86y5ro4CXA 8YW1/D+tzaMtcYVv0jLWlJ2/YEzfPjA= X-MC-Unique: yIw7wIy5O1WoAA6iWGQrZA-1 X-Mimecast-MFC-AGG-ID: yIw7wIy5O1WoAA6iWGQrZA_1783679351 From: Laurent Vivier To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Hanna Reitz , Fam Zheng , qemu-block@nongnu.org, "Michael S. Tsirkin" , Kevin Wolf , Laurent Vivier , Stefan Hajnoczi , Paolo Bonzini , Amit Shah , qemu-stable@nongnu.org Subject: [PATCH 2/3] hw/virtio: return NULL from qemu_get_virtqueue_element() on invalid state Date: Fri, 10 Jul 2026 12:28:58 +0200 Message-ID: <20260710102859.1967551-3-lvivier@redhat.com> In-Reply-To: <20260710102859.1967551-1-lvivier@redhat.com> References: <20260710102859.1967551-1-lvivier@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=lvivier@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.445, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1783679425320158500 Content-Type: text/plain; charset="utf-8" qemu_get_virtqueue_element() uses assert() to check that the in_num and out_num fields deserialized from the migration stream do not exceed VIRTQUEUE_MAX_SIZE. A crafted migration stream can set these fields to invalid values, hitting the assertion and aborting the destination QEMU process. Replace the assertions with a bounds check that returns NULL on failure. Update all callers (virtio-serial-bus, virtio-blk, virtio-scsi) to handle the NULL return and fail the migration gracefully. Cc: qemu-stable@nongnu.org Fixes: 6bdc21c050a2 ("virtio: fix up max size checks") Resolves: https://gitlab.com/qemu-project/qemu/-/issues/3802 Signed-off-by: Laurent Vivier --- hw/block/virtio-blk.c | 4 ++++ hw/char/virtio-serial-bus.c | 3 +++ hw/scsi/scsi-bus.c | 4 ++++ hw/scsi/virtio-scsi.c | 4 ++++ hw/virtio/virtio.c | 11 ++++------- 5 files changed, 19 insertions(+), 7 deletions(-) diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c index 6b92066aff4c..42c0f2553f18 100644 --- a/hw/block/virtio-blk.c +++ b/hw/block/virtio-blk.c @@ -1384,6 +1384,10 @@ static int virtio_blk_load_device(VirtIODevice *vdev= , QEMUFile *f, } =20 req =3D qemu_get_virtqueue_element(vdev, f, sizeof(VirtIOBlockReq)= ); + if (!req) { + return -EINVAL; + } + virtio_blk_init_request(s, virtio_get_queue(vdev, vq_idx), req); =20 WITH_QEMU_LOCK_GUARD(&s->rq_lock) { diff --git a/hw/char/virtio-serial-bus.c b/hw/char/virtio-serial-bus.c index 80f1b308aa53..4ed8840b2efe 100644 --- a/hw/char/virtio-serial-bus.c +++ b/hw/char/virtio-serial-bus.c @@ -763,6 +763,9 @@ static int fetch_active_ports_list(QEMUFile *f, =20 port->elem =3D qemu_get_virtqueue_element(vdev, f, sizeof(VirtQueueElemen= t)); + if (!port->elem) { + return -EINVAL; + } =20 /* * Port was throttled on source machine. Let's diff --git a/hw/scsi/scsi-bus.c b/hw/scsi/scsi-bus.c index dccb2f25b2af..96c4844374c5 100644 --- a/hw/scsi/scsi-bus.c +++ b/hw/scsi/scsi-bus.c @@ -1915,6 +1915,10 @@ static int get_scsi_requests(QEMUFile *f, void *pv, = size_t size, req->retry =3D (sbyte =3D=3D 1); if (bus->info->load_request) { req->hba_private =3D bus->info->load_request(f, req); + if (!req->hba_private) { + scsi_req_unref(req); + return -EINVAL; + } } if (req->ops->load_request) { req->ops->load_request(f, req); diff --git a/hw/scsi/virtio-scsi.c b/hw/scsi/virtio-scsi.c index 6c7376801190..8dd0b88a30c4 100644 --- a/hw/scsi/virtio-scsi.c +++ b/hw/scsi/virtio-scsi.c @@ -274,6 +274,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) { + return NULL; + } + virtio_scsi_init_req(s, vs->cmd_vqs[n], req); =20 if (virtio_scsi_parse_req(req, sizeof(VirtIOSCSICmdReq) + vs->cdb_size, diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index f4d86a365530..7bccfdde33e7 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -2167,13 +2167,10 @@ void *qemu_get_virtqueue_element(VirtIODevice *vdev= , QEMUFile *f, size_t sz) =20 qemu_get_buffer(f, (uint8_t *)&data, sizeof(VirtQueueElementOld)); =20 - /* TODO: teach all callers that this can fail, and return failure inst= ead - * of asserting here. - * This is just one thing (there are probably more) that must be - * fixed before we can allow NDEBUG compilation. - */ - assert(ARRAY_SIZE(data.in_addr) >=3D data.in_num); - assert(ARRAY_SIZE(data.out_addr) >=3D data.out_num); + if (data.in_num > ARRAY_SIZE(data.in_addr) || + data.out_num > ARRAY_SIZE(data.out_addr)) { + return NULL; + } =20 elem =3D virtqueue_alloc_element(sz, data.out_num, data.in_num); elem->index =3D data.index; --=20 2.54.0 From nobody Sun Jul 12 00:42:31 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1783679422; cv=none; d=zohomail.com; s=zohoarc; b=GPi8kEU0vnoS9rbUFpb7r/H+tUNam97i/dU69Wc4bEpId3o4EYKo0aYkMa1dHq3uqt3E7T/bU5WHsQm4qRa+DvLxwZJkxI3Y0NHWeWfWYIyQg7T69LUNyRS2DkfrtGWXDej2xJ2TuVZgnh3lagV6UxzUdhdKrwgG9u1Acv9gO68= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1783679422; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=FCG9HAyi1whBiC4OnqxMq1aPNT1mXuU+57B+pSBea3g=; b=XTHgrlDkxJYJCLnAahfJhB1z4G5YbxsxW/d0Dcx3da9zr2g8VyFLV3Yq5h5liHeHN+weQx03FOJTuF28bDR5K0ruAD2+ewbujFmmuv0fouB3x28Fo2PFZKDfsSLogDkhBg7tWPQf6xG5QDrXUe8ypWR8WCQTfnUYUyzA1knGHY4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1783679422642356.47839983814595; Fri, 10 Jul 2026 03:30:22 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wi8Ty-0006Jp-KZ; Fri, 10 Jul 2026 06:29:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wi8Tx-0006Ic-Ey for qemu-devel@nongnu.org; Fri, 10 Jul 2026 06:29:21 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wi8Tv-0003zK-BY for qemu-devel@nongnu.org; Fri, 10 Jul 2026 06:29:21 -0400 Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-90-zxZodgI0NzCwXSgfi3aT7A-1; Fri, 10 Jul 2026 06:29:16 -0400 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id BA8CA1956041; Fri, 10 Jul 2026 10:29:15 +0000 (UTC) Received: from lenovo-t14s.redhat.corp (headnet03.pony-001.prod.iad2.dc.redhat.com [10.2.32.114]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id C7830180056E; Fri, 10 Jul 2026 10:29:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1783679358; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=FCG9HAyi1whBiC4OnqxMq1aPNT1mXuU+57B+pSBea3g=; b=eBpRJYMdNDqCEt4wfL82h0huxZxHVZBwpVO+2iBoc3zUnv7EPC5Md1p4uAIs/e85uZabH0 3CJrorr+Q6LQVfQ2+U4X6Tk1bY7/XTMyYRp8WLSJ0l2ixdF89otjqfRG1VEb2Sgq8ZumAh VB5668O4+8uHM7zGsQaFBh3WtfzUagI= X-MC-Unique: zxZodgI0NzCwXSgfi3aT7A-1 X-Mimecast-MFC-AGG-ID: zxZodgI0NzCwXSgfi3aT7A_1783679355 From: Laurent Vivier To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Hanna Reitz , Fam Zheng , qemu-block@nongnu.org, "Michael S. Tsirkin" , Kevin Wolf , Laurent Vivier , Stefan Hajnoczi , Paolo Bonzini , Amit Shah , qemu-stable@nongnu.org Subject: [PATCH 3/3] hw/scsi/virtio-scsi: harden virtio_scsi_load_request() against invalid stream Date: Fri, 10 Jul 2026 12:28:59 +0200 Message-ID: <20260710102859.1967551-4-lvivier@redhat.com> In-Reply-To: <20260710102859.1967551-1-lvivier@redhat.com> References: <20260710102859.1967551-1-lvivier@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=lvivier@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 8 X-Spam_score: 0.8 X-Spam_bar: / X-Spam_report: (0.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.445, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1783679423249158500 Content-Type: text/plain; charset="utf-8" virtio_scsi_load_request() uses assert() and exit(1) for conditions that can be triggered by a crafted migration stream: an out-of-range queue index, a malformed SCSI request, or a command mode mismatch. Replace these with proper error returns so the migration fails gracefully instead of aborting the destination QEMU process. Cc: qemu-stable@nongnu.org Fixes: 5db1764cc1f6 ("virtio-scsi: add migration support") Fixes: d2ad7dd46e72 ("virtio-scsi: add multiqueue capability") Fixes: 36b15c79aa1b ("virtio-scsi: start preparing for any_layout") Signed-off-by: Laurent Vivier --- hw/scsi/virtio-scsi.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/hw/scsi/virtio-scsi.c b/hw/scsi/virtio-scsi.c index 8dd0b88a30c4..b34cda8fd85a 100644 --- a/hw/scsi/virtio-scsi.c +++ b/hw/scsi/virtio-scsi.c @@ -271,7 +271,10 @@ static void *virtio_scsi_load_request(QEMUFile *f, SCS= IRequest *sreq) uint32_t n; =20 qemu_get_be32s(f, &n); - assert(n < vs->conf.num_queues); + if (n >=3D vs->conf.num_queues) { + return NULL; + } + req =3D qemu_get_virtqueue_element(vdev, f, sizeof(VirtIOSCSIReq) + vs->cdb_size); if (!req) { @@ -283,14 +286,19 @@ static void *virtio_scsi_load_request(QEMUFile *f, SC= SIRequest *sreq) if (virtio_scsi_parse_req(req, sizeof(VirtIOSCSICmdReq) + vs->cdb_size, sizeof(VirtIOSCSICmdResp) + vs->sense_size) = < 0) { error_report("invalid SCSI request migration data"); - exit(1); + virtio_scsi_free_req(req); + return NULL; } =20 scsi_req_ref(sreq); req->sreq =3D sreq; - if (req->sreq->cmd.mode !=3D SCSI_XFER_NONE) { - assert(req->sreq->cmd.mode =3D=3D req->mode); + if (req->sreq->cmd.mode !=3D SCSI_XFER_NONE && + req->sreq->cmd.mode !=3D req->mode) { + scsi_req_unref(sreq); + virtio_scsi_free_req(req); + return NULL; } + return req; } =20 --=20 2.54.0