Skip to content

Reject non-empty directories for new WSLC session storage#40655

Open
beena352 wants to merge 12 commits into
microsoft:masterfrom
beena352:user/beenachauhan/wslc-session-storage-marker
Open

Reject non-empty directories for new WSLC session storage#40655
beena352 wants to merge 12 commits into
microsoft:masterfrom
beena352:user/beenachauhan/wslc-session-storage-marker

Conversation

@beena352
Copy link
Copy Markdown
Contributor

@beena352 beena352 commented May 27, 2026

Summary of the Pull Request

Prevent users from accidentally reusing existing non-empty directories as WSLC session storage. For new sessions, validate that the storage directory is either empty or non-existent. Existing sessions identified by their storage.vhdx VHD bypass this check, so users can re-enter sessions freely even if additional files are present in the storage directory.

PR Checklist

  • Closes: Link to issue #62259817
  • 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

Validate session storage paths at initialization time:

  • If creating a new session and the directory already exists and is non-empty, reject with E_INVALIDARG and a user-facing error message
  • If the directory is empty or doesn't exist, create it and proceed
  • If a session's VHD already exists in the directory, skip the emptiness check (re-entry allowed)
    This prevents data loss by ensuring new sessions don't accidentally overwrite unrelated user files placed in the storage directory. Once a session is created (VHD exists), the directory can contain other files without blocking re-entry.

Validation Steps Performed

Copilot AI review requested due to automatic review settings May 27, 2026 17:35
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

Adds a wslcsession marker-file convention at the root of a WSLC session storage directory so the service can distinguish directories it owns from arbitrary user content, and rejects new session creation into a non-empty, unmarked directory. Also wires IErrorInfo/COMServiceExecutionContext through the per-user WSLCSessionFactory and WSLCSessionManager so the user-facing rejection message reaches the CLI/test caller.

Changes:

  • Add EnsureSessionMarker helper in WSLCSession::ConfigureStorage (new sessions require empty dir + stamp marker; existing VHD paths get a legacy upgrade stamp).
  • Add ISupportErrorInfo + COMServiceExecutionContext to WSLCSessionFactory and propagate IErrorInfo from factory to caller in WSLCSessionManagerImpl::CreateSession; add ISupportErrorInfo to WSLCSessionManager.
  • Add API-level and e2e tests for marker rejection and legacy auto-upgrade; add localized MessageWslcSessionStorageMustBeEmpty.

Reviewed changes

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

Show a summary per file
File Description
src/windows/wslcsession/WSLCSession.cpp New EnsureSessionMarker helper and wiring into ConfigureStorage for new/existing storage paths.
src/windows/wslcsession/WSLCSessionFactory.cpp Establish COMServiceExecutionContext around CreateSession and implement InterfaceSupportsErrorInfo.
src/windows/wslcsession/WSLCSessionFactory.h Add ISupportErrorInfo base and method declaration.
src/windows/service/exe/WSLCSessionManager.cpp Inspect IErrorInfo after factory failure and re-throw with user-facing message; implement InterfaceSupportsErrorInfo.
src/windows/service/exe/WSLCSessionManager.h Add ISupportErrorInfo base and method declaration.
test/windows/WSLCTests.cpp New API-level cases: non-empty dir rejection and wslcsession-as-directory rejection with COM error validation.
test/windows/wslc/e2e/WSLCE2ESessionEnterTests.cpp E2E test verifying marker creation on default session and legacy auto-upgrade.
localization/strings/en-US/Resources.resw New MessageWslcSessionStorageMustBeEmpty localized string.

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 8 out of 8 changed files in this pull request and generated no new comments.

Copilot AI review requested due to automatic review settings May 28, 2026 16:36
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 8 out of 8 changed files in this pull request and generated no new comments.

Copy link
Copy Markdown
Collaborator

@OneBlue OneBlue left a comment

Choose a reason for hiding this comment

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

I think refusing to create a session storage if the directory is non-empty makes sense (although I worry a bit about this putting us in a corner, like if there's ever a thumdb.db, desktop.ini or similar file created, this could "lock a user out" of using that folder permanently)

I'm not sure about the marker file though. Whenever we create a storage folder, we always create a storage VHD, so could we use that directly instead ?

Copilot AI review requested due to automatic review settings June 2, 2026 18: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 8 out of 8 changed files in this pull request and generated 3 comments.

Comment thread src/windows/wslcsession/WSLCSession.cpp Outdated
Comment thread src/windows/wslcsession/WSLCSession.cpp
Comment thread src/windows/wslcsession/WSLCSessionFactory.cpp Outdated
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 8 out of 8 changed files in this pull request and generated 1 comment.

Comment thread src/windows/wslcsession/WSLCSession.cpp
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 8 out of 8 changed files in this pull request and generated 1 comment.

Comment thread src/windows/wslcsession/WSLCSessionFactory.cpp Outdated
@beena352 beena352 marked this pull request as ready for review June 3, 2026 17:40
@beena352 beena352 requested a review from a team as a code owner June 3, 2026 17:40
@beena352 beena352 marked this pull request as draft June 3, 2026 17:41
@beena352 beena352 changed the title Add marker-file validation for WSLC session storage Reject non-empty directories for new WSLC session storage Jun 3, 2026
@beena352 beena352 marked this pull request as ready for review June 3, 2026 17:43
@beena352 beena352 marked this pull request as draft June 4, 2026 22:18
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 8 out of 8 changed files in this pull request and generated 1 comment.

Comment thread src/windows/wslcsession/WSLCSession.cpp
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 8 out of 8 changed files in this pull request and generated 1 comment.

Comment thread src/windows/wslcsession/WSLCSession.cpp
@beena352 beena352 marked this pull request as ready for review June 5, 2026 16:12
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