xcl run: guard null RIP in code_at and bounds-check GS hook target #1336

Open
b3IKK wants to merge 1 commit from upstream-pr/1346 into main
b3IKK commented 2026-11-24 15:03:49 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by b3IKK on 2026-11-24T15:03:49Z.


Three safety and bounds bugs in crates/xcl/src/eh.rs:

  • code_at(rip) called std::slice::from_raw_parts(rip as *const u8, 0) when readable() returned false (including rip == 0), which is UB for a null pointer even with length 0. It now returns an empty String when n == 0.
  • find_gs_check used an exclusive range 0..code.len() - p.len() - 4, missing a pattern whose 4-byte rel32 ends at the last byte of code.
  • hook_gs_failure patched 12 bytes at the decoded E9 rel32 target without checking whether [target, target + 12) stays within the supplied [at, at + len) section (or overflows).

What is in it

  • crates/xcl/src/eh.rs: return early on n == 0 in code_at, make the scan range inclusive in find_gs_check, bounds-check [target, target + 12) inside [at, at + len) in hook_gs_failure, and add unit tests find_gs_check_matches_at_exact_end_of_buffer, hook_gs_failure_ignores_target_outside_section, and code_at_handles_null_rip_without_ub (verified failing before the fix).

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): 754 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)
  • cargo test -p xcl --lib find_gs_check_matches_at_exact_end_of_buffer, hook_gs_failure_ignores_target_outside_section, code_at_handles_null_rip_without_ub: all pass (verified failing before the fix)

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: e661e29383cc4207b9c4f4137d3a137aa020c0ea
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: 14604 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 eh.rs, wrote the fixes and unit tests, ran the test suite and scripts/smoke.ps1 regression runs, and drafted this PR description.
<!-- greyfinch-sync:ivall/xcl:issue:5474715837 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1346). Originally posted by [b3IKK](https://github.com/b3IKK) on 2026-11-24T15:03:49Z. --- Three safety and bounds bugs in `crates/xcl/src/eh.rs`: - `code_at(rip)` called `std::slice::from_raw_parts(rip as *const u8, 0)` when `readable()` returned `false` (including `rip == 0`), which is UB for a null pointer even with length 0. It now returns an empty `String` when `n == 0`. - `find_gs_check` used an exclusive range `0..code.len() - p.len() - 4`, missing a pattern whose 4-byte `rel32` ends at the last byte of `code`. - `hook_gs_failure` patched 12 bytes at the decoded `E9 rel32` target without checking whether `[target, target + 12)` stays within the supplied `[at, at + len)` section (or overflows). **What is in it** - `crates/xcl/src/eh.rs`: return early on `n == 0` in `code_at`, make the scan range inclusive in `find_gs_check`, bounds-check `[target, target + 12)` inside `[at, at + len)` in `hook_gs_failure`, and add unit tests `find_gs_check_matches_at_exact_end_of_buffer`, `hook_gs_failure_ignores_target_outside_section`, and `code_at_handles_null_rip_without_ub` (verified failing before the fix). **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`): 754 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`) - `cargo test -p xcl --lib find_gs_check_matches_at_exact_end_of_buffer`, `hook_gs_failure_ignores_target_outside_section`, `code_at_handles_null_rip_without_ub`: all pass (verified failing before the fix) **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: e661e29383cc4207b9c4f4137d3a137aa020c0ea 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: 14604 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 `eh.rs`, wrote the fixes and unit tests, ran the test suite and `scripts/smoke.ps1` regression runs, and drafted this PR description.
futurepro62 commented 2026-11-24 16:07:00 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by futurepro62 on 2026-11-24T15:17:52Z.


Full-suite run, since this PR has no test report yet. Tested exact head e661e29 (on its base 930e8b4).

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, debug, D3D12 debug layer installed.
  • cargo build --workspace, then XCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4: 754 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: find_gs_check_matches_at_exact_end_of_buffer, hook_gs_failure_ignores_target_outside_section, code_at_handles_null_rip_without_ub.

Not tested

  • AMD, 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:7135787636 --> Imported from [ivall/xcl](https://github.com/ivall/xcl/pull/1346#issuecomment-7135787636). Originally posted by [futurepro62](https://github.com/futurepro62) on 2026-11-24T15:17:52Z. --- Full-suite run, since this PR has no test report yet. Tested exact head `e661e29` (on its base `930e8b4`). **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, debug, D3D12 debug layer installed. - `cargo build --workspace`, then `XCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4`: **754 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: `find_gs_check_matches_at_exact_end_of_buffer`, `hook_gs_failure_ignores_target_outside_section`, `code_at_handles_null_rip_without_ub`. **Not tested** - AMD, 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 17:06:21 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-24T16:17:54Z.


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

  • cargo test -p xcl --lib: all passed, 0 failed, ~21 ignored. (One run showed a single flaky failure / 0xc0000005 abort under parallel scheduling; clean on single-threaded rerun — same flake seen on unmodified main.)

Thanks!

<!-- greyfinch-sync:ivall/xcl:comment:7137434239 --> Imported from [ivall/xcl](https://github.com/ivall/xcl/pull/1346#issuecomment-7137434239). Originally posted by [DavidM1911](https://github.com/DavidM1911) on 2026-11-24T16:17:54Z. --- Verification on RTX 3060 Ti (Windows 11), branch merged with current `main`: - `cargo test -p xcl --lib`: all passed, 0 failed, ~21 ignored. (One run showed a single flaky failure / 0xc0000005 abort under parallel scheduling; clean on single-threaded rerun — same flake seen on unmodified `main`.) Thanks!
S1m0ne1997 commented 2026-11-25 15:08:02 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by S1m0ne1997 on 2026-11-25T14:53:09Z.


Test report for e661e29383cc4207b9c4f4137d3a137aa020c0ea (this PR's head), for #1607.

Tested

  • NVIDIA GeForce RTX 4090 24 GB (driver 621.40), AMD Ryzen 9 9950X3D, 47 GB RAM, Windows 11 Home 10.0.26300, rustc 1.100.0 (0ef1bc386 2026-11-09) x86_64-pc-windows-msvc, debug.
  • cargo build --workspace, then cargo test --workspace -- --test-threads=4 at the head: 754 passed, 0 failed, 41 ignored.
  • SKIPPED (2): gpu_geometry_wave32_prefix_count_over_a_mask (no wave64), gpu_wave32_program_in_wave64_hardware (no wave64).

Regression run (retail title, scripts/smoke.ps1 -Seconds 60, release; main built from the commit in its block, this PR from its head with no changes to crates/, both run with the scripts/smoke.ps1 of main, which hashes the name of the game folder)

main:

xcl-smoke v1
commit: 06c9f5505f63f10c5ec49ef932d75b2c28177324
gpu: NVIDIA GeForce RTX 4090
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1599 (PresentX 1599)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 16384 MB

this PR:

xcl-smoke v1
commit: e661e29383cc4207b9c4f4137d3a137aa020c0ea
gpu: NVIDIA GeForce RTX 4090
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1636 (PresentX 1636)
presents per 2 s (last 3): 60 60 59
device removals: 0
crashes: 0
peak commit: 16971 MB

Not tested

  • AMD, other NVIDIA cards and drivers, Linux. I did not review the diff; this report is the build, the suite and the regression run only.

AI use: Claude Code with Claude Opus 5.5 ran the build, the suite and the regression run and wrote this report at my request.

<!-- greyfinch-sync:ivall/xcl:comment:7165967625 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1346#issuecomment-7165967625). Originally posted by [S1m0ne1997](https://github.com/S1m0ne1997) on 2026-11-25T14:53:09Z. --- Test report for `e661e29383cc4207b9c4f4137d3a137aa020c0ea` (this PR's head), for #1607. **Tested** - NVIDIA GeForce RTX 4090 24 GB (driver 621.40), AMD Ryzen 9 9950X3D, 47 GB RAM, Windows 11 Home 10.0.26300, `rustc 1.100.0 (0ef1bc386 2026-11-09)` `x86_64-pc-windows-msvc`, debug. - `cargo build --workspace`, then `cargo test --workspace -- --test-threads=4` at the head: **754 passed, 0 failed, 41 ignored**. - SKIPPED (2): `gpu_geometry_wave32_prefix_count_over_a_mask` (no wave64), `gpu_wave32_program_in_wave64_hardware` (no wave64). **Regression run** (retail title, `scripts/smoke.ps1 -Seconds 60`, release; `main` built from the commit in its block, this PR from its head with no changes to `crates/`, both run with the `scripts/smoke.ps1` of `main`, which hashes the name of the game folder) main: ``` xcl-smoke v1 commit: 06c9f5505f63f10c5ec49ef932d75b2c28177324 gpu: NVIDIA GeForce RTX 4090 title: 9cc6a39e seconds: 60 exit: 0x0 frames shown: 1599 (PresentX 1599) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 16384 MB ``` this PR: ``` xcl-smoke v1 commit: e661e29383cc4207b9c4f4137d3a137aa020c0ea gpu: NVIDIA GeForce RTX 4090 title: 9cc6a39e seconds: 60 exit: 0x0 frames shown: 1636 (PresentX 1636) presents per 2 s (last 3): 60 60 59 device removals: 0 crashes: 0 peak commit: 16971 MB ``` **Not tested** - AMD, other NVIDIA cards and drivers, Linux. I did not review the diff; this report is the build, the suite and the regression run only. *AI use: Claude Code with Claude Opus 5.5 ran the build, the suite and the regression run and wrote this report at my request.*
github-actions[bot] commented 2026-11-28 20:17:30 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by github-actions[bot] on 2026-11-28T20:17:30Z.


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:7245178119 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1346#issuecomment-7245178119). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-11-28T20:17:30Z. --- 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 05:29:48 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T05:29:48Z.


Triage (#1607) – head e661e29

No open or merged PR makes these changes; main still has the off-by-one range in find_gs_check, the unchecked target in hook_gs_failure and from_raw_parts(null, 0) in code_at.
hook_gs_failure now requires __report_gsfailure to be inside the same executable section as __security_check_cookie (loader.rs calls it per section); an image with the two in different code sections would silently lose the hook. Three separate fixes in one PR.
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:7301830400 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1346#issuecomment-7301830400). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T05:29:48Z. --- **Triage (#1607)** – head e661e29 No open or merged PR makes these changes; main still has the off-by-one range in `find_gs_check`, the unchecked `target` in `hook_gs_failure` and `from_raw_parts(null, 0)` in `code_at`. `hook_gs_failure` now requires `__report_gsfailure` to be inside the same executable section as `__security_check_cookie` (loader.rs calls it per section); an image with the two in different code sections would silently lose the hook. Three separate fixes in one PR. 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/1346:upstream-pr/1346'
git switch 'upstream-pr/1346'

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/1346'
git switch 'upstream-pr/1346'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/1346'
git switch 'upstream-pr/1346'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/1346'
git switch 'main'
git merge --squash 'upstream-pr/1346'
git switch 'main'
git merge --ff-only 'upstream-pr/1346'
git switch 'main'
git merge 'upstream-pr/1346'
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!1336
No description provided.