Skip to content

[DO NOT REVIEW] virtiofs: resolve a microVM file child's path as its identity does - #5219

Merged
Pedro Henrique Penna (ppenna) merged 7 commits into
feature/microvm/devfrom
copilot/nvx-issue-1618-aggregate-child-paths
Nov 22, 2026
Merged

Pedro Henrique Penna (ppenna) merged 7 commits into
feature/microvm/devfrom
copilot/nvx-issue-1618-aggregate-child-paths

Conversation

@ppenna

@ppenna Pedro Henrique Penna (ppenna) commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Refs microsoft/nvx#1618.

Stacked on #5218 (microsoft/nvx#1608): only the top commit, de700ffc2, 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 #5218 by fast-forwarding feature/microvm/dev to that exact commit, not with the merge button, which squashes.

What and why

A microVM aggregate's file child (MicroVmAggregateChild::new_file) whose host path is a bare file name, such as seed.txt, or a symbolic link to a regular file passes MicroVmAggregateChild::validate_root_path, but VirtioFs::new_microvm_aggregate then fails to attach it: for the bare name with ENOENT on Linux or EINVAL on Windows, from new_volume(""), 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, since microvm_object_identity canonicalizes the path: from the current directory, and through symbolic links to their final target. open_microvm_volume split the path as given instead: it opened root_path.parent(), the empty path for a bare name, and exposed root_path.file_name(), a link's own name for a link, so the lstat of the child's root in VirtioFsInode::new found S_IFLNK, which VirtioFsVolume::ensure_object_allowed refuses in a volume that exposes a file.

The fix, in open_microvm_volume: a file child's path that ends in a symbolic link is resolved to its final target with std::fs::canonicalize, as the identity is, and any other path is made absolute with std::path::absolute, so the volume opens the directory of the file whose identity the child has and finds the file there by its name. The name check of microsoft/nvx#1614, which refuses a name with \ or :, now checks the name that the volume uses, the target's for a link: a link whose own name has a colon attaches, and a link to a file whose name has one is refused, as is, on Windows, a link to an alternate data stream.

Only a link is canonicalized: on Windows, canonicalize turns a path to the default stream of a file, file::$DATA, into the file's own path, which the check of microsoft/nvx#1614 would then accept, and it turns a name into its on-disk case or long form, which would change the name that a snapshot records for a path that attached before. std::path::absolute keeps the name that a path gives, and resolves a drive-relative Windows path, such as C:seed.txt, against the drive's current directory, where Path::parent would have given the drive's root.

Kept from the issue's suggested fix: a link resolves to its final target, as a directory share's root does, and a bare name opens the current directory. Changed: a path that is not a link is made absolute rather than given . as its parent, which also covers drive-relative Windows paths, and only a link is canonicalized, for the reasons above. Rejected: refusing links in microvm_file_identity, which would make a file child refuse what a directory child and the identity's documented resolution accept.

Unchanged: the OpenVMM command line, which passes canonical paths and refuses links; directory shares and children, whose volumes open the directories that their paths resolve to; and the saved state. No saved state, protocol, ABI, or format, and no version of any of them, changes.

Tests

Three unit tests in virtiofs, among the microVM aggregate tests (microvm::aggregate_fs_tests):

  • a_file_child_may_be_named_relative_to_the_current_directory: a file in the test's current directory, given by its bare name, by ./ and its name, and on Windows by its drive and its name, attaches, and the guest reads it.
  • a_file_child_may_be_a_symbolic_link_to_its_file: an absolute link in another directory, a link relative to its own directory, and a link to a link each attach as their target, which the guest sees as a regular file, reads, and writes, while the link stays a link.
  • a_file_child_link_needs_a_target_that_its_volume_can_name: a link to a file named a:b, or on Windows to the stream target:stream, is refused, and on Linux a link named link:target to a file that the volume can name attaches.

The last two are ignored on Windows, which needs permission to create native symbolic links, as stale_directory_paths_do_not_follow_native_links is; they ran on the Windows host below with that permission.

