xcrdapi: fail a read whose destination is not committed instead of faulting #486

Merged
3kynox merged 1 commit from upstream-pr/486 into main 2026-11-29 16:02:14 +00:00
3kynox commented 2026-11-29 15:47:39 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by 3kynox on 2026-11-29T15:47:39Z.


Summary

A read that decodes into the title's own memory ends with a plain store. When part of that range is not committed, the store faults on the provider's worker thread and the title ends with an access violation inside xcrdapi.dll. An undecoded read into the same memory fails in ReadFile instead.

Look at the destination first. A range with a part that is not committed now fails its request with ERROR_NOACCESS through the usual failure path, and the log says how much of it could not be written, from which offset, and its state and protection. A part that is committed but protected is only logged (the first sixteen times) and the store goes ahead as before: whoever closed those pages may open them on the store, as draft #413 does.

Seen in ProjectScarlett 1.0.2.1, 12 min 40 s into an offline run: a zlib read of 0x290000 bytes to 0x8c6200000 faulted at offset 0x10000, with the stack inside xcrdapi.dll and only the first 64 KiB of the destination writable. That run was b8355fa with #389 and fc69bc2; the store is the same on main.

Not established: why the title's destination was in that state, and whether the rest of it was uncommitted or closed. The minidump holds no memory state. If it was closed rather than uncommitted, this change only logs it and the fault is still to be fixed where the pages are closed. The log line added here will say which the next time it happens.

