Commit Graph
536 Commits
Author SHA1 Message Date
David Bennett 1b6516b7ca Add --format json-array 2026-09-24 14:02:19 -07:00
Blue a153d883d6 Impersonate the caller before making various filesystem operations (#41689)
* Impersonate the caller before making various filesystem operations

* Apply PR feedback
2026-09-24 10:13:48 -07:00
Blue 4ccd41ae18 INcrease the VM termination timeout to 30 seconds (#41688) 2026-09-24 10:09:21 -07:00
Feng Wang 72542675aa resolve comments (#41642)
This is a follow up to PR #41512

Remove the redundant restore cgroup namespace code.
Simplify the cgroup check logic by moving the retry inside the debug shell.
Add a new systemd boot timeout test.
2026-09-23 08:01:00 +08:00
Feng Wang 8fbdba5cae Prevent potential invalid access for string array pretty print (#41673) 2026-09-22 14:43:01 -07:00
Feng Wang 56244fdb65 Fix config's handling of non-ascii characters (#41657)
When parsing the config file, non-ascii utf-16 values are casted into char. This will mangle non-ascii values in the config file. For example, a custom kernel path containing Chinese characters will cause WSL_E_CUSTOM_KERNEL_NOT_FOUND.

This PR removes the faulty static cast and stores the config value in wstring instead of string. So non-ascii values are preserved.
2026-09-22 10:42:24 +08:00
beena352 535b16d896 simplify event reader cleanup and remove unused include (#41667) 2026-09-21 16:50:13 -07:00
Blue 6ab1ac65a1 Fix potential out of bound access when pretty-printing string field in init messages (#41664) 2026-09-21 14:32:16 -07:00
beena352 1b3e0ec446 Add WSLC network lifecycle events (#41576)
* Add WSLC network lifecycle events

* Localize pending network prune errors

* Fix network operation wait ownership and cleanup ordering

* Fix prune event correlation after timed-out

* Fix network event rollback and timeout recovery

* Format

* Forward Docker network events directly

* Restore lock_guard after removing event waits

* fix test

* align event stream test helpers after merge

* feedback
2026-09-21 11:02:57 -07:00
Blue d49f455596 Fix various protocol parsing issues (#41637)
* Save state

* Use proper arrays

* Format

* Add new tests

* Cleanup tests

* Cleanup diff

* Format

* Apply PR feedback

* Apply PR feedback

* Format

* Apply PR feedback

* Move logging call

* Apply PR feedback

* Apply PR feedback
2026-09-18 14:42:55 -07:00
ggarzia-MSFTandCopilot 0f7ae21a4b Move objects shared by wslc.exe and the tests to src/windows/common (#41619)
* Move objects shared by wslc.exe and the tests to src/windows/common

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Link yaml-cpp, advapi32 and Crypt32 into common

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Drop yaml-cpp, advapi32 and crypt32 from wslclib now that common provides them

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Move wslc code in common under common/wslc and namespace CLI types as wslc::cli

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-09-18 14:40:38 -07:00
ggarzia-MSFTandCopilot b5f2411d3b wslc: add --follow-link to cp (#41501)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-09-18 12:11:33 -07:00
Feng Wang 611467bc13 Fix unnecessary delay in the port tracking loop (#41472)
Before this change, an additional 10ms delay was added in the port tracker loop presumably to make the main loop slower than the worker loop. So, the worker result does not get super dated. This is not reliable. And the 10ms delay also slows down every consecutive bind call.

This PR refactors the thread synchronization method. So, the timing between those two loops is more deterministic. And removes the performance penalty for all bind calls.
2026-09-18 11:13:29 +08:00
Feng Wang 4196b0ab2e Create new namespaces for distro cgroups (#41512)
In 2.9.8, the distro processes are separated into their own cgroups. But they remain in the same cgroup namespace. That caused compatibility issues with softwares that assume a fixed systemd cgroup layout. For example, rootless docker and nerdctl.
Fixes on Moby and nertctl are being worked on. However, to avoid issues with other software, WSL's cgroup handling should also be improved.

This PR creates new cgroup namespaces for the distros. So, to the non-critical distro processes, the systemd cgroup layout stays the same as before.
This PR also introduces a cgroup structure change to accomplish this. The systemd init is moved from wsl-user/distro-N/systemd to wsl-user/distro-N. And the initialization of the distro-N controllers is handled by systemd instead.
The processes are also moved into the non-systemd cgroup in systemdless distros. This makes sure that sub-group controllers can be enabled in the distro root.
Cgroup v2 is now enforced when distro isolation is enabled. Instead of constructing an unusable cgroup v1 layout when cgroup v1 and distro isolation are both enabled.
2026-09-18 11:08:31 +08:00
beena352 214bcadf5e Add wslc events command (#41608) 2026-09-17 13:59:58 -07:00
FetoiuCatalinandCatalin-Emil Fetoiu 8adf7b61de In mirrored mode, handle route update as add instead of replace (#41391)
In mirrored mode, handle route update as add instead of replace
Remove usage of route update as it can overwrite routes on other interfaces. add tests that verify host routing changes are correctly reflected in Linux

---------

Co-authored-by: Catalin-Emil Fetoiu <cfetoiu@microsoft.com>
2026-09-17 13:59:18 -07:00
Blue 08df631ad3 Explicitely return SOCKET from WSLCPluginAPI_ProcessGetFd() (#41626) 2026-09-17 10:29:17 -07:00
ggarzia-MSFTandCopilot efa05848ba wslc: add --digests to image list for docker parity (#41457)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-09-16 21:36:12 -07:00
Feng Wang a2ff822c9b Fix redirect stdout and stderror to the same file overlapping (#41611)
Currently the stdout and stderr relay tracks the output offset separately. And when redirected to the same file, the writes could overlap.

This PR uses the append mode for overlap io writes instead of the separate offsets in the relay. So, the file write offset is correctly tracked by the system.
2026-09-17 10:15:09 +08:00
Feng Wang 1db5af439b Change default relay buffer size to 64KiB (#41603)
The current logic uses a fixed 4KiB buffer for stdio relay on the Windows side. And uses an initial 4KiB buffer for stdio relay on the Linux side, which grows only if the message won't fit. This can severely limit the relay performance in some situations. For example, in #41572, when redirecting stdout to a SMB share.

This PR increases thedefault relay buffer size to 64KiB. Which shows significant performance improvements according to buffer size tests.
2026-09-17 10:14:35 +08:00
David Bennett bf9b8aaaf6 CLI: Global option scopes for nested commands (related to compose support) (#41546) 2026-09-16 15:48:12 -07:00
Leo Camus e7488375e3 Warn on an escaped CR in wsl.conf instead of dropping it silently (#41591)
`case '\r': break;` made a backslash before a CR the only unrecognised
escape the parser accepts without a diagnostic. In a CRLF file that left
the value truncated at the backslash and the remainder parsed as its own
line, with nothing reported.

Letting it fall into the default case gives the same
MessageConfigInvalidEscape warning as any other bad escape. As with those,
the line is then discarded rather than kept truncated.
2026-09-15 11:12:13 -07:00
ggarzia-MSFTandCopilot 54fba960f9 wslc: keep image list json CreatedSince locale-invariant (#41609)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-09-15 01:45:22 +00:00
Craig Loewen 2678a87f13 Added WSL container to OOBE (#41402) 2026-09-14 23:29:16 +00:00
ggarzia-MSFTandCopilot 0b0a1435a8 wslc: add --all-tags to pull for docker parity (#41494)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-09-14 22:47:07 +00:00
Blue d6977e2d85 Don't stop parsing linux config files on invalid lines (#41606) 2026-09-14 13:48:44 -07:00
Anton Kesy 0117aeef9a Fix typos (#41589) 2026-09-14 11:19:17 -07:00
e53598d74f Enable RedirectionGuard process mitigation (#41542)
Co-authored-by: Ben Hillis <benhill@ntdev.microsoft.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-09-14 10:22:10 -07:00
Feng Wang bc5abef10c Fix activating a stopping service treated as OOM (#41460)
The current factory function for LxssUserSession and WSLCSessionManager translates the error code CO_E_SERVER_STOPPING to S_FALSE. Which combined with *ppCreated == NULL causes COM to treat this as an OOM. Leading to error messages like this when activating a stopping service:

Not enough memory resources are available to complete this operation.
Error code: Wsl/E_OUTOFMEMORY
This PR removes this conversion. So, COM actually retries when the service is stopping. And returns CO_E_SERVER_EXEC_FAILURE if the retry times out.
2026-09-14 13:55:48 +08:00
d770badc00 Tear down the stale plugin Plan9 server before recreating it (#41565)
When the per-user plugin Plan9 server is no longer running, the previous instance was dropped without a Teardown call, so it could still hold the Plan9 port when the replacement tries to bind it.

Co-authored-by: Ben Hillis <benhill@ntdev.microsoft.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 0d028ad4-fe5e-4ef1-9832-18ee0e4825cc
2026-09-11 15:40:06 -07:00
ggarzia-MSFTandCopilot d677589d90 wslc: add docker --quiet to image load, image push and container cp (#41466)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-09-11 14:58:22 -07:00
David Bennett 5b51c1707f CLI: Add global options to root help, adjust options usage (#41534)
* Add global options to root help, adjust options usage to match CLI conventions

* Trim some unnecessary test code
2026-09-11 06:53:40 -07:00
16337836b1 Reduce distro termination log noise (#41541)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Co-authored-by: Ben Hillis <benhill@ntdev.microsoft.com>
Copilot-Session: adf24228-67c0-452e-9cc2-c698a8d7b3b7
2026-09-10 22:35:49 -07:00
6872612147 Fix WSLC fallback gateway collision (#41547)
Avoid selecting the guest IPv4 address as its synthesized default gateway when the host adapter does not expose one.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Co-authored-by: Ben Hillis <benhill@ntdev.microsoft.com>
Copilot-Session: ce168659-cb9d-4f0e-8fd1-2834d065ba9d
2026-09-10 22:34:17 -07:00
b378272103 Validate variable-length message strings (#41567)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Co-authored-by: Ben Hillis <benhill@ntdev.microsoft.com>
Copilot-Session: 3086bdaf-bc43-4fed-88d1-3a95a21fd14e
2026-09-11 00:57:51 +00:00
Flor Chacón 24774cf6cc Fix build issue for wslsettings, and add more logging to the pipelines (#40388) 2026-09-10 17:23:23 -07:00
ggarzia-MSFTandCopilot b96cd0b82d wslc: add --all-tags to push for docker parity (#41500)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-09-10 16:09:55 -07:00
ggarzia-MSFTandCopilot bd28ec29e9 wslc: add --size to container list for docker parity (#41477)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-09-10 16:07:35 -07:00
Blue 8c5e17ab6d Don't fail the installation if DeprovisionMsix() fails (#41453)
* Don't fail the installation if DeprovisionMsix() fails

* Apply PR feedback
2026-09-10 15:37:50 -07:00
8647d1edb3 wslc: add --details to container logs for docker parity (#41467)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: JohnMcPMS <johnmcp@microsoft.com>
2026-09-10 13:05:16 -07:00
ggarzia-MSFTandCopilot 42bc8b71f2 wslc: add --all to image list for docker parity (#41456)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-09-10 12:38:57 -07:00
ggarzia-MSFTandCopilot ead585256b wslc: match docker prune semantics (confirmation prompt, -f aliases --force) (#41455)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-09-10 12:36:23 -07:00
5e573a4d6a Fix virtiofs bind mounts exposing files as root-owned (#40719) (#40733)
* Fix virtiofs bind mounts exposing files as root-owned (#40719)

Add the 'metadata' option to virtiofs shares created via
HcsVirtualMachine::AddShare (the WSLC/Docker container path). Without
this option, the virtiofs device host cannot persist per-file uid/gid
in NTFS extended attributes, so all files default to uid=0/gid=0
regardless of the creating user.

This matches the behavior of the regular distro mount path
(WslCoreVm::AddVirtioFsShare) which receives metadata/uid/gid options
from the Linux init's ConvertDrvfsMountOptionsToPlan9.

Also adds a regression test (WindowsMountsVirtioFsFileOwnership) that
verifies file ownership is preserved on virtiofs mounts.

Fixes #40719

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Address code review feedback

- Add inline comment explaining why 'metadata' is required
- Use unique mount point (/virtiofs-ownership-test) to avoid test interference
- Use numeric UID (su '#65534') instead of username to avoid environment dependency

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* test: use 'nobody' user instead of numeric UID in virtiofs ownership test

The su command with numeric UID syntax ('#65534') requires the user to
exist in /etc/passwd. Use the 'nobody' account directly since it is
already available in the test VHD.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* fix: wrap long test command strings to satisfy clang-format 130-col limit

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* test: unmount inline with VERIFY_SUCCEEDED to match file convention

Replace the scope_exit unmount cleanup with an inline VERIFY_SUCCEEDED
call at the end of the test, matching every other mount test in this
file (e.g. WindowsMountsVirtioFsShareReuse). This also asserts the
unmount HRESULT rather than silently swallowing it.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 9213b7da-c5c8-4d9c-89ab-e80048d288a2

* Fix Windows mount test API calls

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Blue <OneBlue@users.noreply.github.com>
Copilot-Session: 9213b7da-c5c8-4d9c-89ab-e80048d288a2
2026-09-10 11:58:43 -07:00
de2586290f Host plugin Plan9 shares as the session user (#41548)
* Host plugin Plan9 shares as the session user

Use a dedicated per-user Plan9 server for plugin folder mounts so host filesystem permissions are preserved without relying on HCS-managed share identity.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: c20b1da0-c613-489d-92a3-9c27527c0c54

* Simplify plugin Plan9 port plumbing

Use the fixed plugin port directly in mini_init and mirror the existing per-user Plan9 server lifecycle.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: c20b1da0-c613-489d-92a3-9c27527c0c54

* Recreate stopped plugin Plan9 servers

Recreate the per-user server before adding a share when its process is no longer running.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: c20b1da0-c613-489d-92a3-9c27527c0c54

---------

Co-authored-by: Ben Hillis <benhill@ntdev.microsoft.com>
Copilot-Session: c20b1da0-c613-489d-92a3-9c27527c0c54
2026-09-10 10:28:10 -07:00
DesertRatUa 03f6b0e5dd init: fix dhcpcd option name in bridged-mode config (#41538)
* init: fix dhcpcd option name in bridged-mode config

dhcpcd has no option named "broadcast"; option 28 is "broadcast_address".
dhcpcd 10 rejects the whole "option" line, so DNS servers, domain, search
list, hostname and MTU were never requested from the DHCP server, leaving
/mnt/wsl/resolv.conf without nameservers on servers that honour the PRL.

* init: apply clang-format to dhcpcd config string

The longer broadcast_address option name pushed the literal past the
130-column limit in .clang-format. Split it as clang-format does; the
concatenated value is unchanged.
2026-09-09 17:23:40 +00:00
beena352 28d0fed363 Add wslc container restart command (#41435) 2026-09-08 14:36:17 -07:00
ggarzia-MSFTandCopilot 80d300ab0a wslc: add --size to inspect for docker parity (#41489)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-09-08 09:21:28 -07:00
Feng Wang c85de0d422 Fix WSLC Plan9 mount and image-build failures (#41535)
* Fix WSLC Plan9 mounts using a per-user server

* remove debug code
2026-09-08 07:52:01 -07:00
Feng Wang 74c6ac9abb Fix p9 drvfs read only mount regression (#41487)
#41129 introduces a regression where the ";ro" option is passed to the host for p9 shares. However, that option is not supported by the p9 server and causes the mount to fail.

This PR removes the special handling of "ro" in the common parser. And use MountParseFlags to add the required virtio option.
2026-09-07 10:41:29 +08:00
beena352 556440f392 Add container restart runtime support (#41454) 2026-09-04 08:16:40 -07:00