Repository navigation
[DO NOT REVIEW] lxutil: reject xattr names longer than an NTFS EA name allows - #5283
Merged
Pedro Henrique Penna (ppenna) merged 3 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>
Pedro Henrique Penna (ppenna)
requested review from
a team and
Anatol Belski (weltling)
as code owners
November 25, 2026 16:48
|
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
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>
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>
This was referenced Nov 25, 2026
Pedro Henrique Penna (ppenna)
merged commit Nov 25, 2026
c7f6a04
into
feature/microvm/dev
104 of 105 checks passed
5 tasks done
syeedali
pushed a commit
to syeedali/nvx
that referenced
this pull request
Nov 27, 2026
…enVMM roadmap Map position 399, the commit of microsoft/openvmm#5293, which NVX now pins at ee66d2311, 273 commits past the mapped tip, on 5f4a47b83, position 398, the head of feature/microvm/dev since microsoft/openvmm#5283-#5290 landed positions 391-398: - 399, lxutil: close the descriptor when fdopendir fails in DirectoryEnumerator::new. The constructor keeps its OwnedFd until fdopendir succeeds, so a listing of a descriptor that is not a directory, which upstream's virtio-fs FUSE_READDIR and Plan9 Treaddir reach, no longer leaks it (microsoft#2124). Position 399 is not assigned to a PR, and no chain commit changes the file that it changes. It is a cherry-pick of microsoft/openvmm#5291's 7417a033b, which proposes it on upstream main 8d4e03132, where lxutil type-checks and its tests pass on azure-intel-kvm-7, so it can go upstream on its own. The Scope now records that positions 391-398 landed on feature/microvm/dev. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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#2137.
Stacked on #5282 (
770bc61e7, branchcopilot/nvx-issue-2125-virtiofs-access-mode-3), itself stacked on #5281 (350018ce4), whose commits this pull request includes; only its top commit,c7f6a04fd, belongs to it. NVX pins the head of this branch,c7f6a04fd7515441959b9b7a303bafd407179e85, in the NVX pull request of microsoft/nvx#2137 (branchagents/issue-2137-virtiofs-xattr-name-length), so this pull request is a prerequisite of that NVX change. It lands after #5281 and #5282 by fast-forwardingfeature/microvm/devto that exact commit, not with the merge button, which squashes.What and why
On Windows, lxutil stores a Linux xattr as an NTFS extended attribute (EA) named
LX.and the xattr's name.FILE_GET_EA_INFORMATIONandFILE_FULL_EA_INFORMATIONgive that EA name's length in one byte (EaNameLength), butLX_UTIL_XATTR_NAME_MAXwasu16::MAX - 3andvm/devices/support/fs/lxutil/src/windows/xattr.rswrote the length withas u8, which kept only its low 8 bits. AFUSE_GETXATTRof a 262-byte name that starts withuser.a, which a guest can send by building the request itself, thus queried the 9-byte EA nameLX.user.a(265 modulo 256) and returned the value of theuser.aattribute. Names of 252 to 261 bytes failed withEINVALorENODATA, depending on the operation and the length, rather than withERANGE, andXATTR_CREATEof the 262-byte name failed withEEXIST.NTFS accepts EA names of at most 254 bytes: on NTFS, a 251-byte xattr name, an EA name of 254 bytes, works, and a 252-byte one fails with
EINVALfrom NTFS. So lxutil can store xattr names of at most 251 bytes:LX_UTIL_XATTR_NAME_MAXis now 251, derived from a newLX_UTILP_EA_NAME_MAXof 254 and the 3-byte prefix.set_name, likegetandset, accepts a name of exactly that length rather than rejecting it with>=, and returns the EA name's length as theu8that the headers hold, through a checked conversion, so no caller truncates it withas u8any more.get,set, andremove(throughcheck_exists) thus fail every longer name withERANGEbefore it reaches NTFS, as Linux fails names longer than its 255 bytes.LxVolume's xattr methods now gives the limit, where it said only that the limit was "slightly shorter" than Linux's.The issue suggests
u8::MAX - 3, 252, as the limit. It behaves the same, but only becauseset_namerejects a 252-byte name with>=aftergetandsetlet it through; this change states the real limit and checks it the same way everywhere.Linux builds do not compile
xattr.rs, so Linux's behavior does not change. No saved state, protocol, ABI, or format, and no version of any of them, changes.Tests
xattr_name_length(lxutil/src/lib.rs, next to thexattrtest) setsuser.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 withERANGEin a get, a get of the size, a set with no flag, withXATTR_CREATE, and withXATTR_REPLACE, and a remove; and expectsuser.ato keep its value.Validation
On Windows 11 Enterprise (build 26300, NTFS) and on a Linux KVM test VM (Azure Linux 3, kernel 6.18, x86_64, ext4):
1633b3797, the new test fails on Windows at the first longer name, whose get failed withEINVAL. One-off tests, not committed, showed the rest there: throughLxVolume, every operation on a 252- or 253-byte name failed withEINVAL; on 254- to 261-byte names, get,XATTR_REPLACE, and remove failed withENODATA, and set andXATTR_CREATEwithEINVAL; and the 262-byte name readsecret, the value ofuser.a, failedXATTR_CREATEwithEEXIST, and failed the others withEINVAL. ThroughVirtioFs,FUSE_GETXATTRof the 262-byte name returnedsecret. With the fix, the test passes, and the one-off test throughVirtioFsfailsFUSE_GETXATTR, its size query,FUSE_SETXATTR, andFUSE_REMOVEXATTRof every name of 252 to 262 bytes withERANGE, leavinguser.aas it was.1633b3797:cargo check,cargo clippy --all-targets, andcargo doc --no-deps(with-D warningson Linux, and forcargo docon Windows too) oflxutilhave no warnings;cargo nextest run --profile agent -p lxutilpasses 73 tests on Windows (2 skipped) and 53 on Linux (3 skipped);cargo nextest run --profile agent -p virtiofspasses 240 tests on Windows (3 skipped).cargo xtask fmt --fixonly rewrapped one line of the test.virtiofs. Atc7f6a04fd,cargo clippy --all-targets -p lxutilhas no warnings on Windows and Linux, nor docargo checkandcargo doc --no-depsoflxutilon Linux, with-D warnings;cargo nextest run --profile agent -p lxutil -p virtiofspasses 315 tests on Windows (5 skipped), andcargo nextest run --profile agent -p lxutil53 on Linux (3 skipped).