Follows fc69bc2 (#457) in the same file. Draft #413 also changes queue.rs; the two merge without a conflict there.

Tested

Run the checks relevant to this change.

  • The checks relevant to this change passed: the xcrdapi suite and the code checks did, except one Python test of the launcher that fails the same way on main on this machine (below)
  • Changed or new behaviour is covered by a Lanes scenario, or the reason it cannot be is stated below
  • Where the table calls for AMD and NVIDIA, they passed on both. Otherwise, say which vendor still needs to run them: the table asks for any card for this provider; run on NVIDIA only.

Lanes issues no storage read into memory it has not committed, so the case is a unit test. a_read_into_a_partly_committed_destination_fails_instead_of_faulting reads a zlib stream into three 64 KiB pages of which one is committed and expects the request to fail, then commits the rest and expects the same read to land. With the check taken out, the test process ends with an access violation in that read.

GPU, driver and backend: GeForce RTX 4070 Ti SUPER, 620.73.04, Proton Experimental for the checks (Core i9-12900K, Linux 7.2.11).

Commands run and their results:

python tuxbox.py check --no-gpu
  passed   Build the shader compiler
  FAILED   Python tests: 654 ran, 1 failed, 10 skipped
           test_stage_baseline.GuestWatch.test_a_guest_that_died_stops_the_sandbox_instead_of_waiting_out_the_timeout
           AssertionError: 0 != 'guest gone'
           It fails the same way on main (d58ecf0b) without this change, four runs out of four (NixOS).
  passed   Shader compiler tests
  passed   DXBC tests
  passed   XG layout tests
  passed   Storage codec tests
  passed   D3D12 Windows typecheck

python build.py xmem && python build.py xcrdapi
python tuxbox.py verify --only xcrdapi
  PASS  xcrdapi

cargo test -p tuxbox-xcrdapi (x86_64-pc-windows-msvc, run under Wine)
  6 passed; with the check taken out, the process ends in the new test (exit code 5)

The checks ran on this commit over 090cf6c; it was then rebased onto fa1b9cf6, which changes nothing under runtime/xcrdapi.

Checks

No evidence JSON changed.

<!-- greyfinch-sync:brcly/TuxBox:issue:5552356317 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/486). Originally posted by [3kynox](https://github.com/3kynox) on 2026-11-29T15:47:39Z. --- ## Summary A read that decodes into the title's own memory ends with a plain store. When part of that range is not committed, the store faults on the provider's worker thread and the title ends with an access violation inside `xcrdapi.dll`. An undecoded read into the same memory fails in `ReadFile` instead. Look at the destination first. A range with a part that is not committed now fails its request with `ERROR_NOACCESS` through the usual failure path, and the log says how much of it could not be written, from which offset, and its state and protection. A part that is committed but protected is only logged (the first sixteen times) and the store goes ahead as before: whoever closed those pages may open them on the store, as draft #413 does. Seen in ProjectScarlett 1.0.2.1, 12 min 40 s into an offline run: a zlib read of `0x290000` bytes to `0x8c6200000` faulted at offset `0x10000`, with the stack inside `xcrdapi.dll` and only the first 64 KiB of the destination writable. That run was `b8355fa` with #389 and `fc69bc2`; the store is the same on `main`. **Not established:** why the title's destination was in that state, and whether the rest of it was uncommitted or closed. The minidump holds no memory state. If it was closed rather than uncommitted, this change only logs it and the fault is still to be fixed where the pages are closed. The log line added here will say which the next time it happens. Follows `fc69bc2` (#457) in the same file. Draft #413 also changes `queue.rs`; the two merge without a conflict there. ## Tested Run the [checks relevant to this change](../CONTRIBUTING.md#test-what-your-change-touches). - [ ] The checks relevant to this change passed: the `xcrdapi` suite and the code checks did, except one Python test of the launcher that fails the same way on `main` on this machine (below) - [x] Changed or new behaviour is covered by a Lanes scenario, or the reason it cannot be is stated below - [ ] Where the table calls for AMD and NVIDIA, they passed on both. Otherwise, say which vendor still needs to run them: the table asks for any card for this provider; run on NVIDIA only. Lanes issues no storage read into memory it has not committed, so the case is a unit test. `a_read_into_a_partly_committed_destination_fails_instead_of_faulting` reads a zlib stream into three 64 KiB pages of which one is committed and expects the request to fail, then commits the rest and expects the same read to land. With the check taken out, the test process ends with an access violation in that read. GPU, driver and backend: GeForce RTX 4070 Ti SUPER, 620.73.04, Proton Experimental for the checks (Core i9-12900K, Linux 7.2.11). Commands run and their results: ```text python tuxbox.py check --no-gpu passed Build the shader compiler FAILED Python tests: 654 ran, 1 failed, 10 skipped test_stage_baseline.GuestWatch.test_a_guest_that_died_stops_the_sandbox_instead_of_waiting_out_the_timeout AssertionError: 0 != 'guest gone' It fails the same way on main (d58ecf0b) without this change, four runs out of four (NixOS). passed Shader compiler tests passed DXBC tests passed XG layout tests passed Storage codec tests passed D3D12 Windows typecheck python build.py xmem && python build.py xcrdapi python tuxbox.py verify --only xcrdapi PASS xcrdapi cargo test -p tuxbox-xcrdapi (x86_64-pc-windows-msvc, run under Wine) 6 passed; with the check taken out, the process ends in the new test (exit code 5) The checks ran on this commit over 090cf6c; it was then rebased onto fa1b9cf6, which changes nothing under runtime/xcrdapi. ``` ## Checks No evidence JSON changed.
Copilot commented 2026-11-29 15:52:05 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by Copilot on 2026-11-29T15:52:05Z.

Code review location: runtime/xcrdapi/src/queue.rs; line 799

@@ -750,6 +771,46 @@ pub(crate) fn debug(text: &str) {
 /// texture over XMem pages there is checked at its next use. XMem's write
 /// watch sees these stores itself wherever it tracks the pages; this says so
 /// for every destination. Other memory is not XMem's to track.
+/// The first part of `[address, address + bytes)` that is not committed and
+/// writable, described for the log, with whether it is committed. None when a
+/// store can write the whole range.
+fn unwritable(address: usize, bytes: usize) -> Option<(bool, String)> {
+    use windows::Win32::System::Memory::{MEM_COMMIT, MEMORY_BASIC_INFORMATION, PAGE_GUARD, VirtualQuery};
+    let Some(end) = address.checked_add(bytes) else {
+        return Some((false, "the range wraps".to_owned()));
+    };
+    let mut at = address;
+    while at < end {
+        let mut info = MEMORY_BASIC_INFORMATION::default();
+        let got = unsafe {
+            VirtualQuery(Some(at as *const c_void), &mut info, size_of::<MEMORY_BASIC_INFORMATION>())
+        };
+        if got == 0 {
+            return Some((false, format!("no memory information at {at:#x}")));
+        }
+        let region_end = (info.BaseAddress as usize).saturating_add(info.RegionSize);
+        let committed = info.State == MEM_COMMIT;
+        // PAGE_READWRITE, PAGE_WRITECOPY and their executable forms.
+        let writable = committed
+            && info.Protect.0 & PAGE_GUARD.0 == 0
+            && matches!(info.Protect.0 & 0xff, 0x04 | 0x08 | 0x40 | 0x80);
+        if !writable || region_end <= at {
+            return Some((
+                committed && region_end > at,

A committed but protected prefix followed by an uncommitted tail returns Some((true, ...)) here, so execute() copies the whole range and can still fault after the prefix's protection fault is handled. Continue scanning the full output range, giving uncommitted regions precedence over the saved protected-region diagnostic. Add a regression with a protected committed prefix followed by a reserved tail.

<!-- greyfinch-sync:brcly/TuxBox:review-comment:4732075788 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/486#discussion_r4732075788). Originally posted by [Copilot](https://github.com/apps/copilot-pull-request-reviewer) on 2026-11-29T15:52:05Z. **Code review location:** `runtime/xcrdapi/src/queue.rs`; line 799 ~~~~diff @@ -750,6 +771,46 @@ pub(crate) fn debug(text: &str) { /// texture over XMem pages there is checked at its next use. XMem's write /// watch sees these stores itself wherever it tracks the pages; this says so /// for every destination. Other memory is not XMem's to track. +/// The first part of `[address, address + bytes)` that is not committed and +/// writable, described for the log, with whether it is committed. None when a +/// store can write the whole range. +fn unwritable(address: usize, bytes: usize) -> Option<(bool, String)> { + use windows::Win32::System::Memory::{MEM_COMMIT, MEMORY_BASIC_INFORMATION, PAGE_GUARD, VirtualQuery}; + let Some(end) = address.checked_add(bytes) else { + return Some((false, "the range wraps".to_owned())); + }; + let mut at = address; + while at < end { + let mut info = MEMORY_BASIC_INFORMATION::default(); + let got = unsafe { + VirtualQuery(Some(at as *const c_void), &mut info, size_of::<MEMORY_BASIC_INFORMATION>()) + }; + if got == 0 { + return Some((false, format!("no memory information at {at:#x}"))); + } + let region_end = (info.BaseAddress as usize).saturating_add(info.RegionSize); + let committed = info.State == MEM_COMMIT; + // PAGE_READWRITE, PAGE_WRITECOPY and their executable forms. + let writable = committed + && info.Protect.0 & PAGE_GUARD.0 == 0 + && matches!(info.Protect.0 & 0xff, 0x04 | 0x08 | 0x40 | 0x80); + if !writable || region_end <= at { + return Some(( + committed && region_end > at, ~~~~ --- A committed but protected prefix followed by an uncommitted tail returns `Some((true, ...))` here, so `execute()` copies the whole range and can still fault after the prefix's protection fault is handled. Continue scanning the full output range, giving uncommitted regions precedence over the saved protected-region diagnostic. Add a regression with a protected committed prefix followed by a reserved tail.
copilot-pull-request-reviewer[bot] commented 2026-11-29 15:52:05 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by copilot-pull-request-reviewer[bot] on 2026-11-29T15:52:05Z.

Review: COMMENTED


The output-range check stops at a protected committed prefix, allowing execute() to copy into an uncommitted tail and fault; it must scan the full range and prioritize uncommitted regions.

1 open issue
What changed in this PR

Adds destination-memory checks to decoded reads in TuxBox’s xcrdapi provider, aiming to report uncommitted destinations through normal request failure instead of crashing the worker thread.

Changes:

  • Checks destination memory and reports ERROR_NOACCESS for detected uncommitted regions.
  • Logs committed but protected regions while preserving recoverable protection-fault behavior.
  • Adds tests for partially committed destinations and successful reads after full commitment.
File Description
runtime/​xcrdapi/​src/​tests/​queue.rs Adds destination-state and decoded-read regression tests.
runtime/​xcrdapi/​src/​queue.rs Adds destination scanning, failure reporting, and sampled protection diagnostics.
runtime/​xcrdapi/​Cargo.toml Enables Windows memory APIs for querying and testing destinations.

Review effort: Balanced

<!-- greyfinch-sync:brcly/TuxBox:review:6103617901 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/486#pullrequestreview-6103617901). Originally posted by [copilot-pull-request-reviewer[bot]](https://github.com/apps/copilot-pull-request-reviewer) on 2026-11-29T15:52:05Z. **Review:** COMMENTED --- <!-- ccr-overview-v2 --> ### 🟡 Changes recommended The output-range check stops at a protected committed prefix, allowing execute() to copy into an uncommitted tail and fault; it must scan the full range and prioritize uncommitted regions. <details open> <summary><strong>1 open issue</strong></summary> - <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/high-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/high-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/high-v2-light.png" alt="High severity" width="62" height="18" align="texttop"></picture> [Uncommitted tail must take precedence over protected-prefix diagnostic](https://github.com/brcly/TuxBox/pull/486#discussion_r4732075788) · New </details> <details> <summary><strong>What changed in this PR</strong></summary> Adds destination-memory checks to decoded reads in TuxBox’s `xcrdapi` provider, aiming to report uncommitted destinations through normal request failure instead of crashing the worker thread. **Changes:** - Checks destination memory and reports `ERROR_NOACCESS` for detected uncommitted regions. - Logs committed but protected regions while preserving recoverable protection-fault behavior. - Adds tests for partially committed destinations and successful reads after full commitment. | File | Description | | ---- | ----------- | | `runtime/​xcrdapi/​src/​tests/​queue.rs` | Adds destination-state and decoded-read regression tests. | | `runtime/​xcrdapi/​src/​queue.rs` | Adds destination scanning, failure reporting, and sampled protection diagnostics. | | `runtime/​xcrdapi/​Cargo.toml` | Enables Windows memory APIs for querying and testing destinations. | </details> <sub>Review effort: Balanced</sub>
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
brcly/TuxBox!486
No description provided.