From nobody Tue Jan 21 07:40:27 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; 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 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 173643294976210.031780919230187; Thu, 9 Jan 2025 06:29:09 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id AF4E615C3; Thu, 9 Jan 2025 09:29:08 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 13E1C14E3; Thu, 9 Jan 2025 09:28:39 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id DAA0814A9; Thu, 9 Jan 2025 09:28:34 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 657341495 for ; Thu, 9 Jan 2025 09:28:34 -0500 (EST) 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-52-arv-F-hvMDeLoy2NQgNcQQ-1; Thu, 09 Jan 2025 09:28:32 -0500 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (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 7E08D1954191 for ; Thu, 9 Jan 2025 14:28:31 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.45.242.7]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id A4CE219560AA for ; Thu, 9 Jan 2025 14:28:30 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.5 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1736432914; 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=jjI/ZsT7pc/QPznlfE2kl4SOp96+Umke1K4ZwHRm/+w=; b=fejNxfXzY0sSl2Cvl+mMTRgacpX6h0kiencuLfM2w97WNA74DY52db0sQRl1v7C3pYr29V +ZKF6pf2jvi2BUESmkfLJSWCFNzYkAAWHj2NpNRVCCEw4uZcIUGCFjiGCgpYsSOaywuorC L96nQPYZTxehZFZGmh/gpdqrRdAjN9M= X-MC-Unique: arv-F-hvMDeLoy2NQgNcQQ-1 X-Mimecast-MFC-AGG-ID: arv-F-hvMDeLoy2NQgNcQQ From: Peter Krempa To: devel@lists.libvirt.org Subject: [PATCH 1/2] storage_file: Refuse qcow2 images with empty string as 'data_file' Date: Thu, 9 Jan 2025 15:28:26 +0100 Message-ID: <894f653fe3787f7204f68224adeec33e6357ca6b.1736432852.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: Xj5xMR2l3-LPFj9z3MH1RA0stPcnid-Cbzc6kI5CqpQ_1736432911 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: ISKRDUUKNMWXRQ334JDL7FQCXSSD7IWT X-Message-ID-Hash: ISKRDUUKNMWXRQ334JDL7FQCXSSD7IWT X-MailFrom: pkrempa@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1736432951183116600 Content-Type: text/plain; charset="utf-8" In certain buggy conditions qemu can create an image which has empty string stored as 'data_file'. While probing libvirt would consider the empty string as a relative file name and construct the path using the path of the parent image stripping the last component and appending the empty string. This results into attempting to using a directory as an image and thus the following error when attempting to start VM with such an image: error: unsupported configuration: storage type 'dir' requires use of stora= ge format 'fat' Reject empty strings passed in as 'data_file'. Note that we do not have the same problem with 'backing store' as an empty string there is interpreted as no backing file both by qemu and libvirt. Resolves: https://issues.redhat.com/browse/RHEL-70627 Signed-off-by: Peter Krempa --- src/storage_file/storage_source.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/storage_file/storage_source.c b/src/storage_file/storage_s= ource.c index 4612e710b0..fa59949cf2 100644 --- a/src/storage_file/storage_source.c +++ b/src/storage_file/storage_source.c @@ -557,6 +557,16 @@ virStorageSourceNewFromDataFile(virStorageSource *pare= nt) g_autoptr(virStorageSource) dataFile =3D NULL; int rc; + /* 'qemu-img' records an empty string as 'data_file' field in certain = buggy + * cases. Note that it can't happen for 'backing store' as absence of = the + * string equals to no backing store. */ + if (STREQ(parent->dataFileRaw, "")) { + virReportError(VIR_ERR_OPERATION_FAILED, + _("invalid empty data-file definition in '%1$s'"), + NULLSTR(parent->path)); + return NULL; + } + if ((rc =3D virStorageSourceNewFromChild(parent, parent->dataFileRaw, &dataFile)) < 0) --=20 2.47.1