Skip to content

nvx: share the descriptor and ACL reads of the Windows private-file checks - #1761

Open
Pedro Henrique Penna (ppenna) wants to merge 1 commit into
devfrom
agents/issue-1760-windows-security-descriptor
Open

Pedro Henrique Penna (ppenna) wants to merge 1 commit into
devfrom
agents/issue-1760-windows-security-descriptor

Conversation

@ppenna

Copy link
Copy Markdown
Contributor

Fixes #1760

What does this pull request change?

nvx/src/host/platform/windows/private.rs repeated two unsafe Win32 sequences. This pull request names each once and calls it from both places:

  • SecurityDescriptor::of(handle) runs the two-call GetKernelObjectSecurity sequence (the length query, then the read into a buffer aligned for a descriptor) and owns the buffer. as_ptr() lends the descriptor, whose owner and list point into that buffer. check_vm_dir and privacy_problem used to carry a copy each.
  • ace_count(acl) runs the GetAclInformation query for an entry count, beside ace_at. vm_dir_problem and privacy_problem used to carry a copy each.

The policies that the two checks apply to the entries stay where they are. vm_dir_problem keeps its signature, so its tests still build descriptors by hand and call it. No item becomes more visible, and nothing outside private.rs and its tests.rs changes.

The diff is 124 insertions and 50 deletions: the three callers shrink by about 37 lines, and the two helpers with their documentation add about 57, so the production file grows by about 20 lines in return for one copy of each unsafe sequence. The two new tests add the other 54. Where to start: the SecurityDescriptor type after check_vm_dir.

Left out, as follow-ups that #1760 lists: a shared aligned-buffer helper (CurrentUser::get and object_name in log_claim.rs repeat the vec![0u64; ...] idiom), and a shared reader of the owner and the DACL.

Why is this change needed?

The unsafe length-then-fill protocol and its safety argument now live in one place instead of two copies that had to be kept in step, and the long functions read as their policy rather than as API plumbing. The Win32 calls, their arguments and order, and each io::Error::last_os_error() path are the same, so every error and every problem string is unchanged.

Rejected: a trait or generic wrapper over all the security-descriptor reads. It would touch the test helpers and the log_claim code, and the four call sites that matter here need only these two helpers.

How was this change validated?

Checks and results, on Windows (x86_64-pc-windows-msvc), Rust 1.97.1, with CARGO_TARGET_DIR set to a scratch directory:

  • Baseline at the base revision 3fa75642eb1, before the change: cargo test --locked --manifest-path nvx/Cargo.toml --features cli --lib -- host::platform::windows gave 33 passed, 0 failed, 1 ignored; ... -- host::vm_directory host::sandbox host::restore gave 131 passed, 0 failed, 1 ignored. After the change the same selectors give 35 passed (the two new tests) and 131 passed, and no existing test changed.
  • python scripts\local_gates.py --base origin/dev --run --keep-going (Git's usr\bin on PATH, XDG_CACHE_HOME unset): test-changes, markdown-links, test-layout, nvx-format, nvx-lint, nvx-test, nvx-doc, nvx-msrv, and nvx-cli all passed, in 796 s. The nvx-cli run left NVX unset because no nvx release build existed, so the tests that run nvx skipped, as the gate itself reports.
  • From check-nvx, in nvx/: cargo fmt --all --check, and cargo clippy --locked with --all-targets --all-features, with --lib, with --lib --no-default-features, with --lib --no-default-features --features serde, with --lib --bins --features cli, and with --lib --bins --no-default-features --features testing, each with -- -D warnings, all exit 0. RUSTDOCFLAGS='-D warnings' cargo doc --locked --no-deps --all-features exit 0. cargo test --locked --all-features gave 1115 passed, 0 failed in the library, and cargo test --locked gave 555 passed, 0 failed.
  • python scripts\public_api.py exit 0: the snapshots in nvx/public-api/ are unchanged.
  • python scripts\check_test_layout.py exit 0, and python scripts\check_test_changes.py --base origin/dev reports 0 changes to existing tests.

Backend, host OS, host type, and guest: none; this change is Windows host code and starts no VM.

Left to CI: the Linux-only check-nvx steps (the macOS build, the guest binaries), and the hypervisor jobs. The guest module does not build on Windows, and this change does not touch it.

Checklist

  • Tests cover the new or fixed behavior, in the layout that
    python3 scripts/check_test_layout.py checks.
  • python3 scripts/check_test_changes.py --base origin/dev lists no change
    to an existing test, or a Changes to existing tests section below
    explains each one.
  • The documentation that the change affects is updated, including
    .github/copilot-instructions.md and the skills when a convention or
    workflow changes. (None is affected.)
  • A change to the public API of nvx updates nvx-rs/public-api/ with
    python3 scripts/public_api.py --update. (No public item changes; nvx/public-api/ is unchanged.)
  • Snapshots, protocols, and on-disk formats stay compatible, or the
    description says how the change versions or migrates them.

…hecks

check_vm_dir and privacy_problem each ran the same two-call
GetKernelObjectSecurity sequence over an aligned buffer, and
vm_dir_problem and privacy_problem each ran the same GetAclInformation
query for an entry count. Name each once, as a private SecurityDescriptor
and ace_count in private.rs, and call them from both.

The Win32 calls, their arguments and their order, and every error and
problem string stay the same, and no item becomes more visible. Two
tests cover the new type: the owner and entries that it reads from a
store directory, and its refusal of a handle without read-control access.

Co-authored-by: Copilot <[email protected]>
Copilot AI balanced review requested due to automatic review settings November 19, 2026 00:37

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

There are no active review issues requiring changes to the Windows security-descriptor and ACL-read refactor.

No open issues 🎉

What changed in this PR

This PR addresses #1760 by consolidating duplicated Windows security-descriptor and access-control-list reads in NVX’s private-file checks, while preserving their policies, error handling, and public API.

Changes:

  • Adds a private SecurityDescriptor helper that owns the aligned buffer used by both checks.
  • Extracts the shared ACL entry-count query into ace_count, leaving policy checks unchanged.
  • Adds tests for reading an object’s owner and ACL entries and rejecting handles without read-control access.
File Description
nvx/​src/​host/​platform/​windows/​private/​tests.rs Adds successful descriptor-read and access-denied tests; existing tests remain unchanged.
nvx/​src/​host/​platform/​windows/​private.rs Introduces shared descriptor and ACL-count helpers and replaces duplicated Win32 sequences.

Review effort: Balanced

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

nvx: share the security descriptor and ACL reads of the Windows private-file checks

2 participants