Preserve token owner during distribution move rollback - #41355
Conversation
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>
There was a problem hiding this comment.
Pull request overview
This PR updates WSL’s Windows service distribution-move flow to preserve the duplicated caller token’s original default owner (TokenOwner) specifically for rollback scenarios, so cross-volume rollback copies keep the prior default-owner behavior while forward moves still normalize ownership to the caller’s user SID.
Changes:
- Capture the duplicated caller token’s original
TOKEN_OWNERbefore normalizing it to the caller’s user SID. - Restore the original token owner inside the rollback (
scope_exit_log) path before executing the reverseMoveFileExW.
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
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>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.
Suppressed comments (2)
src/windows/service/exe/LxssUserSession.cpp:980
- Rollback restores TokenOwner using originalVhdOwner unconditionally. If owner capture fails (or returns a null owner SID), this passes an invalid SID to SetTokenInformation and can also obscure the intended behavior. Guard the restore on originalVhdOwner being non-null.
auto revert = wil::scope_exit_log(WI_DIAGNOSTICS_INFO, [&]() {
TOKEN_OWNER originalOwner{originalVhdOwner};
LOG_IF_WIN32_BOOL_FALSE(SetTokenInformation(userToken.get(), TokenOwner, &originalOwner, sizeof(originalOwner)));
src/windows/service/exe/LxssUserSession.cpp:958
- GetNamedSecurityInfoW failure now aborts MoveDistribution (THROW_IF_WIN32_ERROR). That can turn an otherwise-successful move into a hard failure if the caller lacks READ_CONTROL or the security query otherwise fails. Consider making the owner capture best-effort (log and continue), since it’s only needed to improve rollback fidelity.
This issue also appears on line 977 of the same file.
{
auto impersonate = wil::impersonate_token(userToken.get());
THROW_IF_WIN32_ERROR(GetNamedSecurityInfoW(
distro.VhdFilePath.c_str(), SE_FILE_OBJECT, OWNER_SECURITY_INFORMATION, &originalVhdOwner, nullptr, nullptr, nullptr, &originalSecurityDescriptor));
}
Summary of the Pull Request
Preserves the source VHD's owner when rolling back a distribution move.
PR Checklist
Detailed Description of the Pull Request / Additional comments
Follow-up to #41333. Before moving the VHD, capture its current owner SID under caller impersonation. If the operation must be rolled back, use that SID as the duplicated token's default owner before the reverse
MoveFileExWoperation.This keeps the normal forward move owned by the caller's user SID while ensuring a cross-volume rollback recreates the VHD with its pre-move owner.
Validation Steps Performed
FormatSource.ps1cmake --build . -- -mbin\x64\Debug\test.bat -f /name:*MoveVhd*was attempted; shared module setup failed while setting the defaulttest_distro, before either selected test executed.