xcl run: confine manifest/config exe paths to game root and preserve CreateProcessW error #1586

Open
github-bot wants to merge 1 commit from github-bot/gh-1586 into main AGit
Owner

@⁠b3IKK on GitHub · 2026-11-24 17:59 UTC · original
b3IKK:launcher/path-containment-and-lasterror → main · +73 −5 · 1 files · 1 commits · open

Fixes two bugs in crates/xcl/src/launcher.rs:

  • pick_exe() and run() joined MicrosoftGame.config <Executable Name=...> and xcl.toml exe directly onto root via Path::join. In Rust, Path::join replaces root for absolute/drive-rooted paths and allows .. parent traversal, allowing a manifest or config entry to escape the game directory and launch an arbitrary executable.
  • spawn_host() called std::env::remove_var("XCL_HOST") before GetLastError(), which can overwrite the thread's Win32 last error before reporting why CreateProcessW failed.

This adds exe_inside_root() to reject absolute/parent components and verify canonical containment inside root (with a comment noting the check-at-pick-time TOCTOU posture), and captures GetLastError() immediately after CreateProcessW fails before calling remove_var.

What is in it

  • crates/xcl/src/launcher.rs: add exe_inside_root() and use it in pick_exe() and run(); capture GetLastError() before remove_var("XCL_HOST") in spawn_host(); add unit tests pick_exe_rejects_paths_outside_game_root (including lowercase drive-letter canonicalization) and spawn_host_preserves_create_process_last_error.

Tested

  • hardware (GPU + driver, CPU), Windows build, Rust version, debug / release: NVIDIA GeForce RTX 5080 (driver 32.0.16.1088), AMD Ryzen 9 9950X3D, Windows 11 10.0.26300, Rust 1.100.0 (stable-x86_64-pc-windows-msvc), DXC 1.9.2609.5, debug (scripts/test.ps1) and release (scripts/smoke.ps1)
  • .\scripts\test.ps1 (cargo build --workspace + cargo test --workspace -- --test-threads=4): 778 passed, 0 failed, 41 ignored (SKIPPED GPU tests: 2 no wave64 — gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask, gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware; 1 no heap windows — heap_window_out_of_memory_falls_back_to_the_switch_form)
  • cargo test -p xcl --lib launcher::tests: 14 passed, 0 failed

Regression run

main:

xcl-smoke v1
commit: 47efa2ecea0a12934719ae69b81930cf02a4b1c3
gpu: NVIDIA GeForce RTX 5080
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1226 (PresentX 1226)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15341 MB

PR:

xcl-smoke v1
commit: 56c15c7501600e1f5ca9f9a776aba4656d6248f0
gpu: NVIDIA GeForce RTX 5080
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1646 (PresentX 1646)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14596 MB

Not tested

  • AMD GPUs and native wave64 hardware
  • other titles (Minecraft Preview, Unicorn Overlord, Fortnite, XDefiant) and Linux / Wine

AI use

  • OpenCode, Gemini 4 Neon: audited launcher.rs, wrote the fixes and unit tests, added the TOCTOU posture comment and lowercase drive-letter test per review feedback, ran the test suite and scripts/smoke.ps1 regression runs, and drafted this PR description.
