`wslc system session terminate` claims to accept a session name, but only supports terminating the default session
- Dominant language
- C++
- Stars
- 33.7k
- Forks
- 1.8k
- Avg merge
- 3d 17h
- Merged PRs (30d)
- 116
Description
### Windows Version
Microsoft Windows [Version 10.0.26200.8973]
### WSL Version
2.9.4.0
### Are you using WSL 1 or WSL 2?
- [x] WSL 2
- [ ] WSL 1
### Kernel Version
6.18.35.2-1
### Distro Version
_No response_
### Other Software
_No response_
### Repro Steps
1. Create a defaultly-named session by running a container with WSLC under your own account. E.g.:
```cmd
C:\Windows\System32>wslc run --rm hello-world
Hello from Docker!
[...]
```
2. Create a second defaultly-named session by running a container under your own account, but elevated
3. Run `wslc system session list` (and see in Task Manager). You now have two session VMs: `wslc-cli-User` and `wslc-cli-admin-User`.
Due to being lightweight Hyper-V VMs, your only way of terminating them is with `wslc system session terminate`.
4. Run `wslc system session terminate --help`
5. Notice the command help specifies it can accept a session name in the description, but the command format does not mention it:
```cmd
Copyright (c) Microsoft Corporation. All rights reserved.
For privacy information about this product please visit https://aka.ms/privacy.
Terminates an active session. If no session is specified, the default session will be terminated.
Usage: wslc system session terminate []
The following options are available:
-?,--help Shows help about the selected command
```
6. Attempt to specify a session name (or ID) anyway. Notice it complains about a positional argument that was not expected:
```cmd
C:\Windows\System32>wslc system session list
ID Creator PID Display Name
1 1234 wslc-cli-User
2 5678 wslc-cli-admin-User
C:\Windows\System32>wslc system session terminate 2
Copyright (c) Microsoft Corporation. All rights reserved.
For privacy information about this product please visit https://aka.ms/privacy.
Found a positional argument when none was expected: '2'
[...help text follows...]
C:\Windows\System32>wslc system session terminate wslc-cli-User
Copyright (c) Microsoft Corporation. All rights reserved.
For privacy information about this product please visit https://aka.ms/privacy.
Found a positional argument when none was expected: 'wslc-cli-User'
[...help text follows...]
```
7. Running an unspecified terminate command works, but of course only terminates the session owned by the current user **and integrity level:**
```cmd
C:\Windows\System32>wslc system session terminate
C:\Windows\System32>wslc system session list
ID Creator PID Display Name
1 1234 wslc-cli-User
```
8. Running `[...]terminate` a second time fails as the session does not exist anymore:
```cmd
C:\Windows\System32>wslc system session terminate
Session not found: 'wslc-cli-admin-User'
Error code: WSLC_E_SESSION_NOT_FOUND
```
**The end result is:** If you started several sessions across user accounts _and integrity levels,_ those sessions can only be terminated by the users (and integrity levels) who started them.
### Expected Behavior
`wslc system session terminate` should accept a session name (or ID if the ordering of `wslc system session list` is consistent across calls and can be trusted), and allow a user at or above trust level to terminate another session. I.e.: a non-elevated user account would be able to terminate their own non-elevated session, while an elevated user account would be able to terminate all other users' elevated and non-elevated sessions.
If not, the command description should be amended.
**However,** in that case, due to Hyper-V lightweight VMs being unmanageable with regular tools, a user can end up with essentially "leaked" VMs if they don't know about the sessions' user + integrity distinction.
### Actual Behavior
`wslc system session terminate` does not accept any other option than `--help`/`-?`, and can only terminate the default session.
See repro steps for full console output of this & related commands.
### Diagnostic Logs
_No response_
Contributor guide
Assessment
This issue has not been assessed yet.