From nobody Wed Nov 27 06:49:08 2024 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 1723819401501583.6648527092774; Fri, 16 Aug 2024 07:43:21 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 50D1514E0; Fri, 16 Aug 2024 10:43:20 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 01F0912FE; Fri, 16 Aug 2024 10:42:47 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 126FB1275; Fri, 16 Aug 2024 10:42:41 -0400 (EDT) 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 97D3D1274 for ; Fri, 16 Aug 2024 10:42:40 -0400 (EDT) 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-578-FcSmCN-PMDaZTc2OLsZ0wQ-1; Fri, 16 Aug 2024 10:42:39 -0400 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (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 2B81D19560A3 for ; Fri, 16 Aug 2024 14:42:38 +0000 (UTC) Received: from speedmetal.lan (unknown [10.45.242.12]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 025E51955F38 for ; Fri, 16 Aug 2024 14:42:36 +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.6 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE 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=1723819360; 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=NNN5DsADhp+n4/xmR6iFJlJq9ypMwOYyuWZZ9Nus874=; b=NkolJwQtLoF3CxbuGjmfNYr9gg2FUnnefaSpi9cMtufh+KeVGsw7ycLHGnmHsU00ltB44U PE0ftABcZ1gVU6ZgmMtjnRMtFISpavsmeC4haIqTFb+DbX4AJiPbMVU718cf6DMv88nDI7 l/4poImSZJ3x6r9NmHA6+1p0f6DFbIE= X-MC-Unique: FcSmCN-PMDaZTc2OLsZ0wQ-1 From: Peter Krempa To: devel@lists.libvirt.org Subject: [PATCH 1/2] qemu: block: Allow NULL 'data' in 'qemuBlockStorageSourceChainDetach' Date: Fri, 16 Aug 2024 16:42:32 +0200 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: MP4MYVMAAO3VPVBF3OZQEQSMCF4KCR3S X-Message-ID-Hash: MP4MYVMAAO3VPVBF3OZQEQSMCF4KCR3S 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: 1723819401998116600 Content-Type: text/plain; charset="utf-8" Some code paths, such as if hotplug of an empty cdrom fails can cause that 'qemuBlockStorageSourceChainDetach' will be called with 'NULL' @data as there is no backend for the disk. The above case became possible once we allowed hotplug of cdroms and subsequently fixed the case when users would hotplug an empty cdrom which ultimately caused the possibility of having no backend in the hotplug code path which was not possible before (see 'Fixes:' below and also the commit linked from there). Make 'qemuBlockStorageSourceChainDetach' tolerate NULL @data by simply returning early. Fixes: 894c6c5c1686cfbc1742493ed512a4795098b763 Resolves: https://issues.redhat.com/browse/RHEL-54550 Signed-off-by: Peter Krempa Reviewed-by: Martin Kletzander --- src/qemu/qemu_block.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c index d6cdf521c4..6e90bae9f2 100644 --- a/src/qemu/qemu_block.c +++ b/src/qemu/qemu_block.c @@ -1927,6 +1927,9 @@ qemuBlockStorageSourceChainDetach(qemuMonitor *mon, { size_t i; + if (!data) + return; + if (data->copyOnReadAttached) ignore_value(qemuMonitorBlockdevDel(mon, data->copyOnReadNodename)= ); --=20 2.46.0 From nobody Wed Nov 27 06:49:08 2024 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 1723819429437400.8855394421827; Fri, 16 Aug 2024 07:43:49 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 661C01314; Fri, 16 Aug 2024 10:43:48 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 3EF9E13EA; Fri, 16 Aug 2024 10:42:49 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 4A4361340; Fri, 16 Aug 2024 10:42:42 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.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 90F2E1274 for ; Fri, 16 Aug 2024 10:42:41 -0400 (EDT) Received: from mx-prod-mc-02.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-97-YUTPRzJuPzWxI2S7OUwFfg-1; Fri, 16 Aug 2024 10:42:40 -0400 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (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-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 407201955F43 for ; Fri, 16 Aug 2024 14:42:39 +0000 (UTC) Received: from speedmetal.lan (unknown [10.45.242.12]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 5A1791955F38 for ; Fri, 16 Aug 2024 14:42:38 +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.6 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE 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=1723819361; 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=mxPerkJFfdVgPBoj+FEsbcVSYfBNIimVmZEZfDHTU+E=; b=P6VXjRcDjjBWnqnHnKX9SCKuF4z2XcB8PB0OapYTQy4a8Ymof9ONOUfLotykfUW2iZkpxy DgNUM09S2NUhcUpHOG1nr28d3QR8rG6S+Yvpo3GQx7kqHPsI+ySqn4XjqxhohxhZ4w04IG XgysgAz771LpVcCp89uTm6HHbyRkULo= X-MC-Unique: YUTPRzJuPzWxI2S7OUwFfg-1 From: Peter Krempa To: devel@lists.libvirt.org Subject: [PATCH 2/2] qemu: validate: Reject empty USB disks Date: Fri, 16 Aug 2024 16:42:33 +0200 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: 4QPQG5QD4SJLXCRYRSFAG3RV7NO7LNRI X-Message-ID-Hash: 4QPQG5QD4SJLXCRYRSFAG3RV7NO7LNRI 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: 1723819429919116600 Content-Type: text/plain; charset="utf-8" Attempting to start qemu with or hotplug an empty 'usb-storage' based disk results in the following error: qemu-system-x86_64: -device {"driver":"usb-storage","bus":"usb.0","port":"= 2","id":"usb-disk1","removable":true}: drive property not set Reject such config at validation step and adjust tests. Signed-off-by: Peter Krempa Reviewed-by: Martin Kletzander --- src/qemu/qemu_validate.c | 6 ++++ .../disk-cdrom-bus-other.x86_64-latest.args | 5 ++-- .../disk-cdrom-bus-other.x86_64-latest.xml | 5 ---- .../qemuxmlconfdata/disk-cdrom-bus-other.xml | 5 ---- .../disk-cdrom-usb-empty.x86_64-latest.err | 1 + .../qemuxmlconfdata/disk-cdrom-usb-empty.xml | 29 +++++++++++++++++++ tests/qemuxmlconftest.c | 1 + 7 files changed, 39 insertions(+), 13 deletions(-) create mode 100644 tests/qemuxmlconfdata/disk-cdrom-usb-empty.x86_64-lates= t.err create mode 100644 tests/qemuxmlconfdata/disk-cdrom-usb-empty.xml diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c index b885fe7c77..48abc3f850 100644 --- a/src/qemu/qemu_validate.c +++ b/src/qemu/qemu_validate.c @@ -3037,6 +3037,12 @@ qemuValidateDomainDeviceDefDiskFrontend(const virDom= ainDiskDef *disk, return -1; } + if (virStorageSourceIsEmpty(disk->src)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("'usb' disk must not be empty")); + return -1; + } + if (disk->info.type !=3D VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE && disk->info.type !=3D VIR_DOMAIN_DEVICE_ADDRESS_TYPE_USB) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", diff --git a/tests/qemuxmlconfdata/disk-cdrom-bus-other.x86_64-latest.args = b/tests/qemuxmlconfdata/disk-cdrom-bus-other.x86_64-latest.args index e0d2452a10..e1406af663 100644 --- a/tests/qemuxmlconfdata/disk-cdrom-bus-other.x86_64-latest.args +++ b/tests/qemuxmlconfdata/disk-cdrom-bus-other.x86_64-latest.args @@ -27,9 +27,8 @@ XDG_CONFIG_HOME=3D/var/lib/libvirt/qemu/domain--1-QEMUGue= st1/.config \ -no-shutdown \ -boot strict=3Don \ -device '{"driver":"piix3-usb-uhci","id":"usb","bus":"pci.0","addr":"0x1.0= x2"}' \ --blockdev '{"driver":"file","filename":"/root/boot.iso","node-name":"libvi= rt-2-storage","read-only":true}' \ --device '{"driver":"usb-storage","bus":"usb.0","port":"1","drive":"libvirt= -2-storage","id":"usb-disk0","removable":false}' \ --device '{"driver":"usb-storage","bus":"usb.0","port":"2","id":"usb-disk1"= ,"removable":false}' \ +-blockdev '{"driver":"file","filename":"/root/boot.iso","node-name":"libvi= rt-1-storage","read-only":true}' \ +-device '{"driver":"usb-storage","bus":"usb.0","port":"1","drive":"libvirt= -1-storage","id":"usb-disk0","removable":false}' \ -audiodev '{"id":"audio1","driver":"none"}' \ -sandbox on,obsolete=3Ddeny,elevateprivileges=3Ddeny,spawn=3Ddeny,resource= control=3Ddeny \ -msg timestamp=3Don diff --git a/tests/qemuxmlconfdata/disk-cdrom-bus-other.x86_64-latest.xml b= /tests/qemuxmlconfdata/disk-cdrom-bus-other.x86_64-latest.xml index 312e735947..f16fe63057 100644 --- a/tests/qemuxmlconfdata/disk-cdrom-bus-other.x86_64-latest.xml +++ b/tests/qemuxmlconfdata/disk-cdrom-bus-other.x86_64-latest.xml @@ -23,11 +23,6 @@ - - - - -
diff --git a/tests/qemuxmlconfdata/disk-cdrom-bus-other.xml b/tests/qemuxml= confdata/disk-cdrom-bus-other.xml index 9564dc11be..119ce297a0 100644 --- a/tests/qemuxmlconfdata/disk-cdrom-bus-other.xml +++ b/tests/qemuxmlconfdata/disk-cdrom-bus-other.xml @@ -20,11 +20,6 @@ - - - - - diff --git a/tests/qemuxmlconfdata/disk-cdrom-usb-empty.x86_64-latest.err b= /tests/qemuxmlconfdata/disk-cdrom-usb-empty.x86_64-latest.err new file mode 100644 index 0000000000..a00cb0a4b2 --- /dev/null +++ b/tests/qemuxmlconfdata/disk-cdrom-usb-empty.x86_64-latest.err @@ -0,0 +1 @@ +unsupported configuration: 'usb' disk must not be empty diff --git a/tests/qemuxmlconfdata/disk-cdrom-usb-empty.xml b/tests/qemuxml= confdata/disk-cdrom-usb-empty.xml new file mode 100644 index 0000000000..fc1cf45085 --- /dev/null +++ b/tests/qemuxmlconfdata/disk-cdrom-usb-empty.xml @@ -0,0 +1,29 @@ + + QEMUGuest1 + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219100 + 219100 + 1 + + hvm + + + + destroy + restart + destroy + + /usr/bin/qemu-system-x86_64 + + + + + + + + + + + + + diff --git a/tests/qemuxmlconftest.c b/tests/qemuxmlconftest.c index 89292af300..436d58b977 100644 --- a/tests/qemuxmlconftest.c +++ b/tests/qemuxmlconftest.c @@ -1536,6 +1536,7 @@ mymain(void) DO_TEST_CAPS_LATEST("disk-cdrom"); DO_TEST_CAPS_LATEST("disk-cdrom-empty-network-invalid"); DO_TEST_CAPS_LATEST("disk-cdrom-bus-other"); + DO_TEST_CAPS_LATEST_PARSE_ERROR("disk-cdrom-usb-empty"); DO_TEST_CAPS_LATEST("disk-cdrom-network"); DO_TEST_CAPS_LATEST("disk-cdrom-tray"); DO_TEST_CAPS_LATEST("disk-floppy"); --=20 2.46.0