Skip to content

[DO NOT REVIEW] virtiofs: restore microVM handles opened with access mode 3 - #5282

Merged
Pedro Henrique Penna (ppenna) merged 2 commits into
feature/microvm/devfrom
copilot/nvx-issue-2125-virtiofs-access-mode-3
Nov 25, 2026
Merged

Pedro Henrique Penna (ppenna) merged 2 commits into
feature/microvm/devfrom
copilot/nvx-issue-2125-virtiofs-access-mode-3

Conversation

@ppenna

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

Copy link
Copy Markdown
Contributor

Refs microsoft/nvx#2125.

Stacked on #5281 (350018ce4, branch copilot/nvx-issue-2135-virtiofs-last-node-id), whose commit this pull request includes; only its top commit, 770bc61e7, belongs to it. NVX pins the head of this branch, 770bc61e7b2c683b092bffb5c8cd83b8696cf54a, in the NVX pull request of microsoft/nvx#2125 (branch agents/issue-2125-virtiofs-access-mode-3), so this pull request is a prerequisite of that NVX change. It lands after #5281 by fast-forwarding feature/microvm/dev to that exact commit, not with the merge button, which squashes.

What and why

A microVM guest that opened a virtio-fs file with access mode 3 (O_ACCMODE == 3, lx::O_NOACCESS) and held it open could save the VM's state, but its restore failed with "saved handle has invalid access mode", on read-write and read-only shares alike. Linux's open(2) reserves access mode 3 to check for read and write permission and return a descriptor that can neither read nor write, and the guest's FUSE client sends that access mode to FUSE_OPEN, which accepts it: util::open_flags keeps the access mode, and check_open_readonly refuses only the opens that opens_for_writing names, those for O_WRONLY or O_RDWR, or with O_TRUNC. So FUSE_OPEN gives such a handle on a read-only share or child and outside a microVM share's writable paths too.

The restore (vm/devices/virtio/virtiofs/src/microvm/state.rs) disagreed with FUSE_OPEN about such a handle twice, since the microVM's persistence added it:

  • reopen_flags rejected access mode 3 outright.
  • validate_microvm_state took every access mode other than O_RDONLY for one that writes, so a read-only share or child, or a node outside the writable paths, would still have refused the handle without that rejection.

reopen_flags now keeps every access mode, and the validation takes a handle for one that writes as opens_for_writing takes the open that reopens it, which drops O_CREAT, O_EXCL, and O_TRUNC: only O_WRONLY and O_RDWR need a writable node, as at FUSE_OPEN. A restored handle keeps access mode 3, so it still neither reads nor writes: on Linux the host descriptor has neither access, and on Windows open_flags_to_access_mask gives it only the minimum permissions. The alternative, refusing access mode 3 at FUSE_OPEN, would refuse a valid Linux open that the device already serves.

No saved state, protocol, ABI, or format, and no version of any of them, changes.

Tests

a_handle_that_neither_reads_nor_writes_survives_save_and_restore (microvm/fs_tests.rs) opens a file with access mode 3 on a read-write share, on a read-only share, and outside the writable paths of a read-write share, saves and restores the state, and expects the restored handle to serve its node (FUSE_GETATTR with FUSE_GETATTR_FH) and to fail FUSE_READ and FUSE_WRITE with EBADF, leaving the file unchanged. The existing readonly_profile_rejects_a_writable_saved_handle, restore_rejects_a_writable_handle_outside_the_writable_paths, and the read-only child case of aggregate_state_rejects_changed_children still check that an O_RDWR handle is refused there.

Validation