Validation

cargo nextest run --profile agent -p virtiofs, at the base with the new tests applied (the fix reverted), and with the fix:

Host Without the fix With the fix, at this head
Windows 11, local, where native symbolic links can be created at 3aefff9ba: a_file_child_may_be_named_relative_to_the_current_directory fails with failed to initialize filesystem volume: EINVAL, and a_file_child_may_be_a_symbolic_link_to_its_file with EACCES 205 passed, 3 skipped (the tests that need native symbolic links); 208 passed with --run-ignored all
nvx-kvm-test, Azure Linux 3.0 VM at 28f2e5793, microsoft/nvx#1614's change: all three new tests fail, the bare name with failed to initialize filesystem volume: ENOENT, the links with EACCES, and the link named link:target because of its own name 213 passed, 1 skipped (it needs CAP_SETUID), as at the base

At this head, on Windows, cargo check, cargo clippy --all-targets, and cargo doc --no-deps for virtiofs are clean, with no warning but the LNK4199 linker message that every linked artifact gets on that machine, and cargo xtask fmt --fix changes nothing. On nvx-kvm-test, cargo clippy --all-targets for virtiofs is clean at this head too. NVX's virtio-fs microVM scenarios, among them the two that attach file children, filesystem-shares and platform-aggregate-export, pass on KVM on nvx-kvm-test with OpenVMM built from this head: platform-filesystem, filesystem-snapshot, filesystem-shares, filesystem-policy, filesystem-owner, denied-filesystem-paths, platform-aggregate-export, and filesystem-comma-paths.

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>
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>
@github-actions github-actions Bot added Guide release-nvx Targets a branch under feature/microvm/. unsafe Related to unsafe code labels Nov 22, 2026
@github-actions

Copy link
Copy Markdown

⚠️ Unsafe Code Detected

This PR modifies files containing unsafe Rust code. Extra scrutiny is required during review.

For more on why we check whole files, instead of just diffs, check out the Rustonomicon

@ppenna
Pedro Henrique Penna (ppenna) merged commit de700ff into feature/microvm/dev Nov 22, 2026
104 of 105 checks passed
syeedali pushed a commit to syeedali/nvx that referenced this pull request Nov 23, 2026
…admap

Map position 353, the commit of microsoft/openvmm#5219, which NVX now
pins at de700ffc2, 227 commits past the mapped tip:

- 353, virtiofs: resolve a microVM file child's path as its identity
  does. open_microvm_volume opens the file that the host path of an
  aggregate's file child resolves to, as the child's identity does: it
  resolves a symbolic link at the path's end to its final target, and
  makes any other path absolute, which keeps the name that the path
  gives. A bare file name opened the path's empty parent, which
  failed, and a link exposed the link itself, which a file child
  refuses.

Position 353 is not yet assigned to a PR. It fixes a defect of
position 165, which no PR maps, and follows it, as position 343 does,
whose name check now applies to the name that the volume uses.
Replaying the commit on upstream main, bf353460f, conflicts in the
microVM's fs.rs and aggregate_fs_tests.rs, which upstream main lacks,
so it cannot go upstream on its own.

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 answered FUSE_GETATTR and FUSE_STATX of a
microVM aggregate's synthetic root with a link count of two plus one
per child, file children included, while a read of the root lists a
file child as a regular file (microsoft#1632). A directory's link
count is two plus one per subdirectory, so an aggregate with file
children reported subdirectories that its root does not hold: two file
children and a directory child gave 5 rather than 3.

Pin microsoft/openvmm afa67d6a67d76a573439739bf98f8bc85158adcc, one
commit on de700ffc2, the head of microsoft/openvmm#5219:

- virtiofs: count only child directories in the synthetic root's
  nlink. The root's link count is two plus the children that a read
  of the root lists as directories. An aggregate without file
  children reports the same count as before. Its test fails 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Guide release-nvx Targets a branch under feature/microvm/. unsafe Related to unsafe code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant