Repository navigation
[DO NOT REVIEW] lxutil: do not mistake unmapped groups for the overflow GID - #5214
Merged
Pedro Henrique Penna (ppenna) merged 4 commits intoNov 22, 2026
Conversation
Each entry of a FUSE_READDIRPLUS reply other than . and .. hands the guest a lookup reference, which the guest releases with FUSE_FORGET only for an entry that it receives. A microVM READDIRPLUS that failed partway through its directory snapshot returned the error alone and discarded the entries that it had already looked up, so their references leaked (microsoft/nvx#1611): the nodes stayed in the inode map, with their names, until FUSE_DESTROY, counted against the share's limits of 4,096 nodes, 16,384 names, and 1 MiB of names until lookups and creates failed with ENOSPC or E2BIG, and went into every snapshot. A listing fails partway at a listed name that no longer reaches the listed object, as after a rename over it, at a name whose lookup fails, as after an unlink, and at a name whose node the limits refuse, as once the guest holds 4,096 nodes. read_dir_microvm now follows the rule that read_dir_with and the aggregate root already follow: after an error, it returns the entries read so far, and reports the error only if there are none, so that the guest's next read, which starts at the failing entry, gets it. write_microvm_entry_plus looks up and writes one entry. Should the write fail after the lookup, which the size check before the lookup rules out, it releases the entry's reference, so that a failed entry holds none. Tests, in virtiofs' microVM filesystem tests: with room for one more node, a READDIRPLUS of two files returns the one that it looked up, the next read fails with ENOSPC, and once the guest forgets that file, the listing goes on with the other; and a READDIRPLUS of three files whose last listed one a new file replaced keeps no reference that the guest did not receive, so that once the guest forgets every entry that it received, only the root's node remains. Without the fix, at feature/microvm/dev b51f915 on Windows and on Linux (Azure Linux 3.0, nvx-kvm-test, with shares on tmpfs and ext4), the first fails with ENOSPC on its first read and the second leaves three nodes; with it, both and the package's other tests pass there. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
A request through an open handle, such as FUSE_WRITE, FUSE_READ, FUSE_READDIRPLUS, or FUSE_SETATTR with FATTR_FH, names both the handle and the node that it concerns, but VirtioFs::get_file looked the handle up alone (microsoft/nvx#1599). A guest could therefore use a handle with any other node's ID, and keep using it after FUSE_FORGET dropped the handle's node from the inode table. The table updates the paths and aliases of the nodes that it holds when the guest renames or removes a name, and they decide what a request through a handle may do: whether it may write, which check_writable decides from every name that the guest has used for the object, and where READDIRPLUS looks up the entries that it lists. The inode of a forgotten node, which only its handles keep, learns no name again. So a guest that opened a file through a writable host hard link, forgot the node, and looked the file up again at its read-only name, which gives it a new node, still wrote and truncated the read-only file through the handle, with either node's ID; and READDIRPLUS through the handle of a forgotten directory that the guest had moved looked its entries up at the directory's former path. get_file now takes the request's node ID, which the nine requests through a handle pass: GETATTR and STATX with FUSE_GETATTR_FH, SETATTR with FATTR_FH, READ, WRITE, READDIR, READDIRPLUS, FSYNC, and FSYNCDIR. The node must be in the inode table, or the request fails with EINVAL, as other requests about an unknown node do, and the handle must have been opened on that node, or the request fails with EBADF, as virtiofsd's passthrough server answers. Unlike get_inode, get_file does not revalidate the node's paths, so a handle still reaches its file once the file is unlinked, as POSIX requires, and reads and writes walk no path. RELEASE and RELEASEDIR still accept the handle of a forgotten node: closing a handle uses neither the node nor its names, and refusing it would leak the handle. A Linux guest sends none of the refused requests: it names each handle's own node, and it forgets a node only once the RELEASE of the node's last handle has completed, since the RELEASE holds the inode, whose eviction sends FUSE_FORGET. a_handle_serves_only_its_node_while_the_guest_holds_it sends the nine requests through a file's and a directory's handle on a microVM share: with the handles' own nodes, even once the file is unlinked, each succeeds; with another node, each fails with EBADF; once the guest forgets the handles' nodes, each fails with EINVAL; and both handles can still be released. a_handle_of_a_forgotten_node_cannot_write_a_read_only_file opens a read-only file through a host hard link in a writable path, forgets the node, looks the file up at its read-only name, and checks that the handle can neither write nor truncate the file with either node's ID. Without the fix, at feature/microvm/dev b51f915 on Windows and on Linux (Azure Linux 3.0, nvx-kvm-test), every one of the nine requests succeeds with another node and after FUSE_FORGET, and the handle overwrites the read-only file; with it, both tests and the package's other tests pass there. The tests that read a directory through get_file now pass the handle's node. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
A microVM guest could make device nodes in a writable share (microsoft/nvx#1612). On a Linux host, VirtioFs::mknod passed the guest's file type and device number to mknodat, and VirtioFs::rename passed the guest's flags to renameat2. Since Linux 5.8, a caller without CAP_MKNOD may make a whiteout, character device 0:0, with mknodat(S_IFCHR, 0) or with renameat2(RENAME_WHITEOUT), which leaves one at the old name. Even an unprivileged OpenVMM therefore made one whenever the guest asked, which host overlay mounts and tools take for a deleted file, and an OpenVMM with CAP_MKNOD made any character or block device that the guest asked for, which reaches a host device wherever the share's filesystem is not mounted nodev. A whiteout rename also left an untracked node at the old name while HostFs moved that name's aliases to the new one. Windows hosts already refused both, as a microVM volume there makes only regular files and rejects every rename flag. A microVM share now checks both requests after its access policy, and before its resource limits and the host: - mknod makes only regular files, which a type of 0 also makes, FIFOs, and sockets. A character or block device fails with EPERM, as Linux fails a device that it denies, and any other type fails as mknod(2) fails it, a directory with EPERM and the rest with EINVAL, so that every host reports the same errors; - a rename passes the host no flag, RENAME_NOREPLACE, or RENAME_EXCHANGE, and fails with EINVAL, as Linux fails a flag that a filesystem does not support, for RENAME_WHITEOUT, any other flag, or those two together. The standard machine's virtio-fs still passes both to the host, and no saved state changes. The Guide's virtio-fs page lists the refused device nodes and rename flags, and its security model says why. Tests, in virtiofs' new microVM device node tests: mknod of character devices 0:0 and 1:3 and of block device 7:0 fails with EPERM, at a new name and at an existing one, whose EEXIST the host never reports, a directory with EPERM, and a symbolic link or an invalid type with EINVAL, leaving the share unchanged, while a regular file, and on Linux a FIFO, a socket, and a node of type 0, are still made; a rename with RENAME_WHITEOUT, alone or with RENAME_NOREPLACE, with RENAME_NOREPLACE and RENAME_EXCHANGE together, or with an unknown flag fails with EINVAL and changes neither name, even a rename of a name onto itself, while RENAME_NOREPLACE still reaches a Linux host. Without the fix, at feature/microvm/dev b51f915, on Linux (Azure Linux 3.0, kernel 6.18, unprivileged, on tmpfs; nvx-kvm-test), the first test fails where mknod makes character device 0:0 and the second where the RENAME_WHITEOUT rename succeeds; on Windows, only the directory's EINVAL fails. With it, both pass, with the package's other tests, on Windows and on Linux. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
with_fs_identity must run its operation without supplementary groups other than the GID of its identity, and fail with EPERM when it cannot drop them. In a user namespace that leaves some of the thread's groups unmapped, getgroups reports each of them as the kernel's overflow GID (/proc/sys/kernel/overflowgid, 65534 by default). When the target GID was itself the overflow GID, as for a guest caller in the nogroup group under --mount-owner caller, SwitchedCredentials::switch took those groups for the target GID, skipped setgroups, and ran the operation with the thread's original host groups, which it could use to read, write, or keep S_ISGID on files of those groups (microsoft/nvx#1600). A supplementary group that reads as the overflow GID now counts as another group unless the thread's user namespace maps every group ID, as the initial namespace does: a namespace maps only IDs that its parent maps, so such a namespace leaves no group unmapped. /proc/self/gid_map shows whether it does; a map that cannot be read counts as partial, and an overflow GID that cannot be read may be any GID. In a namespace with a partial map, a switch to the overflow GID therefore drops the supplementary groups too, or fails with EPERM before running the operation where it cannot, as when the namespace denies setgroups. That includes a thread whose only group is the one that the namespace maps as the overflow GID, since getgroups cannot tell it apart from an unmapped one. Where the namespace maps every group, the comparison stays exact, so an unprivileged thread whose only group is the overflow GID still needs no privilege there. overflow_gid_groups_fail_closed_without_privilege runs itself again in a user namespace that maps only the overflow GID, to the test's GID, and denies setgroups, and switches to that GID there. At b51f915, on a Linux host (nvx-kvm-test, Azure Linux 3.0, kernel 6.18), the switch returned Ok and chmod kept S_ISGID on a file of another of the test's groups; with the fix, it fails with EPERM. Another test checks which ID maps map every ID. The other lxutil tests pass there and on Windows, and so do virtiofs' tests on that host. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Pedro Henrique Penna (ppenna)
requested review from
a team and
Anatol Belski (weltling)
as code owners
November 22, 2026 03:15
|
This PR modifies files containing For more on why we check whole files, instead of just diffs, check out the Rustonomicon |
Pedro Henrique Penna (ppenna)
added a commit
to microsoft/nvx
that referenced
this pull request
Nov 22, 2026
…admap Map position 348, the commit of microsoft/openvmm#5214, which NVX now pins at 1270a975b, 222 commits past the mapped tip: - 348, lxutil: do not mistake unmapped groups for the overflow GID. SwitchedCredentials::switch counts a supplementary group that reads as the kernel's overflow GID as another group unless the thread's user namespace maps every group ID, so a caller-ownership request whose caller has that GID drops OpenVMM's unmapped host groups, or fails with EPERM where it cannot, instead of running with them. Position 348 is not yet assigned to a PR. It fixes a defect of position 158, which adds with_fs_identity and its credentials.rs and which no PR maps, and of what a mapped PR adds it changes only the Guide's virtio-fs page of PR18's position 085, with a sentence in the caller-mode paragraph that position 158 adds. Upstream main, bf353460f, lacks the defect, since it lacks caller ownership, and replaying the commit there conflicts in credentials.rs and the Guide's virtio-fs page, which upstream main lacks, so it cannot go upstream on its own. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This was referenced Nov 22, 2026
Pedro Henrique Penna (ppenna)
added a commit
to microsoft/nvx
that referenced
this pull request
Nov 22, 2026
…admap Map position 348, the commit of microsoft/openvmm#5214, which NVX now pins at 1270a975b, 222 commits past the mapped tip: - 348, lxutil: do not mistake unmapped groups for the overflow GID. SwitchedCredentials::switch counts a supplementary group that reads as the kernel's overflow GID as another group unless the thread's user namespace maps every group ID, so a caller-ownership request whose caller has that GID drops OpenVMM's unmapped host groups, or fails with EPERM where it cannot, instead of running with them. Position 348 is not yet assigned to a PR. It fixes a defect of position 158, which adds with_fs_identity and its credentials.rs and which no PR maps, and of what a mapped PR adds it changes only the Guide's virtio-fs page of PR18's position 085, with a sentence in the caller-mode paragraph that position 158 adds. Upstream main, bf353460f, lacks the defect, since it lacks caller ownership, and replaying the commit there conflicts in credentials.rs and the Guide's virtio-fs page, which upstream main lacks, so it cannot go upstream on its own. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
5 tasks done
Pedro Henrique Penna (ppenna)
added a commit
to microsoft/nvx
that referenced
this pull request
Nov 22, 2026
OpenVMM's virtio-fs server records the names through which the guest reaches each node, and hard links share one node. It tracked every rename that is not an exchange as a move: it dropped the names at and below the destination, then rewrote those at and below the source under it (#1620). A Linux host renames nothing when the source is another hard link of the destination's object, as POSIX requires, so the node kept only the destination's name, although the source still reached its object. Once the guest removed the destination, the node had no names left, so its requests failed with ENOENT, and saving the microVM failed with "inode has no bounded reopenable aliases". Pin microsoft/openvmm 2a483a06f31fcea8736efa59e2e9c600a0529d52, the head of microsoft/openvmm#5215, one commit on 1270a975b, the head of microsoft/openvmm#5214: - virtiofs: keep node names when renaming one hard link onto another. After a successful rename on a POSIX host, VirtioFs::rename changes no names when the source still reaches the destination's object, as their host device and inode numbers show. A Windows host removes the source link instead, which the names already followed. Its test fails without the change on Linux (nvx-kvm-test) and passes on Windows, and with it, NVX's microVM filesystem scenarios pass on KVM. No saved state, protocol, ABI, or format, and no version of any of them, changes. The protocol vectors and CPU profiles that nvx copies are unchanged. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Pedro Henrique Penna (ppenna)
merged commit Nov 22, 2026
1270a97
into
feature/microvm/dev
101 of 105 checks passed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
For microsoft/nvx#1600. The NVX pull request that pins this commit closes the issue.
Stacked on #5213 (
copilot/nvx-issue-1612-mknod-devices); only the top commit,1270a975b, belongs to this pull request.Problem
lxutil::with_fs_identitypromises that its operation runs without supplementary groups other than the GID of its identity, and that it fails withEPERM, without running the operation, when it cannot drop them.SwitchedCredentials::switchdecided whether to drop them by comparing whatgetgroups(2)returns with the target GID. In a user namespace,getgroupsreports each group that the namespace'sgid_mapleaves unmapped as the kernel's overflow GID (/proc/sys/kernel/overflowgid, 65534 by default), while the kernel still checks access against the real groups. So when the target GID was itself the overflow GID, such as for a guest caller with GID 65534 under--mount-owner caller(also NVX's default workload group), the unmapped host groups compared equal,setgroupswas skipped, and the operation ran with the VMM's original host groups: it could read, write, or keepS_ISGIDon files of those groups.Fix
A supplementary group that reads as the overflow GID now counts as another group unless
/proc/self/gid_mapmaps every ID, as the initial user namespace does. A namespace maps only IDs that its parent maps, so a complete map leaves no group unmapped. A map that cannot be read counts as partial, and an overflow GID that cannot be read may be any GID. Where the map is partial, a switch to the overflow GID therefore drops the supplementary groups, or fails withEPERMbefore running the operation where it cannot, as where the namespace deniessetgroups; that includes a thread whose only group is the one that the namespace maps as the overflow GID, sincegetgroupscannot tell it apart from an unmapped one. In the initial user namespace the comparison is unchanged. The Guide's virtio-fs page says so in its caller-mode paragraph.Tests
overflow_gid_groups_fail_closed_without_privilegeruns itself again in a new user namespace (unshare(CLONE_NEWUSER)before exec) that maps only the overflow GID, to the test's GID, and deniessetgroups, and switches to that GID there. Without the change toswitch, it returnsOk, andchmodkeepsS_ISGIDon a file of another of the test's groups (left: Ok(Some(true))); with it, it fails withEPERM. It skips, with a message, where user namespaces or ID maps are unavailable, and fails if the child runs no test.only_complete_id_maps_map_every_idchecks whichgid_mapcontents map every ID.Validation:
cargo check,cargo clippy --all-targets -- -D warnings,cargo doc --no-deps(RUSTDOCFLAGS=-D warnings), andcargo nextest run --profile agentforlxutil: 69 passed, 2 skipped (the module is Linux-only, so the new tests do not build there).lxutil, 50 passed, 2 skipped (the existing privileged tests), andvirtiofs, 191 passed, 1 skipped.cargo xtask fmt --fix.Out of scope: microsoft/nvx#1606, restoring unmapped groups where a user namespace allows
setgroups, which a later pull request stacked on this one addresses.