On Windows 11 Enterprise (NTFS) and on a Linux KVM test VM (Azure Linux 3, kernel 6.18, x86_64, tmpfs):

  • At 1633b3797, the new test fails with "saved handle has invalid access mode". With only the reopen_flags change, it fails with "read-only microVM profile cannot restore a writable handle" on the read-only share, and with "microVM access policy cannot restore a writable handle outside its writable paths" outside the writable paths (Windows). With the fix, it passes.
  • On the fix's first base, 1633b3797, cargo check, cargo clippy --all-targets, and cargo doc --no-deps of virtiofs have no warnings, and cargo nextest run --profile agent -p virtiofs passes 241 tests on Windows (3 skipped) and 242 on Linux (1 skipped). cargo xtask fmt --fix changes nothing.
  • After the rebase onto [DO NOT REVIEW] virtiofs: let a new microVM object take the last node ID #5281, whose only conflict was the test file's imports, at 770bc61e7: cargo clippy --all-targets -p virtiofs has no warnings on Windows and Linux, nor do cargo check and cargo doc --no-deps on Linux; cargo nextest run --profile agent -p virtiofs passes 242 tests on Windows (3 skipped) and 243 on Linux (1 skipped); cargo xtask fmt --fix changes nothing.

A microVM MKDIR, MKNOD, SYMLINK, or CREATE that reserved the last node
ID that the node table hands out, u64::MAX - 1, made its object on the
host and then failed with ENOSPC (microsoft/nvx#2135). The guest saw the
request fail while the object stayed on the host, and every retry under
another name left another object behind. A restore reaches that state,
since it accepts any next node ID above the saved ones; live requests
would need some 2^64 allocations.

These requests reserve the node ID of their object before they make it,
so that a full table refuses them before the host changes, and insert
the object's node with that ID afterwards. InodeReservation::insert
checked that insert against the microVM limits with
InodeMap::preflight_microvm_insert, which, for a node of its own, also
requires that the table can hand out its next node ID. The reservation
has already taken that ID, so the check asked about the ID after it:
after a reservation of u64::MAX - 1, the table's next node ID is
u64::MAX, which it never hands out, and the insert failed although it
needed no other ID. The check dates from the microVM profile
(dbf0fa4); before 3019375 made u64::MAX - 1 the last node ID, it
failed this way after a reservation of u64::MAX. FileReservation::insert
checks only the handle limit, so handles are not affected.

Check a reserved insert with the new
InodeMap::preflight_microvm_reserved_insert, which checks the inode and
alias limits as before but not the next node ID. The checks that run
before the host changes, and inserts without a reservation, such as a
LOOKUP's, are unchanged.

microvm::fs_tests::a_created_object_takes_the_last_node_id restores a
state whose next node ID is u64::MAX - 1 and checks, for each of the
four requests, that the request returns node u64::MAX - 1, which a
LOOKUP of the new name returns too, that the next such request fails
with ENOSPC and leaves nothing on the host, and that the state then
saves the node and the next node ID u64::MAX, and restores. On
1633b37, MKDIR fails the test with ENOSPC; a probe there showed each
of the four requests failing with ENOSPC twice in a row, each time
leaving its object on the host, and the state saving no node, on
Windows and on a Linux KVM host. With the fix, 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 guest that opened a virtio-fs file with access mode 3 and
held it open could save the VM's state, but its restore failed with
"saved handle has invalid access mode", on read-write and read-only
shares alike (microsoft/nvx#2125). Linux's open(2) reserves access
mode 3 to check for read and write permission and return a descriptor
that can neither read nor write, and the guest's FUSE client sends
that access mode to FUSE_OPEN, which accepts it.

The restore disagreed with FUSE_OPEN about such a handle twice.
reopen_flags rejected access mode 3 outright, and
validate_microvm_state took every access mode other than O_RDONLY for
one that writes, so a read-only share or child, or a node outside the
writable paths, could not restore the handle even without that
rejection. FUSE_OPEN gives the handle there, since check_open_readonly
refuses only the opens that opens_for_writing names: those for
O_WRONLY or O_RDWR, or with O_TRUNC.

reopen_flags now keeps every access mode, and the validation takes a
handle for one that writes as opens_for_writing takes the open that
reopens it, which drops O_TRUNC, so only O_WRONLY and O_RDWR need a
writable node. A restored handle keeps access mode 3, so it still
neither reads nor writes. The format of the saved state is unchanged.

a_handle_that_neither_reads_nor_writes_survives_save_and_restore opens
a file with access mode 3 on a read-write share, on a read-only share,
and outside the writable paths of a read-write share, saves and
restores the state, and expects the restored handle to serve its node
and to fail reads and writes with EBADF. At feature/microvm/dev
1633b37, the restore fails with "saved handle has invalid access
mode" on Windows 11 (NTFS) and Azure Linux 3 (kernel 6.18, tmpfs).
Without that check alone, it fails with "read-only microVM profile
cannot restore a writable handle" on the read-only share, and with
"microVM access policy cannot restore a writable handle outside its
writable paths" outside the writable paths. With the fix, the test
passes on both hosts, and so do the other tests of the virtiofs
package.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions github-actions Bot added the release-nvx Targets a branch under feature/microvm/. label Nov 25, 2026
Pedro Henrique Penna (ppenna) added a commit to microsoft/nvx that referenced this pull request Nov 25, 2026
A microVM guest that opened a virtio-fs file with access mode 3, which
neither reads nor writes, and held it open could save the VM's state,
but its restore failed with "saved handle has invalid access mode", on
read-write and read-only shares alike (#2125). FUSE_OPEN accepts that
access mode, but the restore's validation rejected it, and also took
every access mode other than O_RDONLY for one that writes.

Pin microsoft/openvmm 770bc61e7b2c683b092bffb5c8cd83b8696cf54a, the head
of microsoft/openvmm#5282, one commit on 350018ce4, the head of
microsoft/openvmm#5281, which NVX pins below this commit:

- virtiofs: restore microVM handles opened with access mode 3. A
  restore keeps every access mode, and needs a writable node only for a
  handle whose access mode is O_WRONLY or O_RDWR, as FUSE_OPEN does. Its
  test fails without the fix, on a read-write share, on a read-only
  share, and outside the writable paths, and passes with it, on Windows
  and on Linux, and the virtiofs package's tests pass at the pin on
  both.

No saved-state, protocol, or ABI 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 25, 2026
… OpenVMM roadmap

Map position 390, the commit of microsoft/openvmm#5282, which NVX now
pins at 770bc61e7, 264 commits past the mapped tip, on 350018ce4,
position 389, the head of microsoft/openvmm#5281:

- 390, virtiofs: restore microVM handles opened with access mode 3. A
  restore reopens a handle that the guest opened with access mode 3,
  which neither reads nor writes, rather than reject it, and needs a
  writable node only for a handle whose access mode is O_WRONLY or
  O_RDWR, as FUSE_OPEN does, so that a snapshot of a guest that holds
  such a handle on a read-only share or outside the writable paths
  restores (#2125).

Position 390 is not yet assigned to a PR. It fixes a defect of PR18's
position 083, whose reopen_flags rejected access mode 3 and whose
restore took every access mode but O_RDONLY for a writable one, as
position 160 kept doing for its writable paths, but its code changes
position 160's line and calls position 334's opens_for_writing, and
its test needs positions 160, 164, and 352, so it is not a PR18
fixup. Of positions 372-389, only 385 and 389 change one of its files,
fs_tests.rs. Upstream main, 8d4e03132, lacks the defect, since it
lacks the microVM's saved state, and replaying the commit there
conflicts in the microVM's state.rs and fs_tests.rs, so it cannot go
upstream on its own.

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 25, 2026
On a Windows host, a virtio-fs FUSE_GETXATTR of a 262-byte name that
starts with `user.a`, which a guest can send by building the request
itself, returned the value of the file's `user.a` attribute (#2137).
lxutil stores a Linux xattr as an NTFS extended attribute named `LX.`
and the xattr's name, whose length the EA headers hold in one byte,
but its limit on xattr names was u16::MAX - 3 bytes, and it wrote that
length with `as u8`, so the 265-byte EA name became the 9-byte
`LX.user.a`. Names of 252 to 261 bytes, which Linux allows, failed
with EINVAL or ENODATA rather than with ERANGE.

Pin microsoft/openvmm c7f6a04fd7515441959b9b7a303bafd407179e85, the
head of microsoft/openvmm#5283, one commit on 770bc61e7, the head of
microsoft/openvmm#5282, which NVX pins below this commit:

- lxutil: reject xattr names longer than an NTFS EA name allows. NTFS
  accepts EA names of at most 254 bytes, so lxutil limits xattr names
  to 251 bytes, fails every longer name with ERANGE in get, set, and
  remove before it reaches NTFS, and no longer truncates an EA name's
  length. Its test fails without the fix on Windows and passes with
  it; it also passes on Linux, whose builds do not compile the changed
  code. The lxutil and virtiofs tests pass at the pin on Windows, and
  the lxutil tests on Linux.

No saved-state, protocol, or ABI 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 25, 2026
…penVMM roadmap

Map position 391, the commit of microsoft/openvmm#5283, which NVX now
pins at c7f6a04fd, 265 commits past the mapped tip, on 770bc61e7,
position 390, the head of microsoft/openvmm#5282:

- 391, lxutil: reject xattr names longer than an NTFS EA name allows.
  On Windows, lxutil limits xattr names to the 251 bytes that an NTFS
  EA name of at most 254 bytes holds after its `LX.` prefix, and fails
  every longer name with ERANGE rather than truncating the EA name's
  length to its low 8 bits, which let a FUSE_GETXATTR of a 262-byte
  name read another attribute (#2137).

Position 391 is not yet assigned to a PR. It fixes a defect of
upstream's xattr.rs of f0c2e7814 (microsoft/openvmm#2181), which no
chain commit changes, so it is no fixup. Positions 125, 158, 344, 351,
and 371 also change lxutil's lib.rs, though neither the xattr methods'
documentation nor their tests, and none of positions 372-390 changes
its files. It applies to upstream main, 8d4e03132, as it is, and on
the merged tree, `cargo check -p lxutil` and the lxutil tests pass on
Windows, so it can go upstream on its own.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@ppenna
Pedro Henrique Penna (ppenna) merged commit 770bc61 into feature/microvm/dev Nov 25, 2026
136 of 139 checks passed
Pedro Henrique Penna (ppenna) added a commit to microsoft/nvx that referenced this pull request Nov 25, 2026
…penVMM roadmap

Map position 397, the commit of microsoft/openvmm#5289, which NVX now
pins at a79b4bb40, 271 commits past the mapped tip, on 1495ac815,
position 396, the head of microsoft/openvmm#5288:

- 397, virtiofs: leave entries that lookups refuse out of microVM
  listings. The listing that the first read of a microVM directory
  handle takes leaves out the entries whose names fuse::check_name
  refuses, such as one longer than 255 bytes, and those whose
  child_path fails with EINVAL, for a name that the share refuses, or
  with E2BIG, for a path longer than MAX_PATH_BYTES, as it left out
  those that fail with EACCES, rather than fail and hide every other
  entry of the directory (#2133), and READDIRPLUS skips a listed entry
  whose path a rename of an ancestor has since made too long.

Position 397 is not yet assigned to a PR: it fixes defects of PR18's
positions 081 and 083, but its code changes the closure that position
371's loop calls, around position 160's entry_listable and position
385's check of the bounds, which position 083 lacks, and its tests
follow position 385's, so it is not a PR18 fixup, unlike positions
389, 393, and 396. Of positions 372-396, only 385, 389, 390, 393, and
396 change its files: position 385 the closure of the microVM's
file.rs that it changes, and all five other tests of fs_tests.rs.
Upstream main, 8d4e03132, lacks the defects, 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 names the head of
feature/microvm/dev, 770bc61e7, since microsoft/openvmm#5282 landed
position 390.

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

release-nvx Targets a branch under feature/microvm/.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant