Skip to content

virtiofs: impersonate Windows users for host filesystem access - #4876

Open
Daman Mulye (damanm24) wants to merge 9 commits into
microsoft:mainfrom
damanm24:virtiofs-windows-impersonation
Open

Daman Mulye (damanm24) wants to merge 9 commits into
microsoft:mainfrom
damanm24:virtiofs-windows-impersonation

Conversation

@damanm24

Copy link
Copy Markdown
Contributor

This PR adds per-user access to Windows shares through virtiofs. Host filesystem access currently uses the VM service process token, which may have different permissions from the user whose files are being shared.

Callers can provide a Windows token handle duplicated into the VM service process through the virtiofs RPC configuration. OpenVMM owns a duplicate and impersonates it when opening the share and handling each FUSE request, then reverts to the process identity afterward. The token is kept with the FUSE session. Omitting the token or passing zero preserves the existing behavior.

Invalid tokens fail device creation, and requests return an I/O error if impersonation fails rather than falling back to the process token. Windows regression tests check that successful and failing FUSE requests run under a restricted token and leave no thread token afterward.

Copilot AI balanced review requested due to automatic review settings November 3, 2026 18:33
@github-actions github-actions Bot added the unsafe Related to unsafe code label Nov 3, 2026
@github-actions

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown

⚠️ Unsafe Code Detected

This PR modifies files containing unsafe Rust code. Extra scrutiny is required during review.

For more on why we check whole files, instead of just diffs, check out the Rustonomicon

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.

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Copilot review overview

3 open issues
What changed in this PR

Adds Windows user-token impersonation support for virtio-fs host filesystem access, enabling per-user permissions rather than always using the VM service process token.

Changes:

  • Introduces VirtioFsSession wrapper to optionally impersonate a Windows user token per FUSE request.
  • Extends virtio-fs resource/config plumbing to carry optional Windows token handle and duplicate it into OpenVMM.
  • Refactors device construction to use a VirtioFsDeviceOptions struct and adds parsing/validation in the virtiofs resolver.
File Description
vmm_tests/​vmm_tests/​tests/​tests/​ttrpc.rs Updates virtio-fs test configs to populate the new windows_options field.
vm/​devices/​virtio/​virtiofs/​src/​virtio.rs Refactors device construction around options and routes requests through VirtioFsSession for optional impersonation.
vm/​devices/​virtio/​virtiofs/​src/​session.rs Adds a session wrapper that impersonates a Windows token during dispatch and returns EIO on impersonation failure.
vm/​devices/​virtio/​virtiofs/​src/​resolver.rs Adds structured parsing/validation and Windows-specific token duplication/impersonated open behavior.
vm/​devices/​virtio/​virtiofs/​src/​lib.rs Wires in new impersonation (Windows) and session modules.
vm/​devices/​virtio/​virtiofs/​src/​integration_tests.rs Updates integration test harness to use VirtioFsDeviceOptions.
vm/​devices/​virtio/​virtiofs/​src/​impersonation.rs Implements Windows token duplication and thread impersonation guard with tests.
vm/​devices/​virtio/​virtiofs/​Cargo.toml Adds deps/features needed for impersonation + resolver cfg branching.
vm/​devices/​virtio/​virtio_resources/​src/​lib.rs Extends virtio-fs resources with Windows options payload (token handle).
petri/​burette/​src/​tests/​virtio_fs.rs Updates test resource construction to include windows_options.
openvmm/​openvmm_ttrpc_vmservice/​src/​vmservice.proto Adds WindowsOptions and token handle to virtio-fs RPC config.
openvmm/​openvmm_entry/​src/​ttrpc/​mod.rs Plumbs windows_options from RPC into virtio resource handle and refactors virtio-fs builder.
openvmm/​openvmm_entry/​src/​lib.rs Updates CLI-based virtio-fs config to set windows_options: None.

Review effort: Lite

Copilot AI balanced review requested due to automatic review settings November 3, 2026 18:52

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.

🔵 Needs a closer look

