Skip to content

Service: Best-effort grant of VMWP access to user-supplied VHDs#40485

Open
Copilot wants to merge 1 commit into
masterfrom
copilot/fix-wsl-access-denied-error
Open

Service: Best-effort grant of VMWP access to user-supplied VHDs#40485
Copilot wants to merge 1 commit into
masterfrom
copilot/fix-wsl-access-denied-error

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 10, 2026

HCS fails with E_ACCESSDENIED when starting a VM whose user-supplied kernelModules or systemDistro VHDs live somewhere VMWP cannot read (e.g. under the user profile). Eagerly call HcsGrantVmAccess on those paths while impersonating the user, before the VM is started.

The grant is best-effort: it requires WRITE_DAC on the file (typically via ownership), which the impersonated user may lack for VHDs they only have READ access to (e.g. SYSTEM-owned VHDs reachable via inherited folder ACLs). Failures are logged via CATCH_LOG; if VMWP truly cannot read the VHD, StartComputeSystem will still surface a clear E_ACCESSDENIED.

Tests

  • CustomVhdsInUserProfile: VHDs under %TEMP%, exercises the grant path.
  • CustomVhdsAccessibleViaInheritedAcls: VHDs in the install dir launched as a non-elevated user, exercises the swallowed-grant-failure path.

Copilot AI requested review from Copilot and removed request for Copilot May 10, 2026 15:05
Copilot AI requested review from Copilot and removed request for Copilot May 10, 2026 15:08
Copilot AI changed the title [WIP] Fix access denied error for custom kernel modules in WSL 2.7.3.0 Fix custom kernel modules VHD boot ACL grant for user-profile paths May 10, 2026
Copilot AI requested a review from benhillis May 10, 2026 15:13
Copilot AI review requested due to automatic review settings May 11, 2026 17:24
@benhillis benhillis force-pushed the copilot/fix-wsl-access-denied-error branch from 2e27dbe to 56bac44 Compare May 11, 2026 17:24
@benhillis benhillis changed the title Fix custom kernel modules VHD boot ACL grant for user-profile paths Service: Grant VMWP access to user-supplied kernelModules and systemDistro VHDs May 11, 2026
@benhillis benhillis marked this pull request as ready for review May 11, 2026 17:25
@benhillis benhillis requested a review from a team as a code owner May 11, 2026 17:25
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Aligns WSL VM boot-time behavior to grant HCS/VMWP access for user-supplied VHD paths (notably under C:\Users\...) to prevent E_ACCESSDENIED during VM creation, and updates Windows tests to cover the user-profile repro scenario.

Changes:

  • Add optional pre-start GrantVmAccess to SCSI VHD attach flow and track AccessGranted for teardown.
  • Extend test config generation to support systemDistro=....
  • Update the existing custom VHD test to place VHDs under the user profile and harden cleanup.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
test/windows/UnitTests.cpp Updates/renames the test to stage VHDs under the user profile and remove ACL entries to reproduce the regression.
test/windows/Common.h Adds systemDistro to the test config defaults struct.
test/windows/Common.cpp Emits systemDistro=... into generated .wslconfig content for tests.
src/windows/service/exe/WslCoreVm.cpp Adds optional pre-start VM access grant when attaching VHDs and records access-granted state for later revoke.

Comment thread test/windows/UnitTests.cpp Outdated
Comment thread test/windows/UnitTests.cpp Outdated
Comment thread test/windows/UnitTests.cpp
Comment thread src/windows/service/exe/WslCoreVm.cpp
@benhillis benhillis force-pushed the copilot/fix-wsl-access-denied-error branch from 56bac44 to 8787a50 Compare May 11, 2026 17:46
Copilot AI review requested due to automatic review settings May 11, 2026 19:51
@benhillis benhillis force-pushed the copilot/fix-wsl-access-denied-error branch from 8787a50 to 99d61b1 Compare May 11, 2026 19:51
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

Comment thread test/windows/UnitTests.cpp Outdated
@benhillis benhillis force-pushed the copilot/fix-wsl-access-denied-error branch from 99d61b1 to e57a596 Compare May 11, 2026 21:18
Copilot AI review requested due to automatic review settings May 12, 2026 05:14
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.

@benhillis benhillis force-pushed the copilot/fix-wsl-access-denied-error branch from e764ae1 to e22f943 Compare May 12, 2026 15:52
@benhillis benhillis changed the title Service: Grant VMWP access to user-supplied kernelModules and systemDistro VHDs Service: Best-effort grant of VMWP access to user-supplied VHDs May 12, 2026
@benhillis benhillis requested a review from Copilot May 12, 2026 15:53
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.

@benhillis benhillis force-pushed the copilot/fix-wsl-access-denied-error branch from e22f943 to 23b0efe Compare May 12, 2026 16:33
Copilot AI review requested due to automatic review settings May 12, 2026 17:11
@benhillis benhillis force-pushed the copilot/fix-wsl-access-denied-error branch from 23b0efe to 11d834a Compare May 12, 2026 17:11
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Comment thread src/windows/service/exe/WslCoreVm.cpp Outdated
Comment thread test/windows/UnitTests.cpp
@benhillis benhillis force-pushed the copilot/fix-wsl-access-denied-error branch from 11d834a to 5bd8d73 Compare May 12, 2026 17:24
HCS fails with E_ACCESSDENIED when starting a VM whose user-supplied
kernelModules or systemDistro VHDs live somewhere VMWP cannot read
(e.g. under the user profile). Eagerly call HcsGrantVmAccess on those
paths while impersonating the user, before the VM is started.

The grant is best-effort: it requires WRITE_DAC on the file (typically
via ownership), which the impersonated user may lack for VHDs they only
have READ access to (e.g. SYSTEM-owned VHDs reachable via inherited
folder ACLs). Failures are logged via CATCH_LOG; if VMWP truly cannot
read the VHD, StartComputeSystem will still surface a clear
E_ACCESSDENIED.

Adds two regression tests:
- CustomVhdsInUserProfile: VHDs under %TEMP%, exercises the grant path.
- CustomVhdsAccessibleViaInheritedAcls: VHDs in the install dir launched
  as a non-elevated user, exercises the swallowed-grant-failure path.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 12, 2026 18:05
@benhillis benhillis force-pushed the copilot/fix-wsl-access-denied-error branch from 5bd8d73 to a2d62d5 Compare May 12, 2026 18:05
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.

@benhillis
Copy link
Copy Markdown
Member

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

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.

[BUG] After the WSL 2.7.3.0 update, custom kernel modules are not working due to an 'access denied' error

3 participants