Simplify VHD ownership handling during distribution moves - #41333
Conversation
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>
There was a problem hiding this comment.
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’sTokenOwnerto 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_OWNERfixup) 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.
There was a problem hiding this comment.
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:
MoveVhdOwnershipandMoveVhdWithAdminOwnermove between relative folders on the same volume, whereMoveFileExWperforms a rename and never uses the token's default owner. The tests therefore still pass if thisSetTokenInformationcall 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)));
Blue (OneBlue)
left a comment
There was a problem hiding this comment.
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. |
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 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
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
Detailed Description of the Pull Request / Additional comments
Cross-volume
MoveFileExWoperations 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 . -- -mbin\x64\Debug\test.bat -f /name:*MoveVhdWithAdminOwner— passed (1/1)