Fix swapFile vhd conflict with distro data vhd issue #14045#14467
Fix swapFile vhd conflict with distro data vhd issue #14045#14467wangxin12 wants to merge 1 commit intomicrosoft:masterfrom
Conversation
… setting points to a distribution's data VHD
There was a problem hiding this comment.
Pull request overview
Adds a safety check in the Windows WSL service to prevent .wslconfig’s swapFile from pointing at a distribution’s data VHD, returning a dedicated HRESULT and localized user-facing message to avoid silent filesystem corruption.
Changes:
- Add swapFile-vs-distro-VHD conflict detection during VM creation (
LxssUserSessionImpl::_CreateVm). - Introduce new error code
WSL_E_SWAP_FILE_CONFLICTS_WITH_DISTROand wire it into error-to-string mapping. - Add localized string and a new Windows unit test covering the conflict scenario.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| test/windows/UnitTests.cpp | Adds a unit test asserting WSL fails with the new error when swapFile targets a distro VHD. |
| src/windows/service/inc/wslservice.idl | Defines new HRESULT WSL_E_SWAP_FILE_CONFLICTS_WITH_DISTRO. |
| src/windows/service/exe/LxssUserSession.cpp | Implements swapFile conflict validation during VM creation. |
| src/windows/common/wslutil.cpp | Adds the new error to common HRESULT-to-name mapping used in output. |
| localization/strings/en-US/Resources.resw | Adds localized user-facing error message for the new validation. |
|
Honestly probably a better solution is just to enforce that we need to create the swap .vhd ourselves. Might be a minor UX difference, but I think that's fine. |
@benhillis so we can just disable the "swapFile" option in .wslconfig? I'd like to confirm this solution with you before I make the change. |
Summary of the Pull Request
Detect and fail with a clear error message when
.wslconfig'sswapFilesetting points to a distribution's data VHD, preventing silent data corruption.PR Checklist
Detailed Description of the Pull Request / Additional comments
Add a validation check in
LxssUserSessionImpl::_CreateVm()(after config is loaded, beforeWslCoreVm::Create) that enumerates all registered distributions and compares their VHD paths against the resolved swap file path. If a match is found, throw with a localized user-facing error message.Validation Steps Performed
.wslconfig
Unit test