Repository navigation
[DO NOT REVIEW] virtiofs: fail a synthetic root read too small for its next entry - #5216
Merged
Pedro Henrique Penna (ppenna) merged 5 commits intoNov 22, 2026
Conversation
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>
A guest rename of a hard link onto another link of the same object succeeds on a Linux host without changing anything, as POSIX requires, but HostFs dropped the source name from the object's node (microsoft/nvx#1620). Once the guest removed the other link, the node had no names left although the source still reached its object, so requests on the node failed with ENOENT, and a microVM save failed with "inode has no bounded reopenable aliases". VirtioFs::rename tracks a rename that is not an exchange as a move: it drops the names at and below the destination, which the host replaced, and then rewrites those at and below the source under the destination. When both are links of one object, renameat2 replaces and moves nothing, but the node keeps only the destination's name. After a successful rename on a POSIX host, HostFs now checks whether the source still reaches the destination's object, and then changes no names. It decides from the host's result, not from the two names before the rename: through overlayfs, two hard links in a lower layer report one inode number, but the rename still moves one onto the other. A Windows host does move the name: NTFS removes the source link, which the move's bookkeeping already records, and a rename that changes only the case of a name leaves the old spelling reaching the object, so the check stays off there. The rename still passes the move's alias-limit preflight, and the names that it keeps already fit the limits. renaming_a_hard_link_onto_another_link_keeps_the_remaining_names, in virtiofs' microVM rename tests, renames a hard link onto another link of its object in one directory and across two, after checking that the host still fails such a rename under RENAME_NOREPLACE, with EEXIST on Linux and EINVAL on Windows. On Linux, the node keeps all three names, a snapshot taken right away saves and restores them, and the node still reads the object through the source once the guest removes the other links. On Windows, the host keeps only the destination, and so does the node. Without the fix, on top of the fix for microsoft/nvx#1610 at feature/microvm/dev b51f915, it fails on Linux (nvx-kvm-test, Azure Linux 3, kernel 6.18), where the node keeps only the destination, and passes on Windows; with it, it and the package's other tests pass on both. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
A FUSE_READDIR or FUSE_READDIRPLUS of an aggregate's synthetic root whose buffer cannot hold the next entry returned an empty reply (microsoft/nvx#1617). FUSE takes an empty directory reply for the end of the directory, so the guest saw the root end there: a read from the start with a buffer too small for `.`, of at most 31 bytes for READDIR or 159 for READDIRPLUS, listed an empty root, and a listing whose buffer holds the entries before a child with a longer name ended before that child, without an error. VirtioFs::read_synthetic_root_dir_with stops at the first entry that does not fit, and returned what it had written, even nothing. A read of any other directory, through VirtioFsFile::read_dir_with or read_dir_microvm, fails with EINVAL when its buffer cannot hold the next entry, as getdents64 does, and returns an empty reply only at the end of the directory. Fail the read with EINVAL when the first entry that it reaches does not fit. A read that fits some entries still returns them, and a read at the end of the root still returns an empty reply, whatever its size. READDIRPLUS checks that an entry fits before it looks the child up, so the failed read takes no lookup reference. The Linux FUSE client reads directories with buffers of at least a page, which holds any entry, so Linux guests see no change. aggregate::tests:: synthetic_root_refuses_a_buffer_too_small_for_the_next_entry lists an aggregate's root with READDIR and with READDIRPLUS as the guest does, each read starting at the last cookie of the read before: a buffer that holds the largest entry lists every entry; a buffer a byte smaller lists the entries before the largest and fails at it with EINVAL; a read from the start whose buffer cannot hold `.` fails with EINVAL; and a read at the end of the root with a 1-byte buffer returns an empty reply. Without the fix, the test fails on Windows and on Linux (Azure Linux 3.0, kernel 6.18, nvx-mshv-test), where the listing ends after `work` without an error; with it, the test and the rest of cargo nextest -p virtiofs pass on both. 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 04:17
|
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
Map position 350, the commit of microsoft/openvmm#5216, which NVX now pins at 189dc519f, 224 commits past the mapped tip: - 350, virtiofs: fail a synthetic root read too small for its next entry. VirtioFs::read_synthetic_root_dir_with fails a FUSE_READDIR or FUSE_READDIRPLUS of an aggregate's synthetic root whose buffer cannot hold the next entry with EINVAL, as the reads of every other directory do. It returned an empty reply, which the guest takes for the end of the directory, so the guest listed the root without the children from that entry on. Position 350 is not yet assigned to a PR. It changes only the !fit branch of upstream's loop from a5f055dd7 (microsoft/openvmm#3821), which no chain commit changes, and adds a test to upstream's aggregate_tests.rs; it changes nothing that a mapped PR adds, so it is no fixup. Upstream main, bf353460f, has the defect. The commit applies there as it is, and on the merged tree virtiofs type-checks with its tests, the new test fails without the change, and all 72 tests of the package pass with it, on Windows, so it can 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)
merged commit Nov 22, 2026
189dc51
into
feature/microvm/dev
104 of 105 checks passed
syeedali
pushed a commit
to syeedali/nvx
that referenced
this pull request
Nov 23, 2026
OpenVMM's microVM virtio-fs server lists a directory once, on a handle's first read, and FUSE_READDIRPLUS looks each listed name up again. It failed the read whenever that lookup failed, even with ENOENT for a name that was unlinked or renamed since the listing, as by another guest process or the host while the guest lists the directory a page at a time, or with EACCES for a name whose object the access policy hides, as a host hard link to a hidden file does (microsoft#1622). The guest's next read starts at the failing entry, so every later read of the handle failed too, and the guest could never list the rest of the directory: getdents64 failed, and with it rm -rf, find, and other directory walkers. Pin microsoft/openvmm 8bea555dbb4e5ac9cbb2de041c1ba9a111b292b5, one commit on 189dc519f, the head of microsoft/openvmm#5216: - virtiofs: skip gone or hidden entries in microVM READDIRPLUS. A READDIRPLUS skips an entry whose lookup fails with ENOENT or EACCES, as the server's other profiles do, so that the entry takes no lookup reference, and a read that skips every entry left returns an empty reply, which ends the listing, rather than EINVAL, which it keeps for a buffer that cannot hold the next entry. Its tests fail without the change on Windows and on Linux (nvx-kvm-test). A listed name that now reaches another object still fails the read with EIO. 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>
syeedali
pushed a commit
to syeedali/nvx
that referenced
this pull request
Nov 23, 2026
Map position 357, the commit of microsoft/openvmm#5223, which NVX now pins at 49fc14eeb, 231 commits past the mapped tip: - 357, virtiofs: refuse renames of directories that hold denied paths. VirtioFs::rename fails with EROFS, before the host changes anything, when a denied path lies below either of its names, as the new SubtreePolicy::is_subtree_writable decides. It checked only its two names, so a guest could rename or exchange a writable directory that holds a denied path and so move the hidden entries to a visible name, or rename a directory of its own onto the name of one that the host had removed and so put its entries at the denied path. Position 357 is not yet assigned to a PR. The gap dates from the denied paths of PR22's position 102, whose checks of a name never looked below it, but the commit changes only what position 160 adds, whose policy replaced those checks and whose SubtreePolicy it needs, and nothing that a mapped PR adds. Upstream main, bf353460f, lacks the defect, since it lacks the access policy, and replaying the commit there conflicts in lib.rs and in the four other files that it changes, which upstream main lacks, so it cannot go upstream on its own. Record also that feature/microvm/dev now stands at position 351, 8bea555db, where microsoft/openvmm#5216 and #5217 landed positions 350 and 351. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.
Refs microsoft/nvx#1617.
Stacked on #5215: only the top commit,
189dc519f, belongs to this PR. NVX pins the head of this branch, so this is a prerequisite of the NVX change that pins it, and it lands after #5215 by fast-forwardingfeature/microvm/devto that exact commit, not with the merge button, which squashes.What and why
FUSE_READDIRandFUSE_READDIRPLUSon the synthetic root of an aggregate virtio-fs device reachVirtioFs::read_synthetic_root_dir_with, which stopped at the first entry that did not fit in the guest's buffer and returned what it had written, even nothing. FUSE takes an empty directory reply for the end of the directory (Linux'sfuse_readdir_uncachedreturns 0 togetdents64for it), so a guest whose buffer could not hold the next entry saw the root end there:., at most 31 bytes forREADDIRor 159 forREADDIRPLUS, listed an empty root;A read of any other directory, through
VirtioFsFile::read_dir_withorread_dir_microvm, fails withEINVALwhen its buffer cannot hold the next entry, asgetdents64does, and returns an empty reply only at the end of the directory. Upstream's aggregate support (#3821) wrote the synthetic root's loop without that check, and upstreammainstill lacks it.The fix: when the first entry that the read reaches does not fit, the read fails with
EINVAL. A read that fits some entries still returns them, and a read at the end of the root still returns an empty reply, even with a buffer too small for an entry.READDIRPLUSchecks that an entry fits before it looks the child up, so the failed read takes no lookup reference. The Linux FUSE client reads directories with buffers of at least a page, which holds any entry, so Linux guests see no change. No saved state, protocol, ABI, or format, and no version of any of them, changes.Kept from the issue's suggested fix:
EINVALwhen an entry did not fit and nothing was written. Changed: the check sits in the!fitbranch instead of a flag, and the test is a unit test among the aggregate's own tests,aggregate_tests.rs, on an aggregate built withVirtioFs::new_aggregate, rather than an integration test on a microVM aggregate, so that the commit applies to upstreammainon its own.Out of scope, handled separately:
FSYNCDIRon the synthetic root (microsoft/nvx#1624), the handle map'su64::MAXandSYNTHETIC_ROOT_FH(microsoft/nvx#1627), and the root'sst_nlink(microsoft/nvx#1632).Tests
One unit test in
virtiofs,aggregate::tests::synthetic_root_refuses_a_buffer_too_small_for_the_next_entry: on an aggregate with the childrenworkandbuild-tools, whose entry is the largest, it lists the root withREADDIRand withREADDIRPLUSas the guest does, each read starting at the last cookie of the read before:.,..,work, andbuild-tools;.,.., andwork, one per read, and then fails withEINVALatbuild-tools, rather than ending the listing there;.fails withEINVAL;Validation
cargo nextest run --profile agent -p virtiofs, with the new test and the fix reverted, and with the fix:plus: false,left: None,right: Some(Error(EINVAL (22))), the listing ending afterworkwithout an errornvx-mshv-test, Azure Linux 3.0 VMAt this head, on both hosts,
cargo check,cargo clippy --all-targets, andcargo doc --no-depsforvirtiofsare clean, with no warning but theLNK4199linker message that every linked artifact gets on the Windows machine, and one ignored test is skipped, as at the base.cargo xtask fmt --fixchanges nothing.The commit also applies to upstream
main,bf353460f, on its own: on the merged tree,cargo check -p virtiofs --testspasses, the new test fails without the fix in the same way, and with it all 72 tests ofvirtiofspass, on Windows.NVX's virtio-fs microVM scenarios, among them the two that list an aggregate's root from the guest,
filesystem-sharesandplatform-aggregate-export, andplatform-filesystemandfilesystem-snapshot, pass on KVM onnvx-kvm-test, an Azure Linux 3.0 VM, with OpenVMM built from this head.