Repository navigation
Description
Summary
lxutil::with_fs_identity skips clearing supplementary groups whenever every GID returned by getgroups(2) equals identity.gid. In a Linux user namespace that leaves the VMM thread's host supplementary groups unmapped in gid_map, getgroups(2) reports every unmapped group as the kernel overflow GID (/proc/sys/kernel/overflowgid, 65534 by default). When identity.gid equals that overflow GID (reachable via a guest FUSE request with gid == 65534 under --mount-owner caller in a user namespace mapping 65534), with_fs_identity skips setgroups(&[]) and runs operation with Ok(...) while the thread retains all of its original unmapped host supplementary groups. Found by testing.
Root Cause
In vm/devices/support/fs/lxutil/src/unix/credentials.rs, SwitchedCredentials::switch (invoked by with_fs_identity) decides whether to drop supplementary groups by comparing the gid_t values returned by groups() against identity.gid:
// On an error below, dropping `credentials` restores whatever was already changed.
let groups = groups()?;
if groups.iter().any(|&group| group != identity.gid) {
set_groups(&[])?;
credentials.groups = Some(groups);
}On Linux, getgroups(2) converts each kernel kgid_t in the thread's cred->group_info to the caller's user namespace via from_kgid_munged, which maps every kgid_t lacking an entry in /proc/self/gid_map to /proc/sys/kernel/overflowgid (65534 by default) while leaving the underlying host kgid_t values intact in cred->group_info for VFS permission checks (in_group_p). When OpenVMM runs in a user namespace that maps 65534 (for example unshare --user --map-user=0 --map-group=65534) and the host user belongs to unmapped supplementary groups, groups() returns [65534, 65534, ...]. For a target identity with gid == 65534 — which CallerIdentity::host_identity and run_as pass directly from any guest FUSE request with request.gid() == 65534 (nobody/nogroup) under --mount-owner caller — groups.iter().any(|&group| group != identity.gid) is false. SwitchedCredentials::switch skips set_groups(&[]) (never encountering the namespace's /proc/self/setgroups == "deny" restriction), switches fsuid/fsgid, clears effective capabilities, and executes operation with the host's supplementary groups still active in the kernel.
Consequence
with_fs_identity explicitly guarantees that operation "runs without effective capabilities and without supplementary groups other than the GID of identity, so that it gains no access through the privileges or groups of the thread's original identity" and fails closed with EPERM when those groups cannot be dropped. Instead, in a rootless user namespace that maps 65534 while leaving the VMM user's extra host supplementary groups unmapped, a guest process issuing virtio-fs requests with gid = 65534 retains group-based DAC access (in_group_p, group rwx permissions, and S_ISGID preservation on chmod) for every unmapped host supplementary group of the VMM process across the shared directory tree.
Reproduction
On a Linux host where the current user belongs to at least one supplementary group besides its effective GID, enter a user namespace via unshare --user --map-user=0 --map-group=65534 (so /proc/self/setgroups is "deny" and unmapped supplementary groups report as 65534) and call lxutil::with_fs_identity(FsIdentity { uid: 0, gid: 65534 }, || ...). On commit 9d64daad3cbe14fb0591081b73c6c9648e18d0fb, with_fs_identity returns Ok(...) instead of Err(lx::Error::EPERM), /proc/thread-self/status inside the closure still lists Groups: 65534 ... with CapEff: 0x0, and chmod(0o2755) on a file owned by one of the host user's unmapped supplementary groups preserves S_ISGID. Running cargo nextest run --profile agent -p lxutil -E 'test(unmapped_supplementary_groups_are_dropped_or_refused)' reproduces the failure before fix.patch and passes afterward.
Related: #1606.
Activity
tangruize commentedon Nov 15, 2026
Suggested Fix
Read the kernel overflow GID from
/proc/sys/kernel/overflowgid(defaulting to65534if unreadable) and, inSwitchedCredentials::switch, also clear supplementary groups viaset_groups(&[])whenever!groups.is_empty() && identity.gid == overflow_gid(). Because anyoverflow_gid()entry returned bygetgroups(2)may represent an arbitrary unmapped host group,with_fs_identitythen either drops the supplementary groups (whensetgroupsis permitted) or fails closed withlx::Error::EPERMwithout runningoperation(when the user namespace deniessetgroups).Patch against OpenVMM
9d64daad3cbe14fb0591081b73c6c9648e18d0fb. Save the contents below asfix.patchand rungit apply fix.patch.fix.patch