Skip to content

[DO NOT REVIEW] virtiofs: reach a node whose last name is gone only through its handles - #5227

Merged
Pedro Henrique Penna (ppenna) merged 1 commit into
feature/microvm/devfrom
copilot/nvx-issue-1623-stale-path-ops
Nov 22, 2026
Merged

Pedro Henrique Penna (ppenna) merged 1 commit into
feature/microvm/devfrom
copilot/nvx-issue-1623-stale-path-ops

Conversation

@ppenna

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

Copy link
Copy Markdown
Contributor

Refs microsoft/nvx#1623.

This PR's one commit, eff41b13f, sits on e3b20aef8, the head of feature/microvm/dev, where #5226 (microsoft/nvx#1609) landed. NVX pins the head of this branch in microsoft/nvx#1971, so this is a prerequisite of that NVX change, and it lands by fast-forwarding feature/microvm/dev to that exact commit, not with the merge button, which squashes.

What and why

A request about a node whose names the guest had all removed, by FUSE_UNLINK, FUSE_RMDIR, or a FUSE_RENAME over the last one, acted on whatever object had since appeared at the node's former path. VirtioFsInode::remove_alias_prefix keeps an inode's path when it removes the last alias, and every path-based operation of VirtioFsInode used that path with get_path(), except link, which microsoft/nvx#1608's fix made take its target's path from VirtioFsInode::object_path.

Through such a file node, GETATTR and STATX reported the other object's attributes under the node's inode number, OPEN opened it, SETATTR truncated it or changed its mode, and the extended-attribute requests read and changed its attributes. Through such a directory node, OPENDIR listed the other directory, and LOOKUP, CREATE, MKDIR, MKNOD, SYMLINK, LINK, UNLINK, RMDIR, and RENAME looked up, created, moved, and removed its entries. The object could be a read-only file: on a microVM share whose only writable path is out, a guest that renamed a host hard link of a read-only file over out/file could truncate that file through out/file's old node, writable through its former name, while a request through the file's own node fails with EROFS.

The fix:

  • Every other operation of VirtioFsInode that reaches its object by its path now takes the path from object_path: object_stat, get_attr, get_statx, set_attr, open, read_link, stat_fs, get_xattr, set_xattr, list_xattr, remove_xattr, check_directory_handle, and child_path, through which lookup_child, create, mkdir, mknod, symlink, link, unlink, and rename reach a directory's entries. A request about such a node that names no handle fails with ENOENT, as one through an unlinked file's former name does, and as Linux refuses to look up or create an entry in a removed directory. Requests through the node's open handles, which VirtioFs::get_file (openvmm: virtiofs: open file handles remain usable after FUSE_FORGET and with mismatched node IDs nvx#1599) serves without a path, still reach its object.
  • object_path checks that the path is one of the names that the guest knows, rather than that there is one; VirtioFsInode::add_alias makes a link's new name the path when the path no longer is one, as when an unlink of the node's other name on another request queue records its removal before the link records its name.
  • The microVM confinement check (validate_confined_paths), which validated the former name too because operations used it, validates only the names, so the former name no longer decides whether a request about the node fails, or with which error.

No lstat or other host call is added per request. No saved state, protocol, ABI, or format, and no version of any of them, changes.

Kept from the issue's suggested fix: rejecting path-based operations on inodes whose names have all been removed, with ENOENT, while handle-based operations keep using the open handle. Not taken: verifying the object's device and inode numbers at the path before each operation, which would add a host call per request and still not tell the guest's names apart from the host's.

Known limits, unchanged by this PR: a Linux guest's fstat of an unlinked file sends GETATTR without a handle when it misses the attribute cache, so it fails with ENOENT, as it already did when nothing had replaced the file's name; and a request on another queue can still race a host namespace operation and its bookkeeping, which the microVM profile's single request queue serializes.

Tests

Three unit tests in virtiofs:

  • microvm::policy_tests::a_file_whose_names_are_gone_is_reached_only_through_its_handles removes the last name of a file's node, on a share with and without the microVM profile, either by unlinking it and creating another file at its name or by renaming over it a host hard link of the read-only marker, and sends every request about the node that names no handle. Each must fail with ENOENT, while the node's handle still stats and reads its own file, and the replacement and every protected file stay unchanged.
  • microvm::policy_tests::a_directory_whose_names_are_gone_reaches_no_entry does the same for a directory's node, removed by RMDIR or by renaming another directory over it, and sends GETATTR, OPENDIR, and every request about an entry of it, into and out of it. Each must fail with ENOENT and leave the replacement directory's entries unchanged.
  • inode::tests::a_link_that_an_unlink_of_the_other_name_overtakes_keeps_the_new_name records the removal of a node's other name before a link's new name and checks that the node reaches its object through the new name.

Validation

cargo nextest run --profile agent -p virtiofs, with this PR's production sources (inode.rs and microvm/inode.rs) at its base, e3b20aef8, and the new tests applied, and at this head:

Host Without the fix (at e3b20aef8) At this head, eff41b13f
Windows 11, local the three new tests fail: every request of the file test but LINK reaches the replacement (READLINK EINVAL, GETXATTR ENODATA, the others succeed), every request of the directory test succeeds on the replacement directory, and the linked node keeps the name old 227 passed, 3 skipped (tests that are ignored on Windows)
nvx-kvm-test, Azure Linux 3.0 VM, kernel 6.18 the same failures; on both hosts, in each rename-over case the stale file node truncates marker, which the microVM share makes read-only, to "" 226 passed, 1 skipped (an ignored test)

The same tests failed and passed the same way on both hosts at this PR's earlier bases, 71025ece7 (#5218's commit on #1599's) and b37617f7f (#5226's earlier head), before the stack moved under it; the commit is patch-identical to those versions.

At this head, on both hosts, cargo check, cargo clippy --all-targets, and cargo doc --no-deps for virtiofs pass without warnings, except the LNK4199 linker message that every linked artifact gets on the Windows machine; cargo xtask fmt --fix changes nothing. Two code reviews found no remaining issue: the first's concurrent LINK and UNLINK case is the add_alias change above, and its other point, a request racing a host rename on another request queue, is out of scope, since the microVM profile has one request queue.

@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

A request about a node whose names the guest had all removed, by
FUSE_UNLINK, FUSE_RMDIR, or a FUSE_RENAME over the last one, acted on
whatever object had since appeared at the node's former path
(microsoft/nvx#1623). Through such a file node, GETATTR and STATX
reported that object's attributes under the node's inode number, OPEN
opened it, SETATTR truncated it or changed its mode, and the extended
attribute requests read and changed its attributes. Through such a
directory node, OPENDIR listed that directory, and LOOKUP, CREATE,
MKDIR, MKNOD, SYMLINK, LINK, UNLINK, RMDIR, and RENAME looked up,
created, moved, and removed its entries. The object could be a
read-only file whose host hard link inside a writable path the guest
had renamed over the node's name: the node, writable through its
former name, then truncated the file, which a request through the
file's own node refuses with EROFS.

VirtioFsInode::remove_alias_prefix keeps an inode's path when it
removes the last alias, and every path-based operation of
VirtioFsInode used that path, except VirtioFsInode::link, which
microsoft/nvx#1608's fix made take its target's path from
VirtioFsInode::object_path, which fails with ENOENT once the guest
knows no name for the object.

Every other operation of VirtioFsInode that reaches its object by its
path now takes the path from object_path too: object_stat, get_attr,
get_statx, set_attr, open, read_link, stat_fs, get_xattr, set_xattr,
list_xattr, remove_xattr, and check_directory_handle; and so does
child_path, through which lookup_child, create, mkdir, mknod, symlink,
link, unlink, and rename reach a directory's entries. A request about
such a node that names no handle thus fails with ENOENT, as one
through an unlinked file's former name does, and as Linux refuses to
look up, create, or list entries of a removed directory, while
requests through the node's open handles, which VirtioFs::get_file
serves without a path, still reach its object.

object_path now checks that the path is one of the names that the
guest knows, rather than that there is one. VirtioFsInode::add_alias,
which records a FUSE_LINK's name after the host link, makes that name
the path when the path no longer is one, as when a FUSE_UNLINK of the
node's other name on another request queue records its removal first;
object_path would otherwise use the removed name, or now fail. The
microVM profile's confinement check, which validated the former name
as well because operations used it, thus validates only the names, so
the former name no longer decides whether a request about the node
fails, or with which error.

a_file_whose_names_are_gone_is_reached_only_through_its_handles and
a_directory_whose_names_are_gone_reaches_no_entry remove the last name
of a file's and a directory's node, on a share with and without the
microVM profile, either by unlinking or removing it and creating
another at its name, or by renaming another entry over it, and send
every request about the node that names no handle.
a_link_that_an_unlink_of_the_other_name_overtakes_keeps_the_new_name
records the removal of a node's other name before a link's new name.
Without the fix, at e3b20ae, microsoft/nvx#1609's fix, which stacks
on microsoft/nvx#1608's, on Windows and on a Linux KVM host, every
request of the first two tests but FUSE_LINK reaches the new object:
READLINK and GETXATTR fail with its errors, EINVAL and ENODATA, and
the others succeed, so the file node truncates the file renamed over
its name, which the microVM share makes read-only; and the third
test's node keeps the removed name. With the fix, each request fails
with ENOENT and changes nothing, the node's handle still reads and
stats its file, the linked node reaches its object through the new
name, and the package's tests pass on both hosts.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@ppenna
Pedro Henrique Penna (ppenna) force-pushed the copilot/nvx-issue-1623-stale-path-ops branch from 0000e99 to eff41b1 Compare November 22, 2026 15:02
@github-actions github-actions Bot removed the unsafe Related to unsafe code label Nov 22, 2026
Pedro Henrique Penna (ppenna) added a commit to microsoft/nvx that referenced this pull request Nov 22, 2026
Map position 368, the commit of microsoft/openvmm#5227, which NVX now
pins at eff41b13f, 242 commits past the mapped tip:

- 368, virtiofs: reach a node whose last name is gone only through
  its handles. Every request about a node whose names the guest has
  all removed, other than those through the node's open handles,
  fails with ENOENT, as one through an unlinked file's former name
  does, rather than reach whatever object has since appeared at the
  node's last name: VirtioFsInode's operations and its child_path take
  the path from position 352's object_path, which now checks that the
  path is one of the node's names. They used upstream's get_path, the
  name that position 048 keeps when it drops a node's last name, so
  GETATTR, OPEN, SETATTR, and the extended-attribute requests acted on
  the other object, a removed directory's node reached the entries of
  the directory created in its place, and a file's node whose name a
  read-only file had taken could truncate that file.

Position 368 is not yet assigned to a PR. It changes upstream's
operations in inode.rs, position 048's add_alias, position 083's
object_stat, position 352's object_path, and the names that PR27's
position 126 has the microVM's validate_confined_paths check, so
assigning it revisits PR13, PR18, and PR27, but it fixes no defect of
positions 048, 083, or 126: upstream main, bf353460f, has the defect,
since its nodes keep the name of their last lookup through removals.
It needs position 352's object_path. Replaying it on upstream main
conflicts in inode.rs and in the microVM's inode.rs and
policy_tests.rs, so it cannot go upstream on its own. The Scope also
records that feature/microvm/dev now stands at position 367,
e3b20aef8, where microsoft/openvmm#5226 landed positions 366 and 367.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@ppenna
Pedro Henrique Penna (ppenna) merged commit eff41b1 into feature/microvm/dev Nov 22, 2026
102 of 105 checks passed
Pedro Henrique Penna (ppenna) added a commit to microsoft/nvx that referenced this pull request Nov 22, 2026
OpenVMM's virtio-fs server lists a microVM directory once, numbering
each entry as the host lists it, and a FUSE_READDIRPLUS looks each
listed name up again. It failed the read with EIO at an entry on the
directory's own host device whose lookup reported another inode number
than the listing, to refuse a name that a rename replaced since the
listing. But the host lists some entries on a directory's own device by
another number than their lookup reports: a btrfs snapshot lists the
empty placeholder that it holds of a nested subvolume by the
subvolume's ID, while a lookup reaches a directory numbered 2, and a
directory lists a mount point of its own file system, such as a bind
mount of one of its directories, by the number of what the mount
covers. A guest could therefore list no directory that held such an
entry, with ls, find, and the like (#1605); the root of a
btrfs subvolume, on a device of its own, has listed since
#1619.

Pin microsoft/openvmm 6323fa7b924ac450eb28ef968b4f460b0864d35d, one
commit on eff41b13f, the head of microsoft/openvmm#5227, where
feature/microvm/dev now stands:

- virtiofs: list btrfs placeholders and bind mounts in microVM
  READDIRPLUS. When an entry's lookup reports another number than the
  listing, READDIRPLUS checks that the node's path still reaches the
  handle's directory and lists the directory again, at most once per
  read: it lists the entry, as its lookup reports it, if the host still
  lists the name by the listed number, still fails with EIO if the host
  lists it by another number or by 0, and skips it if the host no
  longer lists it. Its bind-mount test fails without the change on
  Linux (nvx-kvm-test), and its tests that a replaced name still fails
  pass on Windows and on Linux.

No saved state, protocol, ABI, or format, and no version of any of
them, changes. The protocol vectors and CPU profiles that nvx copies
are unchanged.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Pedro Henrique Penna (ppenna) added a commit to microsoft/nvx that referenced this pull request Nov 22, 2026
Map position 369, the commit of microsoft/openvmm#5228, which NVX now
pins at 6323fa7b9, 243 commits past the mapped tip:

- 369, virtiofs: list btrfs placeholders and bind mounts in microVM
  READDIRPLUS. A microVM READDIRPLUS lists an entry that the host lists
  by another inode number than a lookup reports on the directory's own
  device, such as the placeholder that a btrfs snapshot holds of a
  nested subvolume or a bind mount from the directory's own file
  system, rather than fail with EIO as at a name that a rename
  replaced: when the numbers differ, it checks that the node's path
  still reaches the handle's directory and lists the directory again,
  at most once per read, and it still fails with EIO if the host lists
  the name by another number or by 0.

Position 369 is not yet assigned to a PR. It fixes a defect of PR18's
position 083, the check that a listed name still reaches the listed
object, but it changes the check as position 332 limits it to entries
on the directory's device, by the device numbers that position 331
records, and a test needs position 346's get_file, so it is no PR18
fixup and follows position 368. 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 and fs_tests.rs,
which upstream main lacks, so it cannot go upstream on its own. The
Scope also records that feature/microvm/dev now stands at position
368, eff41b13f, where microsoft/openvmm#5227 landed it.

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/.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant