Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9F74AC53200 for ; Wed, 29 Jul 2026 23:19:58 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wpDYd-0002sw-CE; Wed, 29 Jul 2026 19:19:27 -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 1wpDYb-0002qe-8Q for qemu-devel@nongnu.org; Wed, 29 Jul 2026 19:19:25 -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 1wpDYZ-0008CF-8t for qemu-devel@nongnu.org; Wed, 29 Jul 2026 19:19:24 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1785367162; 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=DJwXA5fhz3UpXRGEEgItusWtCzmiEOpXllTR2/JfArM=; b=Wd/Ab3hOMv0TPaU1S8SlhT2rPsSR1c+OsePWD2weZM3LEPMZaj7n2V3St1oFAwe9VgDGiP WU2rcx2UHbC5k8MKxhMpO0qc/QMsa4yGHtfn4iWtyJURb0GddDatNvP0vI6Pu78jGCBnPZ eqCmiq4jtcdf7Eh//7TloL9jEmCOpkE= 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-186-luHvFdHeOtSZm-GsEIdfDQ-1; Wed, 29 Jul 2026 19:19:19 -0400 X-MC-Unique: luHvFdHeOtSZm-GsEIdfDQ-1 X-Mimecast-MFC-AGG-ID: luHvFdHeOtSZm-GsEIdfDQ_1785367158 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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 A391018002C7; Wed, 29 Jul 2026 23:19:17 +0000 (UTC) Received: from lenovo-t14s.redhat.corp (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id CDCBD300019F; Wed, 29 Jul 2026 23:19:13 +0000 (UTC) From: Laurent Vivier To: qemu-devel@nongnu.org Cc: Amit Shah , qemu-ppc@nongnu.org, Harsh Prateek Bora , Hanna Reitz , Nicholas Piggin , "Michael S. Tsirkin" , Kevin Wolf , Paolo Bonzini , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Fam Zheng , qemu-block@nongnu.org, Stefan Hajnoczi , Laurent Vivier , qemu-stable@nongnu.org, =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Thomas Huth Subject: [PATCH v3 2/7] hw/char/virtio-serial-bus: validate nr_active_ports from migration stream Date: Thu, 30 Jul 2026 01:18:59 +0200 Message-ID: <20260729231904.775331-3-lvivier@redhat.com> In-Reply-To: <20260729231904.775331-1-lvivier@redhat.com> References: <20260729231904.775331-1-lvivier@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 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: -36 X-Spam_score: -3.7 X-Spam_bar: --- X-Spam_report: (-3.7 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.58, 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org 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é Reviewed-by: Thomas Huth Acked-by: Michael S. Tsirkin --- Notes: v2: add error_setg() call with descriptive error message hw/char/virtio-serial-bus.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/hw/char/virtio-serial-bus.c b/hw/char/virtio-serial-bus.c index 87bfe51b6e93..4a5507e2f755 100644 --- a/hw/char/virtio-serial-bus.c +++ b/hw/char/virtio-serial-bus.c @@ -803,6 +803,12 @@ static int virtio_serial_load_device(VirtIODevice *vdev, QEMUFile *f, qemu_get_be32s(f, &nr_active_ports); + if (nr_active_ports > max_nr_ports) { + error_setg(errp, "Invalid number of active ports %u > %u", nr_active_ports, + max_nr_ports); + return -EINVAL; + } + if (nr_active_ports) { Error *local_err = NULL; -- 2.54.0