From nobody Thu Nov 12 15:08:23 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 38.145.34.151 as permitted sender) client-ip=38.145.34.151; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 38.145.34.151 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass(p=reject dis=none) header.from=lists.libvirt.org ARC-Seal: i=1; a=rsa-sha256; t=1794226597; cv=none; d=zohomail.com; s=zohoarc; b=RngFbhCos9vSEe+fBPzFNWuHv1mUBuEXLe6hqCEA63D1rkaBepqLqYR9yGHkmd2W2Y/Ha23I+x0O7cPDd2Q1KGDZ9PQNyqCLQxoHkl5rU1ah1WUMUFTArJjC3OY2ydeWnRJwi881xK0jYpJdtt1TOFHw0jbVgvjEeHMQRbR54Dc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1794226597; h=Content-Type:Content-Transfer-Encoding:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Owner:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:Subject:Subject:To:To:Message-Id:Cc; bh=f5AFY/0XayQGf/taNNCDoowbWNivgaW1jq3dsMkq2lI=; b=Qq4k/CrPaX6m2NEHjJ+vBDfCTUpB3wkGYqAMU8YwTEymKsLWATQPUfQZ6JPXpPk9Hs0u6Q5ECHBhiDmby7xwYkhtz2pBEo/miuvO0oiXWHV8qpcgjDscTIV28tWN1ur2qQhkycu1Z6U2xPEndk2PCWQNYcPZNINEQQP7MrkTA9c= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 38.145.34.151 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [38.145.34.151]) by mx.zohomail.com with SMTPS id 1794226597625475.88316699881454; Mon, 9 Nov 2026 04:16:37 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 993) id BEA9241BB3; Mon, 9 Nov 2026 07:16:35 -0500 (EST) Received: from [172.19.199.22] (unknown [10.16.107.18]) by lists.libvirt.org (Postfix) with ESMTP id E986341C4C; Mon, 9 Nov 2026 07:14:47 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 993) id A7F663F292; Mon, 9 Nov 2026 07:14:34 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (3072 bits) server-digest SHA256) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id CC90D3F30B for ; Mon, 9 Nov 2026 07:14:33 -0500 (EST) Received: from mx-prod-mc-06.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-534-Qy-6JS9SNi2zWvWtlDcdzQ-1; Mon, 09 Nov 2026 07:14:32 -0500 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-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 5AAE4180036E for ; Mon, 9 Nov 2026 12:14:31 +0000 (UTC) Received: from speedmetal.openshiftapps.com (unknown [10.44.22.3]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 84AAB30000E5 for ; Mon, 9 Nov 2026 12:14:30 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-3.4 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,SPF_HELO_PASS autolearn=unavailable autolearn_force=no version=4.0.1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1794226473; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=f5AFY/0XayQGf/taNNCDoowbWNivgaW1jq3dsMkq2lI=; b=d61TEN5Lb7doTY/5dGA0Q4G2ZOAj25gv/m+NhOaJakqrJaeTBRG22hPmg58IYDUAZpc5EN LWl7pOKb8MlgdSwpE8LbUkdQO8jzwhf3BTfqJA+48WfCJ9JW8UIzoEK+SpPZZ0ocu+y0iM YfejL8nJIiitxU/f1fkT64cMNAWY+3A= X-MC-Unique: Qy-6JS9SNi2zWvWtlDcdzQ-1 X-Mimecast-MFC-AGG-ID: Qy-6JS9SNi2zWvWtlDcdzQ_1794226471 To: devel@lists.libvirt.org Subject: [PATCH 1/3] virDomainDefParseMemory: Avoid leak of invalid hugepages bitmap Date: Mon, 9 Nov 2026 13:14:25 +0100 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: Jjoymlz54-k32wI1Jmm1HHZbaiGPcQGpayrmo0rxvVU_1794226471 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: I3USW5INNEHOTJMJTJOZNATAVZSTQPTB X-Message-ID-Hash: I3USW5INNEHOTJMJTJOZNATAVZSTQPTB X-MailFrom: pkrempa@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; header-match-devel.lists.libvirt.org-0; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Peter Krempa via Devel Reply-To: Peter Krempa X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1794226599966158500 Content-Type: text/plain; charset="utf-8" From: Peter Krempa Set 'nhugepages' directly to the potential maximum amount of hugepages as we'll parse less than that only on error at which point the function freeing the domain definition needs to clean up also the partially filled entries. Closes: https://gitlab.com/libvirt/libvirt/-/work_items/951 Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/conf/domain_conf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index f3179926c9..bb195264c4 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -19513,12 +19513,12 @@ virDomainDefParseMemory(virDomainDef *def, if (n) { def->mem.hugepages =3D g_new0(virDomainHugePage, n); + def->mem.nhugepages =3D n; for (i =3D 0; i < n; i++) { if (virDomainHugepagesParseXML(nodes[i], ctxt, &def->mem.hugepages[i]) < 0) return -1; - def->mem.nhugepages++; } VIR_FREE(nodes); --=20 2.56.0 From nobody Thu Nov 12 15:08:23 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 38.145.34.151 as permitted sender) client-ip=38.145.34.151; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 38.145.34.151 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass(p=reject dis=none) header.from=lists.libvirt.org ARC-Seal: i=1; a=rsa-sha256; t=1794226657; cv=none; d=zohomail.com; s=zohoarc; b=g5xoLO1fQqBz8kmz7YJ+M0UinXnb9/uP05DWTY3xINpQG85gUYsjxOzyVBOsEF602y/3SQ/lMrMcThNC6JFlYd0fzpGCkK4/WChCN31dJBL6AcbtK+o5Drrs++Uhy7xBX2RnL7803AMkvG30ZpxBuADVDBj0n2uTASS6sMZoYkA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1794226657; h=Content-Type:Content-Transfer-Encoding:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Owner:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:Subject:Subject:To:To:Message-Id:Cc; bh=GpUU9GErTOQiDNs6pnO+hKytOv/rSZs29UHN+JmBoG0=; b=SqC/4mTeZXLScIzxRYEpyCbsbS1gpRqOqa2pgQTabo44ibcmQYu2LMGOixsE3rp3ibLYuOKAOwLYJn1y3/ksgPgekc2KPEQDbRelEdpnQPKoZCyrGGm0zFqq9dv7ee9bERJf/51vj0Tf5F3JLGeH4lDVkW5zmh2NR4SHUnl1/NU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 38.145.34.151 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [38.145.34.151]) by mx.zohomail.com with SMTPS id 179422665733423.058100538707663; Mon, 9 Nov 2026 04:17:37 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 993) id 3EA6541BA6; Mon, 9 Nov 2026 07:17:36 -0500 (EST) Received: from [172.19.199.22] (unknown [10.16.107.18]) by lists.libvirt.org (Postfix) with ESMTP id 4C93441CC6; Mon, 9 Nov 2026 07:14:53 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 993) id 785503F292; Mon, 9 Nov 2026 07:14:35 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (3072 bits) server-digest SHA256) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id E7E203F289 for ; Mon, 9 Nov 2026 07:14:34 -0500 (EST) Received: from mx-prod-mc-01.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-540-6zx4cYGdPIS7J5TmSLPDhw-1; Mon, 09 Nov 2026 07:14:33 -0500 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-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 84DDA19560B1 for ; Mon, 9 Nov 2026 12:14:32 +0000 (UTC) Received: from speedmetal.openshiftapps.com (unknown [10.44.22.3]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id CB0F030000E5 for ; Mon, 9 Nov 2026 12:14:31 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.1 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,RCVD_IN_SBL_CSS,SPF_HELO_PASS autolearn=no autolearn_force=no version=4.0.1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1794226474; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=GpUU9GErTOQiDNs6pnO+hKytOv/rSZs29UHN+JmBoG0=; b=BOkd30ubCd3A7cLK6kT9wFoKu6NhrrYGQI37kY6czySeVWxZJos8M3S3S9dGvx4l4ThL/S RBU0vl0d0aEN9ammInVcvc4IB1xsMH2EtwFLAIvT8v4WLtxwUs4zI187ifduMCBceKSLE7 IX8CgtPHhvR4ulhoQqq+Ud3yaR+hHBI= X-MC-Unique: 6zx4cYGdPIS7J5TmSLPDhw-1 X-Mimecast-MFC-AGG-ID: 6zx4cYGdPIS7J5TmSLPDhw_1794226472 To: devel@lists.libvirt.org Subject: [PATCH 2/3] qcow2GetExtensions: Consider only 1 data file Date: Mon, 9 Nov 2026 13:14:26 +0100 Message-ID: <39299973ee0a266b65aab6a03ea079a9ffa9d23c.1794226373.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: ecOsnNSunG-Mur61tOkfamHkNYmC52B9B_zrfGLUPTI_1794226472 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: AKJ2K5QYY7AXFSE65MNE4LDT4GOI6VUW X-Message-ID-Hash: AKJ2K5QYY7AXFSE65MNE4LDT4GOI6VUW X-MailFrom: pkrempa@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; header-match-devel.lists.libvirt.org-0; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Peter Krempa via Devel Reply-To: Peter Krempa X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1794226658942158500 Content-Type: text/plain; charset="utf-8" From: Peter Krempa While technically the qcow2 header can have multiple data file extensions, such setup doesn't practically make sense. Parse only the first entry to close a potential memory leak when multiple such headers would cause our parser to overwrite the parsed string. Closes: https://gitlab.com/libvirt/libvirt/-/work_items/953 Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/storage_file/storage_file_probe.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/storage_file/storage_file_probe.c b/src/storage_file/stora= ge_file_probe.c index efe95bf818..a30528b02c 100644 --- a/src/storage_file/storage_file_probe.c +++ b/src/storage_file/storage_file_probe.c @@ -552,7 +552,8 @@ qcow2GetExtensions(virStorageSource *meta, } case QCOW2_HDR_EXTENSION_DATA_FILE_NAME: - if (virBitmapIsBitSet(meta->features, VIR_STORAGE_FILE_FEATURE= _DATA_FILE)) + if (!meta->dataFileRaw && + virBitmapIsBitSet(meta->features, VIR_STORAGE_FILE_FEATURE= _DATA_FILE)) meta->dataFileRaw =3D g_strndup(buf + offset, len); break; --=20 2.56.0 From nobody Thu Nov 12 15:08:23 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 38.145.34.151 as permitted sender) client-ip=38.145.34.151; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 38.145.34.151 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass(p=reject dis=none) header.from=lists.libvirt.org ARC-Seal: i=1; a=rsa-sha256; t=1794226707; cv=none; d=zohomail.com; s=zohoarc; b=kBcSbg1DVRe8kbaRk5pCRPnjg3T8fQPBUvGOqUaZEtZi1uNICn9ohOW9p0SBR2CbrddRWxItEsyWGVz3qtaoFPjSTTKaJC4ApYUNNOLK1DfQiSASWQprgzq3XYZfg4Lok2+8qzaZJAebaWt9nunDG4bCiZ/3/aH0bCBmi3ID61I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1794226707; h=Content-Type:Content-Transfer-Encoding:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Owner:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:Subject:Subject:To:To:Message-Id:Cc; bh=n9UOA+EOIrkyI1T+HoO9JZY0pmwBM2ufBtvXbgoIf98=; b=AUMgLHNcubVqfpLpVuSevix5SXx0N2xLToCblzSJ/Qxi/vitYv9VgXj7QKpK1WRc0gTFgFtc9srBr8I53llsB4ajnfE2sq1PC+BdXakdbQ7jjdvjiJt+TGET4BkPb1v1TKdJes2efilVAMfdIClp4KbJC4yRwBRCL4YFKYln1/c= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 38.145.34.151 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [38.145.34.151]) by mx.zohomail.com with SMTPS id 1794226707436427.1839221911431; Mon, 9 Nov 2026 04:18:27 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 993) id 60F8F41B3B; Mon, 9 Nov 2026 07:18:26 -0500 (EST) Received: from [172.19.199.22] (unknown [10.16.107.18]) by lists.libvirt.org (Postfix) with ESMTP id 76F7C41C46; Mon, 9 Nov 2026 07:15:23 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 993) id D471541BC3; Mon, 9 Nov 2026 07:15:14 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (3072 bits) server-digest SHA256) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id DC12C41BD7 for ; Mon, 9 Nov 2026 07:14:42 -0500 (EST) Received: from mx-prod-mc-06.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-127-rloZr4w7Pl6te5Vt-NqW4A-1; Mon, 09 Nov 2026 07:14:36 -0500 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-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 731E718002AD for ; Mon, 9 Nov 2026 12:14:33 +0000 (UTC) Received: from speedmetal.openshiftapps.com (unknown [10.44.22.3]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 022AD30000E5 for ; Mon, 9 Nov 2026 12:14:32 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-3.4 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL,SPF_HELO_PASS autolearn=unavailable autolearn_force=no version=4.0.1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1794226481; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=n9UOA+EOIrkyI1T+HoO9JZY0pmwBM2ufBtvXbgoIf98=; b=YGnlskTHfd328EAKkOsM41b9M0Dn+caNTu2KA5FLRrcmWq9LTHUuygp8ugFePJRaNEz34/ lVevrhdIAwnui+xlJ4e8f0xHylgyjXd83qry0EAVGfMEMC34gQd7+sgSUFIff8biiyl9Qn /khy61hCtavfNDNPhEWFKSiyVNTe8dE= X-MC-Unique: rloZr4w7Pl6te5Vt-NqW4A-1 X-Mimecast-MFC-AGG-ID: rloZr4w7Pl6te5Vt-NqW4A_1794226474 To: devel@lists.libvirt.org Subject: [PATCH 3/3] qcow2GetImageSpecific: Avoid undefined behaviour when shifting bits Date: Mon, 9 Nov 2026 13:14:27 +0100 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: 358QNQjwR065IlrbWX_aChX4vA7q4DHuDSTK0CoBsMY_1794226474 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: RLHDI3HMRAJZ3B2RSCIR4S3TBGTRHS5L X-Message-ID-Hash: RLHDI3HMRAJZ3B2RSCIR4S3TBGTRHS5L X-MailFrom: pkrempa@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; header-match-devel.lists.libvirt.org-0; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Peter Krempa via Devel Reply-To: Peter Krempa X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1794226709829158500 Content-Type: text/plain; charset="utf-8" From: Peter Krempa If the QCOW2 header had more than 64 cluster bits, our parser would do a bitshift operation to determine cluster size beyond the amount of bits in the variable which is undefined behaviour. Any normal implementation would then have the clusterSize variable to be 0 which is what we've wanted but to avoid relying on UB avoid the bitshift completely if the QCOW2 header specifies 64 or more cluster bits. Closes: https://gitlab.com/libvirt/libvirt/-/work_items/952 Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/storage_file/storage_file_probe.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/storage_file/storage_file_probe.c b/src/storage_file/stora= ge_file_probe.c index a30528b02c..7436ce34a5 100644 --- a/src/storage_file/storage_file_probe.c +++ b/src/storage_file/storage_file_probe.c @@ -671,7 +671,8 @@ qcow2GetImageSpecific(virStorageSource *meta, if (buf_size > (QCOWX_HDR_CLUSTER_BITS_OFFSET + 4)) { int clusterBits =3D virReadBufInt32BE(buf + QCOWX_HDR_CLUSTER_BITS= _OFFSET); - if (clusterBits > 0) + if (clusterBits > 0 && + clusterBits < sizeof(meta->clusterSize) * 8) meta->clusterSize =3D 1ULL << clusterBits; } --=20 2.56.0