Repository navigation
[DO NOT REVIEW] virtiofs: accept FSYNCDIR through the synthetic root's handle - #5222
Merged
Pedro Henrique Penna (ppenna) merged 7 commits intoNov 22, 2026
Conversation
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>
FUSE_LINK to a node whose names the guest had all removed, by FUSE_UNLINK or by a FUSE_RENAME over the last one, linked whatever object had since appeared at the node's former path (microsoft/nvx#1608). It recorded the new name for the node and replied with the node's ID and inode number but that object's attributes, so two nodes stood for one object. 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. VirtioFsInode::remove_alias_prefix keeps an inode's path when it removes the last alias, since other requests about the node still use it, and VirtioFsInode::link linked the target at that path without checking that it still names the target's object. VirtioFsInode::object_path returns an inode's path only while the guest still knows a name for its object, and fails with ENOENT once the guest has removed them all. VirtioFsInode::link takes the target's path from it, so FUSE_LINK to such a node fails with ENOENT, as Linux's linkat does for an unlinked file, before it changes the host or the node. The check sits where the path is used rather than in the FUSE_LINK handler, so that the other requests about such a node, which still use its former path (microsoft/nvx#1623), can share it. a_link_to_a_node_whose_names_are_gone_links_nothing removes the last name of a file's node on a microVM share, either by unlinking the file and creating another at its name, or by renaming a host hard link of a read-only file over it, and then links the node. Without the fix, at 2b90ba3, microsoft/nvx#1599's fix on feature/microvm/dev b51f915, on Windows and on a Linux KVM host, both links succeed; with it, both fail with ENOENT, create no host entry, and leave the node without names, and the package's tests pass on both hosts. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
A microVM aggregate's file child whose host path was a bare file name, as `seed.txt`, or a symbolic link to a regular file passed MicroVmAggregateChild::validate_root_path, but attaching it failed (microsoft/nvx#1618): for the bare name, with ENOENT on Linux or EINVAL on Windows, and for the link, with EACCES. The child's identity, which microvm_file_identity computes and validate_root_path checks, is that of the file that the path resolves to, from the current directory and through symbolic links, since both canonicalize the path. open_microvm_volume split the path as given instead: it opened the path's parent, which is empty for a bare name, and exposed the path's last name, which names a link rather than its target, so the lstat of the child's root found a symbolic link, which a file child's volume refuses. open_microvm_volume now resolves a symbolic link at the end of a file child's path to its final target, as the identity does, and makes any other path absolute, which keeps the name that the path gives: on Windows, canonicalization would turn a path to the default stream of a file, `file::$DATA`, into the file's, which the name check of microsoft/nvx#1614 would then accept. That check applies to the name that the volume uses, which for a link is its target's, so a link whose own name has a colon attaches, and a link to a file whose name has one is refused. The OpenVMM command line passes canonical paths and refuses links, so it is unchanged, as are directory shares and children, whose volumes open the directories that their paths resolve to. The saved state is unchanged. Tests, in virtiofs' microVM aggregate tests: a file child given by a bare name in the current directory, by `./` and the name, or on Windows by its drive and the name, attaches, and the guest reads it; one given by an absolute, a relative, or a chained link attaches as the link's target, which the guest reads and writes; and a link to a file that the volume cannot name is refused, on Windows a link to a stream, while on Linux a link with a colon in its own name attaches. Without the fix, on top of that of microsoft/nvx#1614, the bare name fails to attach, with EINVAL on Windows and ENOENT on Linux (Azure Linux 3.0, nvx-kvm-test), the links fail with EACCES, and on Linux the link with a colon in its own name is refused for that name. With it, the new tests and the package's other tests pass on Windows, with native symbolic links allowed for the tests that need them, and on Linux. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
FUSE_GETATTR and FUSE_STATX of a microVM aggregate's synthetic root reported a link count of two plus one per child, file children included, so the count disagreed with the root's listing (microsoft/nvx#1632): two file children and a directory child gave 5, where a directory with one subdirectory has 3. A directory's link count is two, for its `.` and the entry that names it, plus one for the `..` of each subdirectory, which find and other fts-based tools use to tell how many subdirectories a directory holds. VirtioFs::synthetic_root_nlink counted every entry of the aggregate's registry, while a read of the root, in VirtioFs::write_child_entry, lists a child that exposes a regular file, a microVM file child, as DT_REG, and every other child as DT_DIR. Count only the children that expose no file, which a read of the root lists as directories. An aggregate without file children, such as any aggregate outside a microVM, reports the same count as before. microvm::aggregate_fs_tests:: synthetic_root_links_only_its_child_directories checks FUSE_GETATTR and FUSE_STATX of the roots of three microVM aggregates, of two file children and a directory child, of the two file children alone, and of two directory children, against two plus the directories that FUSE_READDIR lists: 3, 2, and 4. Without the fix, the test fails on Windows and on Linux (Azure Linux 3.0, nvx-kvm-test), where the first root reports 5; 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>
In a user namespace whose setgroups file says "allow", as one that newgidmap maps from a subordinate GID range does, a thread with CAP_SETGID there may drop its supplementary groups. getgroups reports each group that the namespace does not map as the kernel's overflow GID, 65534 by default, and setgroups refuses a GID that the namespace does not map, so a thread can never regain such a group once it drops it. with_fs_identity's switch saved the list that getgroups reported, dropped the groups, and restored the list afterwards: with the overflow GID unmapped, the restore failed with EINVAL and the panic of SwitchedCredentials::drop aborted OpenVMM, and with it mapped, the restore replaced the thread's unmapped groups with the one group that the overflow GID maps to. Position 158's switch dropped groups whenever one differed from the target GID, and the overflow GID change for microsoft/nvx#1600 also drops them when the target GID is the overflow GID. A group that may be unmapped can be neither kept, since it may be any group, nor dropped, since the thread could not regain it. The switch therefore takes the groups from mapped_groups, which fails with EPERM before anything changes whenever a supplementary group reads as the overflow GID in a namespace that may not map every group. That refusal covers the case that the overflow GID change drops groups for, so it replaces may_report_other_groups_as and that drop. mapped_groups reads /proc/self/gid_map, about 3.4 us on an Azure Linux 3 test VM, for a thread with supplementary groups, and the initial user namespace, which maps every ID, needs nothing more. In another namespace, it reads the groups again between two reads of the overflow GID, which the administrator may change at any time, and fails unless it can read the overflow GID, both reads agree, and no group has that GID. The virtio-fs Guide says that such a namespace fails every request that runs as its caller. unmapped_groups_fail_closed_with_privilege, which requires CAP_SETGID, gives a child process a group, maps the child's new user namespace without denying setgroups and without that group, and runs the test again as the namespace's root. There, a switch to the child's own identity must fail with EPERM without running the operation, and the child must keep the unmapped group, as chmod's handling of S_ISGID on a file of that group shows, whether the namespace leaves the overflow GID unmapped, maps it to another group, or maps it to the child's own GID; the test reports every layout that fails. Run as root on an Azure Linux 3 VM with kernel 6.18.57 and the default overflow GID, it failed in all three layouts without this change: the first panicked with "failed to restore the thread's supplementary groups: Error(EINVAL (22))", and the others returned Ok(()) rather than EPERM. With the change, it passes. The unprivileged overflow GID test of microsoft/nvx#1600 now fails at the refusal rather than at setgroups. Fold into position 158 at the next reorganization. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
fsync and fdatasync of a descriptor of an aggregate's synthetic root, as `sync` calls for a directory that it is given, failed with EBADF, which POSIX reserves for a descriptor that is not open (microsoft/nvx#1624). The Linux FUSE client sends both as FUSE_FSYNCDIR, with the node of the directory and the handle that FUSE_OPENDIR returned. FUSE_OPENDIR of the synthetic root returns SYNTHETIC_ROOT_FH, which names no open file, and READDIR, READDIRPLUS, and RELEASEDIR, and GETATTR and STATX through a handle, recognize it with the root's node before they look a handle up. VirtioFs::fsync_dir looked it up in the handle map, found nothing, and failed with EBADF. fsync_dir now succeeds for the synthetic root's handle with the root's node, as release_dir does, before it looks a handle up: the root keeps its entries only in memory, so it has nothing to write back. ENOSYS would not do, since the Linux client takes it for the whole mount and stops syncing the children's directories too. Any other handle or node reaches get_file as before. aggregate::tests::synthetic_root_handle_accepts_fsyncdir checks that FUSE_FSYNCDIR through an aggregate root's handle succeeds with and without FUSE_FSYNC_FDATASYNC, and that the handle with a child's node, and another handle with the root's node, still fail with EBADF. At its parent, 655bc31, the change for microsoft/nvx#1606 on the stack of changes above feature/microvm/dev 3288834, the test fails with EBADF on Windows and on a Linux KVM host; with the fix, it 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 05:40
|
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
21b1a55
into
feature/microvm/dev
102 of 105 checks passed
syeedali
pushed a commit
to syeedali/nvx
that referenced
this pull request
Nov 23, 2026
Map position 356, the commit of microsoft/openvmm#5222, which NVX now pins at 21b1a55d0, 230 commits past the mapped tip: - 356, virtiofs: accept FSYNCDIR through the synthetic root's handle. VirtioFs::fsync_dir succeeds for the handle that FUSE_OPENDIR returns for an aggregate's synthetic root, with the root's node, as release_dir does, rather than look that sentinel up in the handle map and fail with EBADF, so fsync and fdatasync of a descriptor of the root succeed in the guest. Position 356 is not yet assigned to a PR. It fixes upstream's fsync_dir, which microsoft/openvmm#3821 adds and which no chain commit changes but position 346, which passes it the request's node, and it changes nothing that a mapped PR adds. Upstream main, bf353460f, has the defect, and replaying the commit there conflicts in lib.rs, next to position 346's node, and in aggregate_tests.rs, among position 350's imports. The same change made on upstream's code applies there without conflicts, and virtiofs type-checks there with its tests, which pass, so it can go upstream on its own in that form. 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 checked only that the guest may modify the two names of a rename, but a rename also moves everything below them, and a microVM share's access policy can hide a path below a writable one (microsoft#1601). Under --mount-deny logs/secret, a guest that renamed logs, or exchanged it with another directory on a Linux host, moved the hidden secret to a visible name, where it could list and remove it, and open one that the host had recreated after attaching the share. Once the host had removed such a directory, the guest could also rename one of its own onto that name and so put its entries at the denied path. Pin microsoft/openvmm 49fc14eeb5971fc42043837fecd2c243b997ef54, one commit on 21b1a55d0, the head of microsoft/openvmm#5222: - virtiofs: refuse renames of directories that hold denied paths. VirtioFs::rename requires that the guest may modify every path at and below both of its names, as SubtreePolicy::is_subtree_writable decides, and otherwise fails with EROFS before the host changes anything. Its tests fail without the change on Windows and on Linux (nvx-kvm-test). 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#1624.
Stacked on #5221 (microsoft/nvx#1606), whose head is
655bc319d; only the top commit,21b1a55d0("virtiofs: accept FSYNCDIR through the synthetic root's handle"), belongs to this PR. The 6 commits beneath it,189dc519fthrough655bc319d, belong to the pull requests of the issues stacked below it, onfeature/microvm/devat2a483a06f. NVX pins the head of this branch, so this is a prerequisite of the NVX change that pins it, and it lands after #5221 by fast-forwardingfeature/microvm/devto that exact commit, not with the merge button, which squashes.What and why
fsync()andfdatasync()of a descriptor of the synthetic root of an aggregate virtio-fs device failed withEBADF, which POSIX reserves for a descriptor that is not open. A Linux guest sends both asFUSE_FSYNCDIR, with the root's node and the handle thatFUSE_OPENDIRreturned, assync DIRandsync -d DIRdo for a directory that they are given: in a microVM whose aggregate is mounted at/run/nvx/shares,sync /run/nvx/sharesfailed withBad file descriptor.FUSE_OPENDIRof the synthetic root returns the sentinelSYNTHETIC_ROOT_FH, which names no open file.READDIR,READDIRPLUS, andRELEASEDIR, andGETATTRandSTATXthrough a handle, recognize it with the root's node before they look a handle up, butVirtioFs::fsync_dirlooked it up in the handle map, found nothing, and failed withEBADF. Upstream's aggregate support (#3821) added the sentinel and the handlers that recognize it, and upstream main still has the defect.The fix:
fsync_dirsucceeds for the synthetic root's handle with the root's node, asrelease_dirdoes, before it looks a handle up, since the root keeps its entries only in memory and has nothing to write back. It does not answerENOSYS, which the Linux client takes for the whole mount, after which it would stop sendingFSYNCDIRfor the children's directories too. Any other handle or node reachesget_fileas before, with the node check that the change for microsoft/nvx#1599 (c819952cf, now onfeature/microvm/dev) added. The comments onSYNTHETIC_ROOT_FHand inopen_dirthat list the handlers that recognize the sentinel now namefsync_dirtoo. No saved state, protocol, ABI, or format, and no version of any of them, changes.Kept from the issue's suggested fix: the check of
is_synthetic_root_handlebefore the lookup, and the success. Changed: the test sits among the aggregate module's unit tests, on an aggregate thatVirtioFs::new_aggregatemakes, which upstream has too, rather than in a new integration-test file, sends well-formedFUSE_OPENDIR,FUSE_LOOKUP, andFUSE_FSYNCDIRrequests, and also checks that the root's handle with a child's node, and another handle with the root's node, still fail withEBADF.Out of scope:
FUSE_FSYNC, which a Linux guest sends only for files, still fails withEBADFfor the root's handle; and the handle map'su64::MAXandSYNTHETIC_ROOT_FH(microsoft/nvx#1627) are handled separately.Tests
One unit test in
virtiofs,aggregate::tests::synthetic_root_handle_accepts_fsyncdir: on an aggregate with one child, it opens the root withFuse::open_dirand sendsFUSE_FSYNCDIRthroughFuse::fsync_dir:FUSE_FSYNC_FDATASYNC, each succeeds, where both failed withEBADFbefore the fix;EBADF, since the guest opened no other handle.Validation
cargo nextest run --profile agent -p virtiofsat this head, and the new test withlib.rsof the parent,655bc319d(the fix reverted):21b1a55d0flags 0x0,left: Err(Error(EBADF (9))),right: Ok(())nvx-kvm-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.cargo xtask fmt --fixchanges nothing. Before the rebase onto this stack, the same results held onb51f9156cunder the changes for microsoft/nvx#1598 and microsoft/nvx#1617, and on a trial cherry-pick onto the change for microsoft/nvx#1599, where the test without the fix also fails withEBADF.In the guest, on KVM on
nvx-kvm-test, with the aggregate of NVX'sfilesystem-sharesmicroVM scenario mounted at/run/nvx/sharesand the OpenVMM of NVX's releasev0.1.0-dev.3e98eff40820(b51f9156c),sync /run/nvx/sharesandsync -d /run/nvx/sharesboth fail withBad file descriptor. With OpenVMM built from this head (build-openvmm --backend kvm, provenance21b1a55d0, clean), both succeed, and NVX'sfilesystem-shares,platform-aggregate-export,platform-filesystem, andfilesystem-snapshotscenarios pass on KVM on the same host.