Repository navigation
[DO NOT REVIEW] lxutil: fail an empty symlink target with ENOENT on Windows - #5284
Merged
Pedro Henrique Penna (ppenna) merged 4 commits intoNov 25, 2026
Conversation
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>
On Windows, lxutil stores a Linux xattr as an NTFS extended attribute named `LX.` and the xattr's name. FILE_GET_EA_INFORMATION and FILE_FULL_EA_INFORMATION give that EA name's length in one byte, but lxutil's limit on xattr names, LX_UTIL_XATTR_NAME_MAX, was u16::MAX - 3 bytes, and lxutil wrote the length with `as u8`, which kept only its low 8 bits (microsoft/nvx#2137). A FUSE_GETXATTR of a 262-byte name that starts with `user.a`, which a guest can send by building the request itself, thus queried the 9-byte EA name `LX.user.a`, 265 bytes modulo 256, and returned the value of the `user.a` attribute. Names of 252 to 261 bytes failed with EINVAL or ENODATA, depending on the operation and the length, rather than with ERANGE, and XATTR_CREATE of the 262-byte name failed with EEXIST. NTFS accepts EA names of at most 254 bytes, so lxutil can store xattr names of at most 251 bytes. LX_UTIL_XATTR_NAME_MAX is now that length. set_name, like get and set, accepts a name of exactly that length rather than rejecting it with `>=`, and returns the EA name's length as the u8 that the headers hold. get, set, and remove thus fail every longer name with ERANGE before it reaches NTFS, as Linux fails names longer than its 255 bytes. The documentation of LxVolume's xattr methods now gives the limit. xattr_name_length sets `user.a`; sets, reads, and removes an attribute whose name has the longest length that the platform allows, 251 bytes on Windows and 255 on Linux; expects every longer name, up to 262 bytes, to fail with ERANGE in get, get of the size, set with no flag, with XATTR_CREATE, and with XATTR_REPLACE, and remove; and expects `user.a` to keep its value. At feature/microvm/dev 1633b37, it fails on Windows 11 Enterprise (build 26300, NTFS) at the first longer name, whose get failed with EINVAL. A one-off test there, not committed, showed the rest: every operation on a 252- or 253-byte name failed with EINVAL; on 254- to 261-byte names, get, XATTR_REPLACE, and remove failed with ENODATA, and set and XATTR_CREATE with EINVAL; and the 262-byte name read `secret`, the value of `user.a`, failed XATTR_CREATE with EEXIST, and failed set, XATTR_REPLACE, and remove with EINVAL. With the fix, the lxutil tests pass on Windows 11 and on Azure Linux 3 (kernel 6.18, ext4). Linux builds do not compile xattr.rs, so the fix leaves Linux's behavior as it was. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
On Windows, LxVolume::symlink and symlink_stat accepted an empty target (microsoft/nvx#2126), which Linux's symlink(2) fails with ENOENT. On a volume that does not confine paths, the empty target names the link's own directory, so symlink_helper chose an NT directory link and called create_nt_link_reparse_buffer. That sized its buffer as the REPARSE_DATA_BUFFER up to the PathBuffer of its symbolic link part, 20 bytes, plus the target twice, but wrote the whole 24-byte struct at its start: with an empty target, 4 bytes past the end of the heap allocation. Where the process may not create NT links, setting that reparse point then failed, and the volume fell back to a WSL-style link to the empty target, as a volume that confines paths makes directly. A virtio-fs guest could thus overflow the host's heap and get a symbolic link to nothing on a direct share, and a virtio-9p guest the same, since both devices pass the guest's target to the volume unchanged. A microVM share already refused an empty target itself. symlink_helper now fails an empty target with ENOENT before it checks the link's path or creates anything, as symlink(2) does, and create_nt_link_reparse_buffer, whose write of the struct relies on a target that is not empty, refuses an empty one with ENOENT too, so that the write stays within the buffer whatever its caller passes. symlink_rejects_an_empty_target checks that symlink and symlink_stat fail with ENOENT and leave no link, with and without confine_paths; nt_link_reparse_buffer_refuses_an_empty_target checks the guard of create_nt_link_reparse_buffer; and virtiofs's direct_symlink_rejects_an_empty_target checks that a guest SYMLINK with an empty target on a direct share fails with ENOENT and leaves no link on the host. At feature/microvm/dev 1633b37, on Windows 11 (NTFS, a process that may not create NT links), all three fail: the first and the last create a symbolic link to the empty target, and the second gets a 20-byte buffer. An AddressSanitizer build of the first, with windows_hook_rtl_allocators, reports a heap-buffer-overflow there: a 24-byte write 0 bytes after a 20-byte region, in create_nt_link_reparse_buffer. With the fix, the three pass, and so do lxutil's other tests, also under AddressSanitizer. On Linux, whose kernel refuses an empty target, and where none of the changed code builds, the first and the last pass with and without the fix. 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 25, 2026 16:55
|
This PR modifies files containing For more on why we check whole files, instead of just diffs, check out the Rustonomicon |
This was referenced Nov 25, 2026
Pedro Henrique Penna (ppenna)
added a commit
to microsoft/nvx
that referenced
this pull request
Nov 25, 2026
A guest that builds its own requests could send a symbolic link request with an empty target, which a Linux guest kernel never sends, to a direct virtio-fs share or a virtio-9p share of a Windows host (#2126). lxutil's Windows symlink_helper accepted it. On a volume that does not confine paths, create_nt_link_reparse_buffer wrote its whole 24-byte REPARSE_DATA_BUFFER into a 20-byte heap buffer, 4 bytes past its end, and where the process may not create NT links, the volume then made a WSL-style link to the empty target, which Linux's symlink(2) refuses with ENOENT. The microVM shares that NVX configures already refused an empty target in virtiofs before the host. Pin microsoft/openvmm e61fa53264090bd63f3cc2baeb80145c63488819, the head of microsoft/openvmm#5284, one commit on c7f6a04fd, the head of microsoft/openvmm#5283, which NVX pins below this commit: - lxutil: fail an empty symlink target with ENOENT on Windows. symlink_helper fails an empty target with ENOENT before it checks the link's path or creates anything, as symlink(2) does, and create_nt_link_reparse_buffer refuses one too, so that its write stays within its buffer. Its three tests fail without the fix on Windows and pass with it; an AddressSanitizer build reports the overflow without the fix and nothing with it. The lxutil, virtiofs, and plan9 tests pass at the pin on Windows and Linux. The microVM shares behave as before. 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
Map position 392, the commit of microsoft/openvmm#5284, which NVX now pins at e61fa5326, 266 commits past the mapped tip, on c7f6a04fd, position 391, the head of microsoft/openvmm#5283: - 392, lxutil: fail an empty symlink target with ENOENT on Windows. lxutil's Windows symlink_helper fails an empty target with ENOENT before it checks the link's path or creates anything, as Linux's symlink(2) does, and create_nt_link_reparse_buffer refuses one too, so that its write of the whole 24-byte REPARSE_DATA_BUFFER no longer runs 4 bytes past the end of the 20-byte buffer that it allocates for an empty target (#2126). Position 392 is not yet assigned to a PR. It fixes a defect that upstream has rather than one of a chain commit: PR27's position 125, whose confine_paths it also tests, left the empty target to the WSL-style link as upstream did, so it is no fixup. Of positions 372-391, only 389, PR18's fixup, and 391 change its files: a line of virtiofs's lib.rs far from its test, so folding position 389 leaves it as it is, and the xattr methods' documentation and tests in lxutil's lib.rs. Upstream main, 8d4e03132, has the defect, and replaying the commit there merges its lxutil changes but conflicts in virtiofs's lib.rs, around position 361's test helper, and its lxutil test needs position 125's confine_paths, so it cannot go upstream on its own as it is. 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
A microVM guest that holds a file on a virtio-fs share open with O_DIRECT could save the VM's state, but not restore it: the restore refused the saved handle with "saved handle has unsupported open flags 0x4002" for O_RDWR | O_DIRECT, from FUSE_OPEN, and with 0x4041 for O_WRONLY | O_CREAT | O_DIRECT, from FUSE_CREATE (#2128). OpenVMM's reopen_flags, which checks a saved handle's flags and gives those with which a restore reopens it, refused every flag outside a list that lacked O_DIRECT, although FUSE_OPEN and FUSE_CREATE accept it, keep it in the handle's flags, and open the host file with it. Pin microsoft/openvmm 5af753b17035f548039cab531027a3cc635ac4fa, the head of microsoft/openvmm#5285, one commit on e61fa5326, the head of microsoft/openvmm#5284, which NVX pins below this commit: - virtiofs: reopen a microVM handle with O_DIRECT on restore. reopen_flags keeps O_DIRECT, so a restore reopens the handle as the guest opened it, with the host's O_DIRECT semantics. Its test fails without the fix on Windows and Linux and passes with it, and the virtiofs tests pass at the pin on both. On KVM, a filesystem-snapshot run whose guest held files open with O_DIRECT across the capture failed its restore before the fix and restored after it. No saved-state, protocol, or ABI format, and no version of any of them, changes; a snapshot that an earlier release saved with such a handle now restores. 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
…VMM roadmap Map position 393, the commit of microsoft/openvmm#5285, which NVX now pins at 5af753b17, 267 commits past the mapped tip, on e61fa5326, position 392, the head of microsoft/openvmm#5284, as a PR18 fixup: - 393, virtiofs: reopen a microVM handle with O_DIRECT on restore. reopen_flags keeps O_DIRECT, which FUSE_OPEN and FUSE_CREATE accept, record, and open the host file with, so that a restore reopens a handle that the guest opened with O_DIRECT as the guest opened it, rather than refuse the saved state with "saved handle has unsupported open flags" (#2128). Position 393 fixes a defect of PR18's position 083, whose list in reopen_flags lacked O_DIRECT, and needs nothing that a later position adds but, for its test, position 164's helpers, position 334's create_with_flags, and position 335's get_file, so, as position 389 does for position 081, it is a PR18 fixup: fold it into position 083, where its line applies as it is, and its test into position 335. The Scope, the DAG, the fold sentences after it, the table, PR18's node, its row in the PR summary, and its commit mapping count it. Of positions 372-392, only 385, 389, and 390 change its files: they add other tests to fs_tests.rs, and position 390 also removes position 083's check of the access mode from reopen_flags, after the list. Upstream main, 8d4e03132, lacks the microVM's saved state, and replaying the commit there conflicts in the microVM's state.rs, fs_tests.rs, and policy_tests.rs, so it cannot go upstream on its own. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Pedro Henrique Penna (ppenna)
merged commit Nov 25, 2026
e61fa53
into
feature/microvm/dev
134 of 139 checks passed
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#2126.
Stacked on #5283 (
c7f6a04fd, branchcopilot/nvx-issue-2137-virtiofs-xattr-name-length), itself stacked on #5282 (770bc61e7), whose commits this pull request includes, on350018ce4, the head offeature/microvm/devsince #5281 landed it; only its top commit,e61fa5326, belongs to it. NVX pins the head of this branch,e61fa53264090bd63f3cc2baeb80145c63488819, in the NVX pull request of microsoft/nvx#2126 (branchagents/issue-2126-virtiofs-empty-symlink), so this pull request is a prerequisite of that NVX change. It lands after #5282 and #5283 by fast-forwardingfeature/microvm/devto that exact commit, not with the merge button, which squashes.What and why
On Windows,
LxVolume::symlinkandsymlink_stataccepted an empty target, which Linux'ssymlink(2)fails withENOENT. On a volume that does not confine paths, the empty target names the link's own directory, sosymlink_helper(vm/devices/support/fs/lxutil/src/windows/mod.rs) chose an NT directory link and calledcreate_nt_link_reparse_buffer(windows/util.rs). That sized its buffer as theREPARSE_DATA_BUFFERup to thePathBufferof its symbolic link part, 20 bytes, plus the target twice, but wrote the whole 24-byte struct at its start: with an empty target, 4 bytes past the end of the heap allocation. Where the process may not create NT links, setting that reparse point then failed, and the volume fell back to a WSL-style link to the empty target, which a volume that confines paths makes directly. A guest that builds the request itself, since a Linux guest kernel refuses an empty target before it reaches the device, could thus overflow the host's heap and get a symbolic link to nothing, with aFUSE_SYMLINKon a direct virtio-fs share (VirtioFs::new) or aTsymlinkon a virtio-9p share, since both devices pass the guest's target to the volume unchanged. A microVM share already refuses an empty target invirtiofsitself.symlink_helpernow fails an empty target withENOENTbefore it checks the link's path or creates anything, assymlink(2)does before it looks up the link's path.create_nt_link_reparse_buffer, whose write of the struct needs a target that is not empty, refuses an empty one withENOENTtoo, so that the write stays within the buffer whatever its caller passes; itsSAFETYcomment now says why the buffer is large enough.The issue suggests the second change alone. It stops the overflow, but a volume that confines paths, and the fallback after a failed NT link, would still create a WSL-style link to the empty target, so the check also goes in
symlink_helper, which serves bothvirtiofsandplan9.Linux builds do not compile the changed code, and the Linux kernel already fails an empty target with
ENOENT. No saved state, protocol, ABI, or format, and no version of any of them, changes.Tests
symlink_rejects_an_empty_target(lxutil/src/lib.rs, next to thesymlinktest) expectssymlinkandsymlink_statof an empty target to fail withENOENTand leave no link, with and withoutconfine_paths.nt_link_reparse_buffer_refuses_an_empty_target(lxutil/src/windows/mod.rs) expectscreate_nt_link_reparse_bufferto refuse an empty target withENOENT.direct_symlink_rejects_an_empty_target(virtiofs/src/lib.rs) expects a guestFUSE_SYMLINKwith an empty target on a direct share to fail withENOENTand leave no link on the host.microvm::symlink_tests::symlink_target_bounds_match_linuxalready covers microVM shares.Validation
On Windows 11 Enterprise (build 26300, NTFS, in a process that may not create NT links) and on a Linux KVM test VM (Azure Linux 3, kernel 6.18, x86_64):
1633b3797, the three tests fail on Windows: the first and the last create a symbolic link to the empty target, a WSL-style link of mode0o120777and size 0 whoseread_linkis empty, after the NT link failed, and the second gets a 20-byte buffer. An AddressSanitizer build oflxutil's tests (-Zsanitizer=address, withASAN_OPTIONS=windows_hook_rtl_allocators=true, since Rust's allocator callsHeapAllocon Windows) reports a heap-buffer-overflow in the first: a 24-byte write 0 bytes after a 20-byte region, increate_nt_link_reparse_buffer, called fromsymlink_helper. With the fix, the three pass, andlxutil's 74 tests pass under AddressSanitizer with no report.1633b3797:cargo check,cargo clippy --all-targets, andcargo doc --no-depsoflxutilandvirtiofshave no warnings on Windows and Linux;cargo nextest run --profile agent -p lxutil -p virtiofs -p plan9passes 331 tests on Windows (5 skipped) and 312 on Linux (4 skipped), where the newlxutilandvirtiofstests pass with and without the fix.cargo xtask fmt --fixchanges nothing.git range-diffreports. [DO NOT REVIEW] lxutil: reject xattr names longer than an NTFS EA name allows #5283 also changeslxutil, so the checks ran again on this head:cargo clippy --all-targets -p lxutil -p virtiofshas no warnings on Windows and Linux, wherecargo checkandcargo doc --no-depsof both have none either, andcargo nextest run --profile agent -p lxutil -p virtiofs -p plan9passes 334 tests on Windows (5 skipped) and 315 on Linux (4 skipped).CI run 45659213705 passed
unit tests [x64-linux],unit tests [x64-windows], andrun vmm-testsonx64-linux-amd-kvm,x64-windows-intel, andx64-windows-amdon its first attempt, andrun vmm-tests [x64-linux-intel-mshv]on its second. The first lost that job tox86_64::openvmm_linux_x64_virtio_blk_device, whose OpenVMM panicked with a VP activityrestore state mismatchinvmm_core/virt/src/x86/vp.rs, on a Linux host, which builds none of this change's code; the job passed at #5281 and #5283, and one rerun of the failed jobs passed it.run vmm-tests [x64-windows-amd-snp]fails at #5281 and #5283 too, andrun vmm-tests [aarch64-windows]lost two Hyper-V OpenHCL tests on the first attempt,hyperv_openhcl_uefi_aarch64_ubuntu_2404_server_aarch64_servicing_downgradeandhyperv_openhcl_uefi_aarch64_ubuntu_2404_server_aarch64_boot_heavy, which do not use lxutil, and passed on the second.