The dispatch test does not cover impersonation failure; a Windows regression must verify -EIO, no filesystem invocation, and no residual thread token.

1 open issue
1 previously missed issue

In code that hasn't changed since last review

Medium severity Add regression test for Windows impersonation failure

vm/​devices/​virtio/​virtiofs/​src/​session.rs:51

Please add a Windows regression for impersonation failure, using an owned non-token handle, and assert that dispatch returns -EIO, never invokes the filesystem, and leaves no thread token. The added dispatch test only exercises a filesystem EACCES after impersonation succeeds, so it would still pass if this failure path regressed to dispatching with the process identity.

2 resolved since last review

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings November 3, 2026 19:09
@damanm24
Daman Mulye (damanm24) marked this pull request as ready for review November 3, 2026 19:11

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.

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Copilot review overview

2 open issues
1 resolved since last review

Review effort: Lite

Comment thread support/pal/src/windows/security.rs Resolved
Comment thread openvmm/openvmm_entry/src/ttrpc/mod.rs Resolved
Copilot AI balanced review requested due to automatic review settings November 3, 2026 20:50

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.

🔵 Needs a closer look

Human assessment is needed because the Windows regression test does not exercise impersonation failure, leaving fail-closed behavior against dispatch under the process identity unverified.

No open issues 🎉

2 resolved since last review

Review effort: Balanced

@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown

Copilot AI balanced review requested due to automatic review settings November 5, 2026 00:26
@github-actions github-actions Bot added the Guide label Nov 5, 2026

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.

🟡 Changes recommended

Missing Windows regression tests leave impersonation-failure handling and token-scoped share opening unverified, including protection against process-identity fallback and thread-token cleanup.

2 open issues

Review effort: Balanced

Daman Mulye and others added 7 commits November 4, 2026 16:39
Duplicate the caller's token while resolving HostFs, retain it with the FUSE session, and impersonate it for each dispatch. Revert afterward and cover successful and failing dispatches with a restricted-token regression test.

Split user impersonation from PR microsoft#4706 without DAX remapping or backend-option changes. Keep resource and protobuf field numbers compatible with the independent DAX branch.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Keep common HostFs parsing and resource resolution together, with token parsing and impersonation in one platform-specific implementation block. Preserve existing validation and token ownership, and cover rejection of Windows-only options on other hosts.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Extract RevertToSelfGuard into pal::windows::security and reuse it for virtiofs requests and sparse-mmap privilege adjustment. Keep impersonation thread-bound and preserve fail-fast cleanup behavior.

Share root-path validation between HostFs and SectionFs.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
main replaced the cfg-if crate with the standard cfg_select! macro (microsoft#4883).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@damanm24
Daman Mulye (damanm24) force-pushed the virtiofs-windows-impersonation branch from beababd to 5e20a63 Compare November 5, 2026 00:55
Copilot AI balanced review requested due to automatic review settings November 5, 2026 00:55

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.

🔵 Needs a closer look

Windows regression tests do not cover fail-closed dispatch when impersonation fails or verify the identity used to open the share, leaving security-sensitive behavior unprotected against regressions.

2 open issues

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings November 5, 2026 01:44

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.

🔵 Needs a closer look

The Windows filesystem identity boundary and cross-process handle transfer require human security review and Windows runtime testing to validate ACL enforcement, token lifetime, and impersonation cleanup.

1 open issue
1 resolved since last review

Review effort: Balanced

@github-actions

github-actions Bot commented Nov 5, 2026

Copy link
Copy Markdown

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.

🔵 Needs a closer look

Windows impersonation and client-supplied handle registration alter security and cross-process ownership boundaries, requiring security-owner review and native Windows validation beyond the available static inspection.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings November 13, 2026 00:05

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.

🔵 Needs a closer look

Windows impersonation and cross-process token transfer alter an access-control boundary, requiring human security review and native Windows validation that was unavailable.

No open issues 🎉

Review effort: Balanced

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

Labels

Guide unsafe Related to unsafe code wsl

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants