Skip to content

[DO NOT REVIEW] fuse: reply EIO when a write or copy count overflows u32 - #5198

Merged
Pedro Henrique Penna (ppenna) merged 1 commit into
feature/microvm/devfrom
copilot/nvx-issue-1631-write-count-u32
Nov 21, 2026
Merged

Pedro Henrique Penna (ppenna) merged 1 commit into
feature/microvm/devfrom
copilot/nvx-issue-1631-write-count-u32

Conversation

@ppenna

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

Copy link
Copy Markdown
Contributor

Refs microsoft/nvx#1631.

NVX pins the head of this branch, so this is a prerequisite of the NVX change that pins it, and it lands by fast-forwarding feature/microvm/dev to that exact commit, not with the merge button, which squashes.

What and why

fuse::Session::dispatch in vm/devices/support/fs/fuse/src/session.rs replies to FUSE_WRITE and FUSE_COPY_FILE_RANGE with a fuse_write_out, whose size is a u32, and it converted the usize that Fuse::write and Fuse::copy_file_range return into that field with try_into().unwrap(). A file system that reported more than u32::MAX bytes therefore panicked the dispatcher and, with panic = 'abort' in the dev and release profiles, aborted the VMM instead of failing the one request.

The count comes from the file system, but a guest can drive it past u32::MAX: fuse_copy_file_range_in.len is 64-bit, and Linux passed the caller's length on unclamped from 4.20 until 6.17 (torvalds/linux@1e08938c3694, "fuse: prevent overflow in copy_file_range return value"), so a file system that copies all that the guest asks for counts more than the reply can hold. The file systems of virtiofs cannot trigger it: VirtioFs refuses a write of more than 1 MiB and implements no copy_file_range, and SectionFs and the dormant microVM file system implement neither request. Any other implementation of Fuse can.

Both replies are now built by Session::write_out, which, when the count does not fit, fails the request with EIO, which Session::dispatch sends as the request's error reply, and logs it with tracelimit::error_ratelimited! (unique, opcode, count), since a guest can repeat the request. EIO is what the Linux FUSE driver gives a write whose reply counts more bytes than the write carried (fuse_send_write()), and, in current kernels, a copy whose reply counts more than it asked for. Fuse::write and Fuse::copy_file_range now document the bound, and that a copy should copy at most u32::MAX bytes, a short copy, which copy_file_range allows, even when arg.len is larger. A count within the bound is replied as before.

The issue's patch makes the same change, with a helper that returns the u32. Its test reads replies through CapturingSender, which keeps only the last one, and checks only the overflow, so it would also pass if the session refused every count or sent two replies. The tests here use the session's test harness, which requires exactly one reply to each request, and also check that counts up to u32::MAX, the bound itself included, are replied unchanged. Rejected: saturating the count at u32::MAX, which would tell the guest that fewer bytes were written than were, and clamping arg.len before calling the file system, which changes what the file system is asked to do and is not needed to stop the abort.

The defect is upstream's: upstream main bf353460f has the same try_into().unwrap() in both replies. This commit does not apply to upstream main as it is only because its tests use the session's test harness, which exists only on this branch.

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

Tests

In session::tests::write_out, each request goes through the session's test harness, which requires exactly one reply, whose header counts its whole length:

  • write_count_beyond_u32_fails_with_eio: a file system that reports u32::MAX + 1 bytes for a 5-byte write gets an -EIO reply with no data.
  • copy_count_beyond_u32_fails_with_eio: a file system that copies all of a u32::MAX + 1-byte copy gets an -EIO reply with no data, and the same session then answers a 4096-byte copy with its count.
  • write_replies_with_the_count_written: a write that the file system reports whole is replied with its count.
  • copy_replies_with_counts_up_to_u32_max: copies of 4096 and u32::MAX bytes are replied with those counts, so the check does not refuse the bound itself.

Validation

With cargo nextest run --profile agent -p fuse, with the fix reverted (session.rs and lib.rs of 3eb7500fd, with the new test module declared) and with it:

Host Without the fix With it
Windows 11, local write_count_beyond_u32_fails_with_eio and copy_count_beyond_u32_fails_with_eio panic with called Result::unwrap() on an Err value: TryFromIntError(PosOverflow), at session.rs:213:46 and session.rs:396:46; the other two pass all 46 pass
nvx-mshv-test, an Azure Linux 3.0 virtual machine the same two tests panic the same way, at the same lines 46 pass, 1 skipped (fuse_hello, which needs root)

