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

Open
b3IKK wants to merge 1 commit from upstream-pr/1586 into main
b3IKK commented 2026-11-24 17:59:25 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by b3IKK on 2026-11-24T17:59:25Z.


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.
<!-- greyfinch-sync:ivall/xcl:issue:5477566326 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1586). Originally posted by [b3IKK](https://github.com/b3IKK) on 2026-11-24T17:59:25Z. --- 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.
pickles976 commented 2026-11-24 18:09:18 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by pickles976 on 2026-11-24T18:03:03Z.


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.

<!-- greyfinch-sync:ivall/xcl:comment:7140084555 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1586#issuecomment-7140084555). Originally posted by [pickles976](https://github.com/pickles976) on 2026-11-24T18:03:03Z. --- 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.
b3IKK commented 2026-11-24 19:07:36 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by b3IKK on 2026-11-24T18:47:22Z.


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.

<!-- greyfinch-sync:ivall/xcl:comment:7141153713 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1586#issuecomment-7141153713). Originally posted by [b3IKK](https://github.com/b3IKK) on 2026-11-24T18:47:22Z. --- 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.
futurepro62 commented 2026-11-24 19:07:49 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by futurepro62 on 2026-11-24T18:55:34Z.


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.
<!-- greyfinch-sync:ivall/xcl:comment:7141344864 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1586#issuecomment-7141344864). Originally posted by [futurepro62](https://github.com/futurepro62) on 2026-11-24T18:55:34Z. --- 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.
DavidM1911 commented 2026-11-24 21:09:14 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-24T20:02:55Z.


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!

<!-- greyfinch-sync:ivall/xcl:comment:7142967535 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1586#issuecomment-7142967535). Originally posted by [DavidM1911](https://github.com/DavidM1911) on 2026-11-24T20:02:55Z. --- 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!
github-actions[bot] commented 2026-11-27 21:26:43 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by github-actions[bot] on 2026-11-27T21:26:43Z.


Nothing has happened on this PR for 3 days, so it is marked stale and will be closed in 4 days. A push or a comment takes the mark off: rebase it onto main if it conflicts, and say in one line what it still fixes. If it only waits for a maintainer, a comment saying so is enough.

<!-- greyfinch-sync:ivall/xcl:comment:7228449864 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1586#issuecomment-7228449864). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-11-27T21:26:43Z. --- Nothing has happened on this PR for 3 days, so it is marked `stale` and will be closed in 4 days. A push or a comment takes the mark off: rebase it onto `main` if it conflicts, and say in one line what it still fixes. If it only waits for a maintainer, a comment saying so is enough.
Foniass commented 2026-12-01 06:11:42 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T06:11:42Z.


Triage (#1607) – head 56c15c7

The CreateProcessW half is already on main: spawn_host reads GetLastError() before the remove_var calls since defe7ef1, which is also why this PR conflicts. On rebase, drop that hunk; spawn_host_preserves_create_process_last_error may still be useful as a regression test against main's signature.
The exe_inside_root part (launcher.rs pick_exe / run) is not on main and no open PR does it. Note that canonicalizing also rejects an exe reached through a junction or symlink inside the game folder that points elsewhere (e.g. a package split across drives); such setups would now fall back to the folder scan.
Recommendation: keep open.

AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.

<!-- greyfinch-sync:ivall/xcl:comment:7302595363 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1586#issuecomment-7302595363). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T06:11:42Z. --- **Triage (#1607)** – head 56c15c7 The CreateProcessW half is already on main: `spawn_host` reads `GetLastError()` before the `remove_var` calls since defe7ef1, which is also why this PR conflicts. On rebase, drop that hunk; `spawn_host_preserves_create_process_last_error` may still be useful as a regression test against main's signature. The `exe_inside_root` part (launcher.rs `pick_exe` / `run`) is not on main and no open PR does it. Note that canonicalizing also rejects an exe reached through a junction or symlink inside the game folder that points elsewhere (e.g. a package split across drives); such setups would now fall back to the folder scan. Recommendation: keep open. AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/1586:upstream-pr/1586'
git switch 'upstream-pr/1586'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/1586'
git switch 'upstream-pr/1586'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/1586'
git switch 'upstream-pr/1586'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/1586'
git switch 'main'
git merge --squash 'upstream-pr/1586'
git switch 'main'
git merge --ff-only 'upstream-pr/1586'
git switch 'main'
git merge 'upstream-pr/1586'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
xcl-dev/xcl!1576
No description provided.