From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id A030C8AE7E for ; Tue, 9 Aug 2022 09:32:43 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 99A012B3AD for ; Tue, 9 Aug 2022 09:32:43 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS for ; Tue, 9 Aug 2022 09:32:42 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 39D274103A; Tue, 9 Aug 2022 09:32:42 +0200 (CEST) Message-ID: <213d8571-9d9f-72dc-c2b1-1076e9c959cb@proxmox.com> Date: Tue, 9 Aug 2022 09:32:41 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:104.0) Gecko/20100101 Thunderbird/104.0 Content-Language: en-US To: Proxmox VE development discussion , =?UTF-8?Q?Fabian_Gr=c3=bcnbichler?= References: <20220719114639.3035048-1-d.csapak@proxmox.com> <20220719114639.3035048-8-d.csapak@proxmox.com> <1659356491.m22f9lbwci.astroid@nora.none> From: Dominik Csapak In-Reply-To: <1659356491.m22f9lbwci.astroid@nora.none> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.096 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment NICE_REPLY_A -0.001 Looks like a legit reply (A) SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record T_SCC_BODY_TEXT_LINE -0.01 - URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [qemu.pm] Subject: Re: [pve-devel] [PATCH qemu-server 3/7] PVE/API2/Qemu: add permission checks for mapped usb devices X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 09 Aug 2022 07:32:43 -0000 On 8/1/22 15:01, Fabian Grünbichler wrote: > On July 19, 2022 1:46 pm, Dominik Csapak wrote: >> Signed-off-by: Dominik Csapak >> --- >> PVE/API2/Qemu.pm | 39 ++++++++++++++++++++++++++++++++++++--- >> 1 file changed, 36 insertions(+), 3 deletions(-) >> >> diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm >> index 99b426e..aa7ddea 100644 >> --- a/PVE/API2/Qemu.pm >> +++ b/PVE/API2/Qemu.pm >> @@ -26,6 +26,7 @@ use PVE::QemuServer::Drive; >> use PVE::QemuServer::ImportDisk; >> use PVE::QemuServer::Monitor qw(mon_cmd); >> use PVE::QemuServer::Machine; >> +use PVE::QemuServer::USB qw(parse_usb_device); >> use PVE::QemuMigrate; >> use PVE::RPCEnvironment; >> use PVE::AccessControl; >> @@ -567,8 +568,12 @@ my $check_vm_create_usb_perm = sub { >> >> foreach my $opt (keys %{$param}) { >> next if $opt !~ m/^usb\d+$/; >> + my $device = parse_usb_device($param->{$opt}); >> >> - if ($param->{$opt} =~ m/spice/) { >> + if ($device->{spice}) { >> + $rpcenv->check_vm_perm($authuser, $vmid, $pool, ['VM.Config.HWType']); >> + } elsif ($device->{mapped}) { >> + $rpcenv->check_hw_perm($authuser, $device->{host}, ['Hardware.Use']); > > maybe I am overlooking something, but where does $device->{host} come > from? > > parse_usb_device (for a mapped USB device) looks up device in the > hardware map, asserts it's valid (for the local node), and then either > returns > > { > vendorid => $map->{vendor}, > productid => $map->{device}, > mapped => 1, > } > > or the result of parse_usb_device($map->{path}), with 'mapped' set. > > since the lookup in the map doesn't set a 'host' member, wouldn't > $device->{host} always be undef for mapped devices? maybe this was > wrongly copied from the PCI code, where the hostpci property string has > a 'host' property (that with this series, also possibly contains a > mapping entry ID)? or is this supposed to parse the property string, and > use the host property from there? > ok, either i did send from the wrong branch, or i redid that already since sending the patches. my branch here locally already has all of the wrong 'parse_usb_device' calls replaced with 'parse_property_string' (like with pci) so in any case that is the correct approach here. first parse the property string, then parse the usb device from the 'host' property