**@⁠b3IKK** on GitHub · 2026-11-24 17:59 UTC · [original](https://github.com/xcl-dev/xcl/pull/1586) `b3IKK:launcher/path-containment-and-lasterror` → `main` · +73 −5 · 1 files · 1 commits · open Fixes two bugs in `crates/xcl/src/launcher.rs`: - `pick_exe()` and `run()` joined `MicrosoftGame.config` `<Executable Name=...>` and `xcl.toml` `exe` directly onto `root` via `Path::join`. In Rust, `Path::join` replaces `root` for absolute/drive-rooted paths and allows `..` parent traversal, allowing a manifest or config entry to escape the game directory and launch an arbitrary executable. - `spawn_host()` called `std::env::remove_var("XCL_HOST")` before `GetLastError()`, which can overwrite the thread's Win32 last error before reporting why `CreateProcessW` failed. This adds `exe_inside_root()` to reject absolute/parent components and verify canonical containment inside `root` (with a comment noting the check-at-pick-time TOCTOU posture), and captures `GetLastError()` immediately after `CreateProcessW` fails before calling `remove_var`. **What is in it** - `crates/xcl/src/launcher.rs`: add `exe_inside_root()` and use it in `pick_exe()` and `run()`; capture `GetLastError()` before `remove_var("XCL_HOST")` in `spawn_host()`; add unit tests `pick_exe_rejects_paths_outside_game_root` (including lowercase drive-letter canonicalization) and `spawn_host_preserves_create_process_last_error`. **Tested** - hardware (GPU + driver, CPU), Windows build, Rust version, debug / release: NVIDIA GeForce RTX 5080 (driver 32.0.16.1088), AMD Ryzen 9 9950X3D, Windows 11 10.0.26300, Rust 1.100.0 (`stable-x86_64-pc-windows-msvc`), DXC 1.9.2609.5, debug (`scripts/test.ps1`) and release (`scripts/smoke.ps1`) - `.\scripts\test.ps1` (`cargo build --workspace` + `cargo test --workspace -- --test-threads=4`): 778 passed, 0 failed, 41 ignored (SKIPPED GPU tests: 2 `no wave64` — `gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask`, `gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware`; 1 `no heap windows` — `heap_window_out_of_memory_falls_back_to_the_switch_form`) - `cargo test -p xcl --lib launcher::tests`: 14 passed, 0 failed **Regression run** main: ``` xcl-smoke v1 commit: 47efa2ecea0a12934719ae69b81930cf02a4b1c3 gpu: NVIDIA GeForce RTX 5080 title: 9cc6a39e seconds: 60 exit: 0x0 frames shown: 1226 (PresentX 1226) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 15341 MB ``` PR: ``` xcl-smoke v1 commit: 56c15c7501600e1f5ca9f9a776aba4656d6248f0 gpu: NVIDIA GeForce RTX 5080 title: 9cc6a39e seconds: 60 exit: 0x0 frames shown: 1646 (PresentX 1646) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14596 MB ``` **Not tested** - AMD GPUs and native wave64 hardware - other titles (Minecraft Preview, Unicorn Overlord, Fortnite, XDefiant) and Linux / Wine **AI use** - OpenCode, Gemini 4 Neon: audited `launcher.rs`, wrote the fixes and unit tests, added the TOCTOU posture comment and lowercase drive-letter test per review feedback, ran the test suite and `scripts/smoke.ps1` regression runs, and drafted this PR description.
In launcher.rs:
- pick_exe() and run() joined MicrosoftGame.config `<Executable Name=...>`
  and `xcl.toml` `exe` directly onto `root` via `Path::join`. In Rust,
  `Path::join` replaces `root` for absolute/drive-rooted paths and allows
  `..` parent traversal, letting a manifest or config escape the game
  folder and execute an arbitrary `.exe`.
- spawn_host() called `std::env::remove_var("XCL_HOST")` before reading
  `GetLastError()`, which can overwrite the thread's Win32 error code
  before reporting why `CreateProcessW` failed.

Add exe_inside_root() to reject absolute/parent components and verify
canonical containment inside `root`, and capture `GetLastError()`
immediately after `CreateProcessW` before `remove_var`.

Assisted-by: OpenCode (Gemini 4 Neon)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:58:23 +00:00
Author
Owner

@⁠pickles976 on GitHub · 2026-11-24 18:03 UTC · original

Review + audit cross-link: this is exactly the class my leonida-surge audit note (#963, mirrored to our surge) said the post-handover merge wave needed watching for — glad to see it found and closed by the community; my own build/dep/script sweep did not cover launcher path handling, so consider this line a receipt that the audit lens has gaps without this kind of PR. Verdict: approach is right — canonicalize-then-starts_with blocks absolute injection, .., and junction/symlink escapes in one move, because canonicalize resolves reparse points before the prefix compare (the same "skip reparse before any metadata" invariant my #1249 cross-check cited on the quota walk). Two small notes: ① residual TOCTOU window — a junction planted between the check and CreateProcess would still escape; closing it fully means either re-checking immediately pre-exec (narrows the race to negligible, cheap) or opening the exe via a handle and executing by image (INFO_...-style, out of scope); worth one code comment stating which posture was taken, so future readers do not mistake canonicalize-as-you-go for check-at-exec. ② Path::starts_with is component-wise byte comparison — after canonicalization both sides are \\?\-normalized with consistent casing, so the usual Windows prefix-compare traps (case, \\.\) do not bite here; a one-line test pinning that assumption (lowercase drive letter input) would keep a future refactor from reintroducing it.

**@⁠pickles976** on GitHub · 2026-11-24 18:03 UTC · [original](https://github.com/xcl-dev/xcl/pull/1586#issuecomment-7140084555) Review + audit cross-link: this is exactly the class my leonida-surge audit note (#963, mirrored to our surge) said the post-handover merge wave needed watching for — glad to see it found and closed by the community; my own build/dep/script sweep did not cover launcher path handling, so consider this line a receipt that the audit lens has gaps without this kind of PR. Verdict: approach is right — canonicalize-then-`starts_with` blocks absolute injection, `..`, **and** junction/symlink escapes in one move, because `canonicalize` resolves reparse points before the prefix compare (the same "skip reparse before any metadata" invariant my #1249 cross-check cited on the quota walk). Two small notes: ① residual TOCTOU window — a junction planted **between** the check and `CreateProcess` would still escape; closing it fully means either re-checking immediately pre-exec (narrows the race to negligible, cheap) or opening the exe via a handle and executing by image (`INFO_...`-style, out of scope); worth one code comment stating which posture was taken, so future readers do not mistake canonicalize-as-you-go for check-at-exec. ② `Path::starts_with` is component-wise byte comparison — after canonicalization both sides are `\\?\`-normalized with consistent casing, so the usual Windows prefix-compare traps (case, `\\.\`) do not bite here; a one-line test pinning that assumption (lowercase drive letter input) would keep a future refactor from reintroducing it.
Author
Owner

@⁠b3IKK on GitHub · 2026-11-24 18:47 UTC · original

Thanks @⁠pickles976 — added both in \56c15c7: a short comment on \exe_inside_root\ noting the check-at-pick-time TOCTOU posture, and a lowercase drive-letter root assertion in \pick_exe_rejects_paths_outside_game_root\ pinning canonical prefix comparison. Re-ran \scripts/test.ps1\ and the 60 s \scripts/smoke.ps1\ run.

**@⁠b3IKK** on GitHub · 2026-11-24 18:47 UTC · [original](https://github.com/xcl-dev/xcl/pull/1586#issuecomment-7141153713) Thanks @⁠pickles976 — added both in \56c15c7\: a short comment on \exe_inside_root\ noting the check-at-pick-time TOCTOU posture, and a lowercase drive-letter root assertion in \pick_exe_rejects_paths_outside_game_root\ pinning canonical prefix comparison. Re-ran \scripts/test.ps1\ and the 60 s \scripts/smoke.ps1\ run.
Author
Owner

@⁠futurepro62 on GitHub · 2026-11-24 18:55 UTC · original

Full-suite run, since this PR has no test report yet. Tested exact head 56c15c7 (on its base 9e3831e).

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 616.64, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.100.0 MSVC, DXC + dxil.dll 1.9.2602.17 (Windows SDK 10.0.26100), debug, D3D12 debug layer installed.
  • cargo build --workspace, then XCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4 --skip heap_window_out_of_memory_falls_back_to_the_switch_form: 777 passed, 0 failed, 41 ignored. SKIPPED (no wave64): gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware.
  • The new tests ran and passed: pick_exe_rejects_paths_outside_game_root, spawn_host_preserves_create_process_last_error.
  • The previous head 98eb22c (the PR was updated before the NVIDIA run above) on the AMD Radeon integrated GPU (iGPU) of the Ryzen 7 9800X3D (RDNA2, XCL_ADAPTER=radeon), cargo test --workspace -- --test-threads=4: 778 passed, 0 failed, 41 ignored. SKIPPED: heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows).
  • heap_window_out_of_memory_falls_back_to_the_switch_form was skipped with --skip. It fails on main 9e3831e too, not because of this PR: under XCL_REQUIRE_GPU=mesh, runner::skip_test turns every skip except "no wave64" into a failure, including this test's opt-in "no heap windows" skip (XCL_HEAP_WINDOWS unset). Reported as #1651.

Not tested

  • a release build, a game (test run only).

AI use

  • Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
**@⁠futurepro62** on GitHub · 2026-11-24 18:55 UTC · [original](https://github.com/xcl-dev/xcl/pull/1586#issuecomment-7141344864) Full-suite run, since this PR has no test report yet. Tested exact head `56c15c7` (on its base `9e3831e`). **Tested** - NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 616.64, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.100.0 MSVC, DXC + dxil.dll 1.9.2602.17 (Windows SDK 10.0.26100), debug, D3D12 debug layer installed. - `cargo build --workspace`, then `XCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4 --skip heap_window_out_of_memory_falls_back_to_the_switch_form`: **777 passed, 0 failed, 41 ignored**. SKIPPED (no wave64): `gpu_geometry_wave32_prefix_count_over_a_mask`, `gpu_wave32_program_in_wave64_hardware`. - The new tests ran and passed: `pick_exe_rejects_paths_outside_game_root`, `spawn_host_preserves_create_process_last_error`. - The previous head `98eb22c` (the PR was updated before the NVIDIA run above) on the AMD Radeon integrated GPU (iGPU) of the Ryzen 7 9800X3D (RDNA2, `XCL_ADAPTER=radeon`), `cargo test --workspace -- --test-threads=4`: **778 passed, 0 failed, 41 ignored**. SKIPPED: `heap_window_out_of_memory_falls_back_to_the_switch_form` (no heap windows). - `heap_window_out_of_memory_falls_back_to_the_switch_form` was skipped with `--skip`. It fails on main `9e3831e` too, not because of this PR: under `XCL_REQUIRE_GPU=mesh`, `runner::skip_test` turns every skip except "no wave64" into a failure, including this test's opt-in "no heap windows" skip (`XCL_HEAP_WINDOWS` unset). Reported as #1651. **Not tested** - a release build, a game (test run only). **AI use** - Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-24 20:02 UTC · original

Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

  • cargo test -p xcl --lib: all passed, 0 failed, ~22 ignored. (Intermittent single-test flake under parallel scheduling; clean on single-threaded rerun — same flake seen on unmodified main.)

Thanks!

**@⁠DavidM1911** on GitHub · 2026-11-24 20:02 UTC · [original](https://github.com/xcl-dev/xcl/pull/1586#issuecomment-7142967535) Verification on RTX 3060 Ti (Windows 11), branch merged with current `main`: - `cargo test -p xcl --lib`: all passed, 0 failed, ~22 ignored. (Intermittent single-test flake under parallel scheduling; clean on single-threaded rerun — same flake seen on unmodified `main`.) Thanks!
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1586/head:github-bot/gh-1586'
git switch 'github-bot/gh-1586'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1586'
git switch 'github-bot/gh-1586'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1586'
git switch 'github-bot/gh-1586'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1586'
git switch 'main'
git merge --squash 'github-bot/gh-1586'
git switch 'main'
git merge --ff-only 'github-bot/gh-1586'
git switch 'main'
git merge 'github-bot/gh-1586'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.