Skip to content

WSLC: sanitize HostingProcessNameSuffix to keep vmmem process name well-formed#40471

Open
benhillis wants to merge 1 commit intomasterfrom
wslc-default-session-name
Open

WSLC: sanitize HostingProcessNameSuffix to keep vmmem process name well-formed#40471
benhillis wants to merge 1 commit intomasterfrom
wslc-default-session-name

Conversation

@benhillis
Copy link
Copy Markdown
Member

@benhillis benhillis commented May 8, 2026

Problem

The HCS HostingProcessNameSuffix becomes the vmmem-XXX process name visible in Task Manager and parsed by various tooling. HcsVirtualMachine was passing the caller's Settings->DisplayName straight through, but for default WSLC sessions that string is built from the caller's username via LookupAccountSidW (added in #40144 / cd05f5c). Usernames can easily contain spaces, unicode, or other characters that produce a malformed vmmem process name.

Fix

Sanitize the value when it's written to HostingProcessNameSuffix: replace any character outside the conservative ASCII allowlist [A-Za-z0-9._-] with _.

Settings->DisplayName itself is not modified — it still flows verbatim into the HCS Owner field, session lookup, telemetry, etc. Only the vmmem suffix gets the scrub.

Scope

Intentionally minimal. This PR does not:

  • Change how default session names are resolved (username suffix retained)
  • Add caller-side validation of DisplayName
  • Change reserved-name semantics or per-user lookup behavior
  • Touch the existing WSL (non-WSLC) path in WslCoreVm.cpp, which already uses the literal c_vmOwner = L"WSL" for its suffix and so doesn't need sanitizing

If we later want to drop the username from the HCS Owner field too, that's a separate change.

Files

  • src/windows/service/exe/HcsVirtualMachine.cpp — file-local SanitizeHostingProcessNameSuffix helper applied at the single HostingProcessNameSuffix assignment site.

Build/test status

IntelliSense-checked only. No new tests — the sanitization is a one-line string transform on a path that has no observable behavior other than the vmmem process name.

Copilot AI review requested due to automatic review settings May 8, 2026 20:37
@benhillis benhillis requested a review from a team as a code owner May 8, 2026 20:37
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

This PR updates WSLC session naming to avoid embedding the caller’s username in the default session name (to prevent HCS/vmmem suffix issues and username collisions), and adds strict validation for caller-supplied session display names before they can flow into HCS.

Changes:

  • Switch default session naming to fixed well-known names (wslc-cli / wslc-cli-admin) and disambiguate per-user default sessions by comparing owner SIDs during lookup.
  • Add server-side validation for custom session names using an ASCII allowlist and maximum-length enforcement.
  • Update unit and E2E tests to remove username-suffixed expectations and add new validation cases.

Reviewed changes

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

Show a summary per file
File Description
test/windows/WSLCTests.cpp Adds negative tests for invalid session name characters and a regression assertion about reserved-name behavior.
test/windows/wslc/e2e/WSLCE2ESessionEnterTests.cpp Updates default storage path computation to no longer include username suffix.
test/windows/wslc/e2e/WSLCE2EHelpers.cpp Updates helper logic to terminate default sessions using fixed well-known names.
test/windows/wslc/e2e/WSLCE2EGlobalTests.cpp Updates expected default session name helpers/comments to fixed names and SID-based disambiguation.
src/windows/service/exe/WSLCSessionManager.h Documents new default-name behavior and introduces IsValidSessionName.
src/windows/service/exe/WSLCSessionManager.cpp Implements fixed default names, owner-SID scoping for default lookups, and display-name validation.
src/windows/service/exe/HcsVirtualMachine.cpp Clarifies (via comment) that display names are validated before reaching HCS fields.

Comment thread src/windows/service/exe/WSLCSessionManager.cpp Outdated
Comment thread src/windows/service/exe/WSLCSessionManager.cpp
@benhillis benhillis force-pushed the wslc-default-session-name branch from 7631ead to 36eab3e Compare May 8, 2026 21:43
@benhillis benhillis changed the title WSLC: drop username from default session name and validate caller names WSLC: sanitize HostingProcessNameSuffix to keep vmmem process name well-formed May 8, 2026
@benhillis benhillis requested a review from Copilot May 8, 2026 22:03
OneBlue
OneBlue previously approved these changes May 8, 2026
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 1 out of 1 changed files in this pull request and generated 1 comment.

Comment thread src/windows/service/exe/HcsVirtualMachine.cpp
…ll-formed

The HCS HostingProcessNameSuffix becomes the vmmem-XXX process name visible
in Task Manager and parsed by various tooling. When the caller's DisplayName
contains spaces, unicode, or other non-ASCII characters (which can easily
happen because default session names are derived from the caller's username
via LookupAccountSidW), it produces a malformed process name.

Fix: when assigning the suffix, replace any character outside the conservative
ASCII allowlist [A-Za-z0-9._-] with '_'. Settings->DisplayName itself (used
for the HCS Owner field, session lookup, etc.) is left untouched so existing
session-naming behavior is unchanged.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@benhillis benhillis force-pushed the wslc-default-session-name branch from 36eab3e to 8f1372d Compare May 8, 2026 22:33
@benhillis benhillis enabled auto-merge (squash) May 8, 2026 22:40
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