From nobody Wed Nov 27 08:38:52 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