Repository navigation
[DO NOT REVIEW] virtiofs: bound the buffer of an aggregate root's directory read - #5207
Merged
Pedro Henrique Penna (ppenna) merged 2 commits intoNov 22, 2026
Conversation
A guest rename of a name onto itself, in the same directory, succeeds on the host without changing anything, as POSIX requires, but it dropped the names at and below that name from every node of the volume (microsoft/nvx#1610). A node that the guest knew only through them was left with no names, so a microVM save then failed with "inode has no bounded reopenable aliases", and a volume that deduplicates nodes by path stopped finding it. A node with another hard link kept only the other name, and once the guest removed that one, the node's requests failed with ENOENT although the renamed name still reached its object. 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 one name, the first step drops the names that the second should keep. The microVM alias preflight models the same steps. A rename whose source and destination are one name now changes no names and skips the preflight. It still reaches the host after the same writability checks, so the host fails it as it fails any other rename: with ENOENT for a missing name, and with EEXIST under RENAME_NOREPLACE on Linux. renaming_a_name_onto_itself_keeps_every_name, in virtiofs' microVM exchange tests, which now cover a rename of a name onto itself too, renames a directory with nodes below it, a file in it, and a file with a second hard link each onto itself. It checks that every node keeps exactly its names, that a snapshot taken right away saves and restores them, and that the hard-linked file's node still reads the file once the guest removes the other link; and that the host still fails a missing name with ENOENT, and RENAME_NOREPLACE with EEXIST on Linux and EINVAL on Windows. Without the fix, at feature/microvm/dev b51f915, it fails on Windows and on Linux (Azure Linux 3.0, nvx-mshv-test), where the renamed directory's node has no names left; with the fix, it and the package's other tests pass there. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
FUSE_READDIR and FUSE_READDIRPLUS on the synthetic root of an aggregate reserved a reply buffer of whatever size the guest asked for, with an infallible Vec::with_capacity, so a guest that read the root with a size of u32::MAX made the device reserve 4 GiB for one request, and a host that could not provide it aborted the VMM (microsoft/nvx#1598). Upstream's aggregate support added that reservation in read_synthetic_root_dir_with, and the commit that bounds the guest's buffers, "virtiofs: bound guest payload allocations and rate-limit diagnostics", which caps the reads of every other directory at MAX_GUEST_BUFFER_SIZE, 1 MiB, and reserves their buffers fallibly, did not reach it. Fail a read of the synthetic root that asks for more than MAX_GUEST_BUFFER_SIZE bytes with E2BIG before reserving anything, and reserve the buffer with try_reserve_exact, failing with ENOMEM, as VirtioFsFile::read_dir_with and read_dir_microvm do. A read of 1 MiB, the session's limit of 256 pages per request, still lists the whole root. synthetic_root_refuses_reads_beyond_the_guest_buffer_limit, in the microVM aggregate tests, opens an aggregate's root and reads it through Fuse::read_dir and Fuse::read_dir_plus: with 1 MiB + 1 byte and with u32::MAX bytes, both fail with E2BIG, and with 1 MiB, both list the whole root. At feature/microvm/dev b51f915, on Windows and on Linux (Azure Linux 3.0, nvx-kvm-test), the test fails: the read of 1 MiB + 1 byte returns the listing rather than E2BIG. On Linux, a variant that reads u32::MAX bytes first aborts under a 1 GiB address-space limit with "memory allocation of 4294967295 bytes failed". With the fix, the test and the package's other tests pass on both, and the variant passes on Linux. 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 21, 2026 22:54
This was referenced Nov 22, 2026
Pedro Henrique Penna (ppenna)
merged commit Nov 22, 2026
ed2d7e3
into
feature/microvm/dev
101 of 105 checks passed
This was referenced Nov 22, 2026
syeedali
pushed a commit
to syeedali/nvx
that referenced
this pull request
Nov 22, 2026
Map position 341, the commit of microsoft/openvmm#5207, which NVX now pins at ed2d7e3a1, 215 commits past the mapped tip: - 341, virtiofs: bound the buffer of an aggregate root's directory read. VirtioFs::read_synthetic_root_dir_with fails a read of an aggregate's synthetic root that asks for more than MAX_GUEST_BUFFER_SIZE, 1 MiB, with E2BIG before it reserves its reply buffer, and reserves the buffer fallibly, failing with ENOMEM, as the reads of every other directory do. It reserved whatever size the guest asked for, so a read with a size of u32::MAX made the device reserve 4 GiB for one request. Position 341 is not yet assigned to a PR. It changes upstream's read_synthetic_root_dir_with, which no earlier chain commit changes, and uses the MAX_GUEST_BUFFER_SIZE with which PR06's position 010 bounds the other reads; it changes nothing that a mapped PR adds and fixes no defect of position 010, so it is not a PR06 fixup. Upstream main, bf353460f, has the defect, but replaying the commit there conflicts in the microVM's aggregate_fs_tests.rs, which upstream main lacks, and its change to aggregate.rs needs position 010's MAX_GUEST_BUFFER_SIZE, so it cannot go upstream on its own as it is; it could go upstream with position 010, in microsoft/openvmm#4597. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
syeedali
pushed a commit
to syeedali/nvx
that referenced
this pull request
Nov 22, 2026
OpenVMM's virtio-fs server lists a microVM directory once, on the first read of each handle, and keeps the listing for the handle's later reads and for its saved state. A saved state holds at most 16,384 entries and 4 MiB of names in the listings of all handles, but the server checked only each listing's own bounds of 4,096 entries and 64 KiB of names, across up to 4,096 handles (microsoft#1613). A guest that kept five handles listing a directory of 4,094 files therefore failed every capture of the VM with "saved directory entries exceed the aggregate bound" until it released them, and its handles could pin 256 MiB of names in the VMM. Pin microsoft/openvmm 5c82edac42ca480d546459e019860759a27c2211, one commit on ed2d7e3a1, the head of microsoft/openvmm#5207, which stacks on microsoft/openvmm#5206 and feature/microvm/dev b51f9156c: - virtiofs: bound microVM directory snapshots in total when listing. The first read of a handle charges its listing to the totals of the attachment's listings, and fails with ENOSPC, keeping no listing, when the listings would then exceed them. A released handle returns its share, and a restore charges the listings that it restores in place of those of the handles that it replaces. Its tests fail without the change on Windows and on Linux (nvx-mshv-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>
syeedali
pushed a commit
to syeedali/nvx
that referenced
this pull request
Nov 22, 2026
OpenVMM's microVM virtio-fs server opens the host directory of an aggregate's file child as a strict volume whose root object is the file, at its name, and a strict volume refuses every path with `\` or `:`. Nothing checked the file's name when the child attached, so a file child whose host file's name had one, as in a timestamp or a digest on Linux, or a Windows path that names an alternate data stream, attached without an error, but every guest lookup of it failed with EINVAL, and so did a READDIRPLUS of the aggregate's root from the child on (microsoft#1614). Pin microsoft/openvmm afa0e9c20a7943d3ec556098d9272f4ee502bdd4, one commit on 5c82edac4, the head of microsoft/openvmm#5208, which stacks on microsoft/openvmm#5207 and feature/microvm/dev 32888344a: - virtiofs: refuse a microVM file child that its volume cannot name. Attaching an aggregate fails, at a cold boot or a restore, with an error that names the file, when a file child's name holds `\` or `:`, which the volume would refuse as a path. Directory shares and children, and a file in a directory whose name has a colon, are unchanged. 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>
5 tasks done
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#1598.
It was stacked on #5206, which has landed:
feature/microvm/devis at its head,32888344a, which this PR's only commit,ed2d7e3a1, follows. NVX pins the head of this branch in microsoft/nvx#1930, so this is a prerequisite of that NVX change, and it lands by fast-forwardingfeature/microvm/devto that exact commit, not with the merge button, which squashes.What and why
FUSE_READDIRandFUSE_READDIRPLUSon the synthetic root of an aggregate virtio-fs device reachVirtioFs::read_synthetic_root_dir_with, which reserved its reply buffer with an infallibleVec::with_capacity(size as usize)on the guest'sfuse_read_in.size. A guest that openedFUSE_ROOT_IDand read it with a size ofu32::MAXmade the device reserve 4 GiB for one request, and a host that could not provide it aborted the VMM withmemory allocation of 4294967295 bytes failed.Upstream's aggregate support (#3821) added that reservation. The chain commit that bounds the guest's buffers, "virtiofs: bound guest payload allocations and rate-limit diagnostics", caps
guest_bufferand the reads of every other directory (VirtioFsFile::read_dir_withandread_dir_microvm) atMAX_GUEST_BUFFER_SIZE, 1 MiB, and reserves their buffers fallibly, but did not reach the synthetic root.The fix: a read of the synthetic root that asks for more than
MAX_GUEST_BUFFER_SIZEbytes fails withE2BIGbefore anything is reserved, and the buffer is reserved withtry_reserve_exact, failing withENOMEM, as for every other directory.DirEntryWriterfills the vector's spare capacity, whichtry_reserve_exactsets aswith_capacitydid, so a reply within the bound is unchanged. A read of exactly 1 MiB, the session's limit of 256 pages per request, which a Linux guest can ask for since Linux clamps a readdir buffer tomax_pagespages, still lists the whole root. No saved state, protocol, ABI, or format, and no version of any of them, changes.Kept from the issue's suggested fix: the bound and the fallible reservation. Changed: the check comes first, as in the other directory reads, and the test reads the root through
Fuse::read_dirandFuse::read_dir_plusamong the package's microVM aggregate tests, rather than in a child process underulimit -v, so it also runs on Windows and fails at the base without reserving 4 GiB.Out of scope, handled separately: an empty reply rather than
EINVALwhen the buffer fits no entry (microsoft/nvx#1617),FSYNCDIRon the synthetic root (microsoft/nvx#1624), the handle map'su64::MAXandSYNTHETIC_ROOT_FH(microsoft/nvx#1627), and the root'sst_nlink(microsoft/nvx#1632).Tests
One unit test in
virtiofs,microvm::aggregate_fs_tests::synthetic_root_refuses_reads_beyond_the_guest_buffer_limit: on a microVM aggregate with two children, it opens the root withFuse::open_dirand reads it throughFuse::read_dirandFuse::read_dir_plus:u32::MAXbytes, both fail withE2BIG, the smaller size first, so that at the base the test fails before it would reserve 4 GiB;.,.., and both children.Validation
cargo nextest run --profile agent -p virtiofs, at the base with the new test applied (the fix reverted), and with the fix:b51f9156c)b51f9156c1048577 bytes, plus: false,left: Ok(128),right: Err(E2BIG)nvx-kvm-test, Azure Linux 3.0 VMAt the base, on Linux, a scratch variant of the test that reads
u32::MAXbytes first aborted underulimit -v 1048576withmemory allocation of 4294967295 bytes failed(exit 134), as the issue reports; with the fix, it passes.At 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, and one ignored test is skipped, as at the base.cargo xtask fmt --fixchanges nothing. NVX's virtio-fs microVM scenarios, among them the two that list an aggregate's root from the guest,filesystem-sharesandplatform-aggregate-export, pass on KVM onnvx-kvm-testwith OpenVMM built from this head.