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 B487F8A0B7 for ; Mon, 1 Aug 2022 15:01:11 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id B22653003A for ; Mon, 1 Aug 2022 15:01:11 +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 ; Mon, 1 Aug 2022 15:01:10 +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 88DAB40F21 for ; Mon, 1 Aug 2022 15:01:10 +0200 (CEST) Date: Mon, 01 Aug 2022 15:01:03 +0200 From: Fabian =?iso-8859-1?q?Gr=FCnbichler?= To: Proxmox VE development discussion References: <20220719114639.3035048-1-d.csapak@proxmox.com> <20220719114639.3035048-8-d.csapak@proxmox.com> In-Reply-To: <<20220719114639.3035048-8-d.csapak@proxmox.com> MIME-Version: 1.0 User-Agent: astroid/0.15.0 (https://github.com/astroidmail/astroid) Message-Id: <1659356491.m22f9lbwci.astroid@nora.none> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-SPAM-LEVEL: Spam detection results: 0 AWL 0.160 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 SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record 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: Mon, 01 Aug 2022 13:01:11 -0000 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(-) >=20 > 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 =3D sub { > =20 > foreach my $opt (keys %{$param}) { > next if $opt !~ m/^usb\d+$/; > + my $device =3D parse_usb_device($param->{$opt}); > =20 > - if ($param->{$opt} =3D~ 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=20 from? parse_usb_device (for a mapped USB device) looks up device in the=20 hardware map, asserts it's valid (for the local node), and then either=20 returns { vendorid =3D> $map->{vendor}, productid =3D> $map->{device}, mapped =3D> 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=20 $device->{host} always be undef for mapped devices? maybe this was=20 wrongly copied from the PCI code, where the hostpci property string has=20 a 'host' property (that with this series, also possibly contains a=20 mapping entry ID)? or is this supposed to parse the property string, and=20 use the host property from there? > $rpcenv->check_vm_perm($authuser, $vmid, $pool, ['VM.Config.HWType'= ]); > } else { > die "only root can set '$opt' config for real devices\n"; > @@ -1552,7 +1557,12 @@ my $update_vm_api =3D sub { > PVE::QemuConfig->add_to_pending_delete($conf, $opt, $force); > PVE::QemuConfig->write_config($vmid, $conf); > } elsif ($opt =3D~ m/^usb\d+$/) { > - if ($val =3D~ m/spice/) { > + my $device =3D PVE::QemuServer::USB::parse_usb_device($val); > + my $host =3D parse_usb_device($device->{host}); > + if ($host->{spice}) { > + $rpcenv->check_vm_perm($authuser, $vmid, undef, ['VM.Config.HWType'])= ; > + } elsif ($host->{mapped}) { > + $rpcenv->check_hw_perm($authuser, $device->{host}, ['Hardware.Use']); same question here.. > $rpcenv->check_vm_perm($authuser, $vmid, undef, ['VM.Config.HWType'])= ; > } elsif ($authuser ne 'root@pam') { > die "only root can delete '$opt' config for real devices\n"; > @@ -1613,7 +1623,30 @@ my $update_vm_api =3D sub { > } > $conf->{pending}->{$opt} =3D $param->{$opt}; > } elsif ($opt =3D~ m/^usb\d+/) { > - if ((!defined($conf->{$opt}) || $conf->{$opt} =3D~ m/spice/) && $p= aram->{$opt} =3D~ m/spice/) { > + my $olddevice; > + my $oldhost; > + if (defined($conf->{$opt})) { > + $olddevice =3D PVE::QemuServer::USB::parse_usb_device($conf->{$opt}); > + $oldhost =3D parse_usb_device($olddevice->{host}); and here > + } > + if (defined($oldhost)) { > + if ($oldhost->{spice}) { > + $rpcenv->check_vm_perm($authuser, $vmid, undef, ['VM.Config.HWTyp= e']); > + } elsif ($oldhost->{mapped}) { > + $rpcenv->check_hw_perm($authuser, $olddevice->{host}, ['Hardware.= Use']); and here > + $rpcenv->check_vm_perm($authuser, $vmid, undef, ['VM.Config.HWTyp= e']); > + } elsif ($authuser ne 'root@pam') { > + die "only root can modify '$opt' config for real devices\n"; > + } > + } > + > + my $newdevice =3D PVE::QemuServer::USB::parse_usb_device($param->{= $opt}); > + my $newhost =3D parse_usb_device($newdevice->{host}); and here > + > + if ($newhost->{spice}) { > + $rpcenv->check_vm_perm($authuser, $vmid, undef, ['VM.Config.HWType'])= ; > + } elsif ($newhost->{mapped}) { > + $rpcenv->check_hw_perm($authuser, $newdevice->{host}, ['Hardware.Use'= ]); and here > $rpcenv->check_vm_perm($authuser, $vmid, undef, ['VM.Config.HWType'])= ; > } elsif ($authuser ne 'root@pam') { > die "only root can modify '$opt' config for real devices\n"; > --=20 > 2.30.2 >=20 >=20 >=20 > _______________________________________________ > pve-devel mailing list > pve-devel@lists.proxmox.com > https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel >=20 >=20 >=20