On both hosts, at this head, cargo check, cargo clippy --all-targets, and cargo doc --no-deps for fuse are clean, but for the LNK4199 linker message that every linked artifact gets on the Windows machine; on Windows, cargo xtask fmt --fix changes nothing. Before the rebase onto 3eb7500fd, the same fix behaved the same on 85c3698f9, on Windows and on nvx-mshv-test.

NVX's eight virtio-fs microVM scenarios, among them platform-filesystem, filesystem-snapshot, and platform-aggregate-export, pass on nvx-mshv-test, on MSHV, with the Alpine guest and OpenVMM built from this head, in microsoft/nvx#1864, which pins it. Their guest writes reach VirtioFs through FUSE_WRITE, whose replies write_out now builds. In this pull request's CI, run 44863866339, every job that NVX requires passed, and so did every unit-test job, on x64 and aarch64, Linux, musl, and Windows; run vmm-tests [x64-windows-amd-snp] failed in three Hyper-V SEV-SNP OpenHCL tests, snp_vmgstool_copy_igvmfile, snp_ak_refresh, and snp_ak_cert_cache, none of them a virtio-fs test.

A FUSE_WRITE or FUSE_COPY_FILE_RANGE whose file system reported more
than u32::MAX bytes aborted the VMM process. Session::dispatch converted
the usize that Fuse::write and Fuse::copy_file_range return into the
u32 size of their fuse_write_out reply with try_into().unwrap(), so
such a count panicked, and OpenVMM builds with panic = 'abort'.

The count comes from the file system, but a guest can drive it past
u32::MAX: fuse_copy_file_range_in carries a 64-bit length, which Linux
passed on unclamped from 4.20 until 6.17 (1e08938c3694, "fuse: prevent
overflow in copy_file_range return value"), so a file system that
copies all that the guest asks for counts more than the reply holds.
VirtioFs is not affected today: it caps a write at 1 MiB and does not
implement copy_file_range.

Build both replies with Session::write_out, which fails the request
with EIO and a rate-limited error when the count does not fit, as
Linux's FUSE driver fails a write whose reply counts more bytes than
the write carried. The documentation of Fuse::write and
Fuse::copy_file_range states the bound, and that a copy should copy at
most u32::MAX bytes, a short copy, even when arg.len is larger.

The new tests in session::tests::write_out send each request through
the session's test harness to a file system that reports a given
count, and expect exactly one reply. A count beyond u32::MAX now fails
the request with EIO, and the session answers the next copy; counts up
to u32::MAX are replied unchanged. At feature/microvm/dev 3eb7500,
the two overflow tests panic at session.rs:213 for a write and at
session.rs:396 for a copy, and with this change, all 46 tests of fuse
pass.

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 21, 2026
@ppenna
Pedro Henrique Penna (ppenna) merged commit 51e9af7 into feature/microvm/dev Nov 21, 2026
104 of 105 checks passed
syeedali pushed a commit to syeedali/nvx that referenced this pull request Nov 22, 2026
Map position 330, the commit of microsoft/openvmm#5198, which NVX now
pins at 51e9af75d, 204 commits past the mapped tip:

- 330, fuse: reply EIO when a write or copy count overflows u32.
  Session::write_out builds the replies to FUSE_WRITE and
  FUSE_COPY_FILE_RANGE, and fails with EIO a byte count from the file
  system that the u32 size of their fuse_write_out cannot hold, which
  it logs with a rate-limited error. The session converted the count
  with try_into().unwrap(), so a larger count panicked, which aborts
  the VMM.

It is not a fixup of a mapped PR. Position 330 changes the two
replies in session.rs, which upstream main has and no earlier chain
commit changes, adds write_out after send_max_size, which position 329
changes, documents the bound on two Fuse methods in lib.rs, which
positions 047, 324, 326, and 329 also change, and adds its tests,
which use the harness, in a new file that it declares in the session's
test module. Upstream main, bf353460f, has the defect, in the same two
replies, but the commit does not apply there as it is: upstream main
lacks the harness and the session tests of positions 047, 324, 326,
327, and 329, whose declarations conflict.

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