Repository navigation
[DO NOT REVIEW] virtiofs: skip gone or hidden entries in microVM READDIRPLUS - #5217
Merged
Pedro Henrique Penna (ppenna) merged 6 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>
A microVM directory handle lists its directory once, on its first read, and later reads page through that listing. READDIRPLUS looks each listed name up again, and failed the read whenever the 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/nvx#1622). Since the guest's next read starts at the failing entry, every later read failed the same way, so the guest could never list the rest of the directory through that handle: getdents64 failed, and with it rm -rf, find, and the like. read_dir_with, which serves the other profiles, skips such an entry. read_dir_microvm now skips an entry whose lookup fails with ENOENT or EACCES, as read_dir_with does, and the entry takes no lookup reference. A read that skips every entry left has reached the end of the directory, so it returns an empty reply, which ends the guest's listing, rather than EINVAL, which a read that returns no entry now reports only if it stopped at an entry that the guest's buffer cannot hold. A listed name that reaches another object still fails the read with EIO. Tests, in virtiofs' microVM tests: a READDIRPLUS of 60 files in 4 KiB pages, whose next page starts at an unlinked file and holds another, lists every other file and leaves no lookup reference; once every entry left is unlinked, a read returns an empty reply, while one whose buffer cannot hold the next entry still fails with EINVAL after it skips the unlinked ones; and a READDIRPLUS of a directory that holds a hard link to a hidden file lists every other entry. Without the fix, on Windows at 189dc51, the microsoft/nvx#1617 fix that this one follows, and on Linux (nvx-kvm-test, Azure Linux 3) on the microsoft/nvx#1611 fix alone, the three fail with ENOENT, ENOENT, and EACCES, and on Windows, with the skip alone, the second fails with EINVAL; with the fix, they and the package's other tests pass there. 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:32
|
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)
merged commit Nov 22, 2026
8bea555
into
feature/microvm/dev
102 of 105 checks passed
5 tasks done
syeedali
pushed a commit
to syeedali/nvx
that referenced
this pull request
Nov 23, 2026
…dmap Map position 351, the commit of microsoft/openvmm#5217, which NVX now pins at 8bea555db, 225 commits past the mapped tip: - 351, virtiofs: skip gone or hidden entries in microVM READDIRPLUS. A microVM READDIRPLUS skips a listed entry whose lookup fails with ENOENT, as for a name unlinked or renamed away since the listing, or with EACCES, as for a name whose object the access policy hides, as upstream's read_dir_with does, 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. It failed the read at such a name, and every later read of the handle, since each starts there, so the guest could never list the rest of the directory. Position 351 is a PR18 fixup. It fixes the READDIRPLUS of a listing that PR18's position 083 adds, in the loop that the PR18 fixup at position 345 rewrites, and needs nothing that a later position adds but the write_microvm_entry_plus of position 345, the helper that position 345's tests add, and the budget that position 342 passes to restore_directory_snapshot, which its persistence tests call, so it folds into position 083, after position 345, with those tests, and its test of a hard link to a hidden file into position 160, which adds the access policy, the identities that it pins, and the policy tests, as the fold sentence after the DAG and the commit mapping say; the Scope, the DAG, the dependency graph, the PR summary, and the commit mapping record it with PR18. Upstream main, bf353460f, lacks the defect, since it lacks the microVM's directory listings, and replaying the commit there conflicts in the microVM's file.rs, fs_tests.rs, and policy_tests.rs, which upstream main lacks, so it follows PR18 upstream. 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
OpenVMM's virtio-fs server records, for each node, the names through which the guest has reached its object, and keeps the last one when the guest removes them all, by an unlink or a rename over it, since other requests about the node still use it. FUSE_LINK to such a node linked whatever object had since appeared at that former name, gave the node the new name, and replied with the node's ID but that object's attributes (microsoft#1608). On a microVM share with writable paths, the object could be a read-only file, which a link through its own node refuses with EXDEV, since a name in a writable path would make the file writable: through the stale node, the guest could give it one. Pin microsoft/openvmm 3aefff9ba4e7ff50d5d34671678da6b58cd423c6, one commit on 8bea555db, the head of microsoft/openvmm#5217: - virtiofs: refuse to link a node whose last name is gone. A link to a node whose names the guest has all removed fails with ENOENT, as Linux's linkat does for an unlinked file, before it changes the host or any node, through VirtioFsInode::object_path, which yields a node's path only while the guest knows a name for its object. Its test fails without the change on Windows and on Linux (nvx-kvm-test). The other requests about such a node still use its former name (microsoft#1623). 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>
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#1622.
Stacked on #5216 (microsoft/nvx#1617), and through it on the earlier pull requests of that stack; only the top commit,
virtiofs: skip gone or hidden entries in microVM READDIRPLUS, belongs to this pull request. NVX pins the head of this branch, so this is a prerequisite of the NVX change that pins it, and it lands by fast-forwardingfeature/microvm/devto that exact commit, not with the merge button, which squashes.What and why
A microVM directory handle lists its directory once, on its first read (
build_microvm_directory_snapshot), and later reads page through that listing (VirtioFsFile::read_dir_microvm).FUSE_READDIRPLUSlooks each listed name up again, since each entry hands the guest a lookup reference and the entry's attributes, and it failed the read whenever that lookup failed, even:ENOENTfor a name that was unlinked or renamed away since the listing, as by another guest process or the host while the guest lists the directory a page at a time (the guest reads 4 KiB pages of about 25 entries);EACCESfor a name whose object the access policy hides, as a host hard link to a hidden file does: the listing filters names by path, but the check that refuses the link's pinned object runs only at lookup.The guest's next read starts at the failing entry, so every later read of the handle failed the same way, and the guest could never list the rest of the directory through it:
getdents64failed, and with itrm -rf,find,ls, and other directory walkers.VirtioFsFile::read_dir_with, which serves the other profiles, skips such an entry.The fix, in
read_dir_microvm:write_microvm_entry_plusfails withENOENTorEACCESis skipped, as inread_dir_with. Only its lookup,VirtioFsInode::lookup_child, returns those errors (the node insert that follows fails only withENOSPC,E2BIG, orEINVAL), so a skipped entry holds no lookup reference. POSIX lets a listing omit an entry removed afteropendir.EINVAL. A read that returns no entry still fails withEINVALif it stopped at an entry that the guest's buffer cannot hold, which it checks before the lookup.Unchanged: plain
FUSE_READDIRstill lists the names as listed; a listed name on the directory's own host device that now reaches another object, such as a file renamed over it, still fails the read withEIO; and any other error still stops the read after the entries before it, as microsoft/nvx#1611 made it. No saved state, protocol, ABI, or format, and no version of any of them, changes.Kept from the issue's suggested fix: the
ENOENTandEACCESskip, and anEINVALreserved for a buffer that cannot hold the next entry. Its other part, returning the entries read so far on any other error, is microsoft/nvx#1611's change below this one.Tests
Three unit tests in
virtiofs, which fail without the fix:microvm::fs_tests::readdirplus_skips_entries_unlinked_during_the_listing, the issue's reproduction: a share of 60 files is read in 4 KiB pages; after the first page, the first file that the next read reaches and a later one are unlinked; the rest of the listing must succeed, list every other file once, and leave no lookup reference once the guest forgets each entry that it received.microvm::fs_tests::readdirplus_ends_the_listing_only_after_skipping_every_entry_left: with the listing ordered as the dots, three short names, then a long one, and the short-named files unlinked, a read after the dots whose buffer holds a short name's entry but not the long one's still fails withEINVAL, since it skipped entries but stopped at one that does not fit; once the long-named file is unlinked too, the same read with a 4 KiB buffer returns an empty reply.microvm::policy_tests::readdirplus_skips_entries_that_reach_hidden_objects: on a share that hidesmarker,READDIRPLUSskips a host hard linkaliasto it, lists every other entry, and leaves no lookup reference.Validation
cargo nextest run --profile agent -p virtiofs, at this head, and with onlymicrovm/file.rsreverted to its base (the new tests kept):189dc519f, this pull request's baseENOENT, the boundary test withENOENTwhere it expectsEINVAL, and the policy test's read withEACCESnvx-kvm-test, Azure Linux 3 VM, kernel 6.189b18b57ef, the microsoft/nvx#1611 fix before the rebase onto microsoft/nvx#1617With the skip alone, keeping the old
EINVALcheck, the boundary test fails withEINVALon its last read; withEINVALkept only for a read that skipped nothing, it fails where its too-small buffer gets an empty reply instead (both on Windows).At this head, on Windows,
cargo check,cargo clippy --all-targets, andcargo doc --no-depsforvirtiofsare clean, with no warning but theLNK4199linker message that every linked artifact gets on that machine, andcargo xtask fmt --fixchanges nothing; the skipped test is the package's ignored one. On Linux, the same checks were clean at9b18b57ef. The NVX pull request that pins this head validates it again on Linux.