Skip to contentSkip to conversation

virt: vbox: Do not report user namespace root as root to the host

PATCH In review Hungyu Lin 2 participants 2 messages Nov 13 Virtual box guest device driver

lore
Share & tools
lore

Hungyu Lin

author
#0 lore raw

PATCH 1/1 virt: vbox: Do not report user namespace root as root to the host

vbg_misc_device_requestor() decides whether the opener of the vboxguest or vboxuser device is reported to the host as root:

	if (from_kuid(current_user_ns(), current_uid()) == 0)
		requestor |= VMMDEV_REQUESTOR_USR_ROOT;

from_kuid() translates the uid into the user namespace of the caller. An unprivileged user who creates a user namespace and maps their uid to 0 in it is therefore reported as VMMDEV_REQUESTOR_USR_ROOT for every request of that session, although the uid has no privileges outside of that namespace. The host uses the user class to account the HGCM requests of a session, so such a user is charged to the budget of root instead of the one for ordinary users.

Compare the uid against GLOBAL_ROOT_UID so that only root in the initial user namespace is reported as root.

Fixes 0532a1b0d045 ("virt: vbox: Implement passing requestor info to the host for VirtualBox 6.0.x")
---
 drivers/virt/vboxguest/vboxguest_linux.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/virt/vboxguest/vboxguest_linux.c +1 -1
index 7474bae2cd9a..ff66c00c27da 100644
@@ -35,7 +35,7 @@ static u32 vbg_misc_device_requestor(struct inode *inode)
 			VMMDEV_REQUESTOR_CON_DONT_KNOW |
 			VMMDEV_REQUESTOR_TRUST_NOT_GIVEN;
 
-	if (from_kuid(current_user_ns(), current_uid()) == 0)
+	if (uid_eq(current_uid(), GLOBAL_ROOT_UID))
 		requestor |= VMMDEV_REQUESTOR_USR_ROOT;
 	else
 		requestor |= VMMDEV_REQUESTOR_USR_USER;

--
2.43.0

maintainer Reviewed-by on v1 1/1
#1 lore raw

Hi,

Quoted 14 lines · Hungyu Lin

vbg_misc_device_requestor() decides whether the opener of the vboxguest or vboxuser device is reported to the host as root:

	if (from_kuid(current_user_ns(), current_uid()) == 0)
		requestor |= VMMDEV_REQUESTOR_USR_ROOT;

from_kuid() translates the uid into the user namespace of the caller. An unprivileged user who creates a user namespace and maps their uid to 0 in it is therefore reported as VMMDEV_REQUESTOR_USR_ROOT for every request of that session, although the uid has no privileges outside of that namespace. The host uses the user class to account the HGCM requests of a session, so such a user is charged to the budget of root instead of the one for ordinary users.

Quoted 6 lines

Compare the uid against GLOBAL_ROOT_UID so that only root in the initial user namespace is reported as root.

Fixes 0532a1b0d045 ("virt: vbox: Implement passing requestor info to the host for VirtualBox 6.0.x")

Thanks, patch looks good to me:

Regards,

Hans

Quoted 19 lines
---
 drivers/virt/vboxguest/vboxguest_linux.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/virt/vboxguest/vboxguest_linux.c +1 -2
index 7474bae2cd9a..ff66c00c27da 100644
@@ -35,7 +35,7 @@ static u32 vbg_misc_device_requestor(struct inode *inode)
 			VMMDEV_REQUESTOR_CON_DONT_KNOW |
 			VMMDEV_REQUESTOR_TRUST_NOT_GIVEN;
 
-	if (from_kuid(current_user_ns(), current_uid()) == 0)
+	if (uid_eq(current_uid(), GLOBAL_ROOT_UID))
 		requestor |= VMMDEV_REQUESTOR_USR_ROOT;
 	else
 		requestor |= VMMDEV_REQUESTOR_USR_USER;
--

2.43.0