Skip to content

Simplify VHD ownership handling during distribution moves - #41333

Merged
Ben Hillis (benhillis) merged 1 commit into
masterfrom
fix/move-distribution-owner
Aug 14, 2026
Merged

Simplify VHD ownership handling during distribution moves#41333
Ben Hillis (benhillis) merged 1 commit into
masterfrom
fix/move-distribution-owner

Conversation

@benhillis

Copy link
Copy Markdown
Member

Summary of the Pull Request

Simplifies VHD ownership handling when moving a distribution. The duplicated caller token now uses the caller's user SID as its default owner, and the move and rollback operations run under that token.

PR Checklist

  • Closes: Link to issue #xxx
  • Communication: I've discussed this with core contributors already. If work hasn't been agreed, this work might be rejected
  • Tests: Added/updated if needed and all pass
  • Localization: All end user facing strings can be localized
  • Dev docs: Added/updated if needed
  • Documentation updated: If checked, please file a pull request on our docs repo and link it here: #xxx

Detailed Description of the Pull Request / Additional comments

Cross-volume MoveFileExW operations create a new file using the impersonation token's default owner. This change sets the duplicated caller token's default owner to its user SID before moving the VHD, keeping the resulting file accessible to that user.

All filesystem operations, including rollback, use the modified caller token. This removes the need to reopen the destination and restore its owner after the move. Same-volume moves remain renames and preserve the existing owner.

Validation Steps Performed

  • cmake --build . -- -m
  • bin\x64\Debug\test.bat -f /name:*MoveVhdWithAdminOwner — passed (1/1)

Run distribution moves under a duplicated caller token whose default owner is the caller's user SID. This keeps cross-volume copies accessible without reopening the destination to rewrite its owner.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI lite review requested due to automatic review settings August 12, 2026 21:06
@benhillis
Ben Hillis (benhillis) requested a review from a team as a code owner August 12, 2026 21:06

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.

Pull request overview

This pull request simplifies distribution move behavior in the WSL Windows service by ensuring cross-volume VHD moves create the destination VHD with the caller’s user SID as the default owner, avoiding elevated-token ownership side effects (e.g., unexpected BUILTIN\Administrators ownership).

Changes:

  • Updates MoveDistribution() to set the duplicated caller impersonation token’s TokenOwner to the caller’s user SID and to run move/rollback filesystem operations under that token.
  • Removes the previous “read original owner then restore owner after move” flow (including privileged WRITE_OWNER fixup) in favor of the normalized-token approach.
  • Updates test commentary to reflect same-volume owner-preservation expectations.

Reviewed changes

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

File Description
src/windows/service/exe/LxssUserSession.cpp Sets the duplicated caller token default owner to the caller SID and performs move + rollback under that token, eliminating post-move owner restoration logic.
test/windows/UnitTests.cpp Adjusts regression test comments to align with the updated ownership/move behavior narrative.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

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.

Pull request overview

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

Suppressed comments (1)

src/windows/service/exe/LxssUserSession.cpp:942

  • The new ownership behavior is not exercised by the existing tests: MoveVhdOwnership and MoveVhdWithAdminOwner move between relative folders on the same volume, where MoveFileExW performs a rename and never uses the token's default owner. The tests therefore still pass if this SetTokenInformation call is removed. Add a genuinely cross-volume move (for example, using a temporary mounted VHD or another test volume) and verify that the copied VHD is owned by the caller and remains launchable.
    THROW_IF_WIN32_BOOL_FALSE(SetTokenInformation(userToken.get(), TokenOwner, &tokenOwner, sizeof(tokenOwner)));

@OneBlue Blue (OneBlue) left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Change LGTM, one small change in behavior is that now we're reverting the VHD owner to the current token on failure, instead of the original VHD's owner.

I could imagine some situations where that could lead to issues, especially if there are some custom ACL's, but I don't think that's necessarily a blocker. That could be fixed in a followup

@benhillis

Copy link
Copy Markdown
Member Author

Change LGTM, one small change in behavior is that now we're reverting the VHD owner to the current token on failure, instead of the original VHD's owner.

I could imagine some situations where that could lead to issues, especially if there are some custom ACL's, but I don't think that's necessarily a blocker. That could be fixed in a followup

Yeah that's true, I think this is an improvement over the existing so I'll look at fixing the ACL stuff in a follow-up.

@benhillis
Ben Hillis (benhillis) merged commit c9f0d36 into master Aug 14, 2026
13 checks passed
@benhillis
Ben Hillis (benhillis) deleted the fix/move-distribution-owner branch August 14, 2026 00:29
Ben Hillis (benhillis) added a commit that referenced this pull request Aug 14, 2026
Run distribution moves under a duplicated caller token whose default owner is the caller's user SID. This keeps cross-volume copies accessible without reopening the destination to rewrite its owner.

Co-authored-by: Ben Hillis <benhill@ntdev.microsoft.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Ben Hillis (benhillis) added a commit that referenced this pull request Aug 17, 2026
* Fix VHD ownership during distribution moves (#41333)

Run distribution moves under a duplicated caller token whose default owner is the caller's user SID. This keeps cross-volume copies accessible without reopening the destination to rewrite its owner.

Co-authored-by: Ben Hillis <benhill@ntdev.microsoft.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* fix build error

* Preserve token owner during move rollback

Save the duplicated caller token's original default owner before normalizing it for a distribution move. Restore that owner before a rollback so cross-volume rollback copies retain the caller token's prior ownership behavior.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Restore VHD owner during move rollback

Capture the source VHD owner before moving it and use that SID as the duplicated token's default owner for a cross-volume rollback. This leaves ownership unchanged when the operation fails.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Request token owner adjustment access for distro moves

MoveDistribution updates the duplicated caller token's default owner before moving a VHD. Request TOKEN_ADJUST_DEFAULT for this operation so SetTokenInformation succeeds on release/2.7.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 36bcfb50-8208-46ef-a5a3-21fb9b57b467

---------

Co-authored-by: Ben Hillis <benhill@ntdev.microsoft.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 36bcfb50-8208-46ef-a5a3-21fb9b57b467
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.

3 participants