gpu: check the raw SRV bounds and 64-bit offsets without a device #1706

Merged
Asimmimx merged 1 commit from upstream-pr/1713 into main 2026-11-24 17:44:45 +00:00
Asimmimx commented 2026-11-24 17:37:32 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Asimmimx on 2026-11-24T17:37:32Z.


Refs #1149.

What the header does

src/raw_buffer_srv.h defines make_raw_buffer_srv, which turns a GPU byte address and a first element inside an already-owned buffer into a raw (R32_TYPELESS, D3D12_BUFFER_SRV_FLAG_RAW) buffer SRV description. It refuses (E_INVALIDARG) a null base, an address outside the buffer, a zero count, an address that is not DWORD-aligned, a first element or count that does not fit the remaining whole DWORDs, and a view start that is not 16-byte aligned.

Tests that reach it

Only vm_raw_srv_warp and vm_raw_srv_hardware (tests/vm_copy_queue_check.cpp). They resolve two views inside one 128 KiB buffer (a cross-page view and the same view shifted by four elements) and refuse a misaligned address, the address one past the buffer and a count one element too long. Nothing checks the header without a device, and nothing exercises widths or offsets above 4 GiB.

Mutation probe

28 single-point mutants of the header, one at a time, rebuilding vm_copy_queue_check and raw_buffer_srv_check and running ^(vm_raw_srv_warp|raw_buffer_srv)$. Killed means at least one of the selected tests failed.

Mutant vm_raw_srv_warp with raw_buffer_srv
drop the !base guard survived killed
drop address < base survived survived (equivalent)
address - base >= width to > survived survived (equivalent)
drop address - base >= width survived killed
drop !count survived killed
available elements rounded up ((width - offset + 3) / 4) survived killed
drop offset % element_bytes survived survived (equivalent)
first_element > available to >= survived survived (equivalent)
drop first_element > available survived killed
count > available - first to >= (exact fit refused) survived killed
16-byte alignment taken from offset instead of start survived killed
drop the 16-byte alignment check killed killed
alignment refusal returns E_FAIL killed killed
alignment % 16 to % 4 killed killed
first refusal returns E_FAIL killed killed
bounds refusal returns E_FAIL killed killed
Format = R32_UINT killed killed
component mapping left 0 killed killed
FirstElement = start (bytes) killed killed
FirstElement ignores first_element killed killed
NumElements = count - 1 killed killed
Flags = NONE killed killed
drop result = {} (earlier StructureByteStride kept) survived killed
offset truncated to 32 bits survived killed
available element count truncated to 32 bits survived killed
first_element truncated to 32 bits in start survived killed
FirstElement truncated to 32 bits survived killed
width truncated to 32 bits survived killed

Existing check: 11 of 28 killed. With the new check: 24 of 28 killed. The 4 survivors are equivalent mutants:

  • An address below the base wraps address - base to a value that is never below a real buffer width.
  • With address - base == width there are 0 available elements, and the nonzero count is refused anyway.
  • start = offset + 4 * first_element, so an offset that is not a multiple of 4 always gives a start that is not 16-aligned.
  • first_element == available leaves 0 elements, and the nonzero count is refused anyway.

New cases

tests/raw_buffer_srv_check.cpp is a device-free check next to raw_buffer_uav_check. It needs only the D3D12 headers. Expected values are worked by hand in the comments. Each accepted view starts from a description filled with 0xcd and must come back with R32_TYPELESS, BUFFER, the default component mapping, the expected FirstElement and NumElements, a zero StructureByteStride and the RAW flag.

Resolved (7):

  • the whole 0x100-byte buffer (0x40 elements);
  • from byte 0x10 with first element 4, 0x38 elements ending exactly at the buffer end (first element 8);
  • the last 16 bytes (first element 0x3c);
  • an unaligned address (byte 4) made 16-aligned by first element 3 (first element 4);
  • a 0x102-byte width, which holds 0x40 whole elements;
  • offset 0x1'0000'0000 into a 0x5'0000'0010-byte buffer with first element 0x1'0000'0000 (first element 0x1'4000'0000, exact fit);
  • offset 0x10 into a 0x4'0000'0010-byte buffer, where exactly 0x1'0000'0000 elements remain (first element 0x1'0000'0000).

Refused with E_INVALIDARG (9): a null base, an address below the base, an address past the buffer end, zero elements, one element past the buffer end, one element too many for the 0x102-byte width, a first element past the available elements, an aligned address with an unaligned first element, and one element past what remains in a 0x1'0000'0010-byte buffer.

Negative control

raw_buffer_srv_first_32_control runs raw_buffer_srv_check --mutate first-32 with WILL_FAIL TRUE. The mutation expects the 32-bit truncation (0x4000'0000) of the first element above 4 GiB, so the check must fail:

FAIL offset and first element above 4 GiB: hr=0x00000000 format=39 dimension=1 mapping=0x1688 first=0x140000000 elements=0x4 stride=0 flags=1, expected S_OK first=0x40000000 elements=0x4
raw_buffer_srv: 1 FAILED

Not pinned

  • Whether the result is left unchanged on refusal. Unlike src/raw_buffer_uav.h, this header does not document it, so the check does not depend on it.
  • The four equivalent mutants listed above.

Commands and results

cmake --preset dev
cmake --build --preset dev --target raw_buffer_srv_check vm_copy_queue_check raw_buffer_uav_check
ctest --preset dev --no-tests=error -R '^(raw_buffer_srv(_first_32_control)?|vm_raw_srv_warp|raw_buffer_uav(_adjacent_control)?)$'
1/5 Test #1044: vm_raw_srv_warp ...................   Passed    0.07 sec
2/5 Test #1050: raw_buffer_srv ....................   Passed    0.02 sec
3/5 Test #1051: raw_buffer_srv_first_32_control ...   Passed    0.01 sec
4/5 Test #1052: raw_buffer_uav ....................   Passed    0.01 sec
5/5 Test #1053: raw_buffer_uav_adjacent_control ...   Passed    0.01 sec
100% tests passed, 0 tests failed out of 5

raw_buffer_srv_check prints raw_buffer_srv: PASS (7 resolved, 9 refused). python -B tests/docs_links_check.py passes (17 Markdown files, 364 links). No _hardware test was run for this change, and no capability skips occurred.

Environment

Windows 11 Pro 26300.9974, MSVC from Visual Studio, Windows SDK 10.0.26100.0, dev preset (Debug). vm_raw_srv_warp uses Microsoft WARP. The new check uses no device.

Commit: 99e2e324

AI-assisted (Claude Code).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6587774052 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1713). Originally posted by [Asimmimx](https://github.com/Asimmimx) on 2026-11-24T17:37:32Z. --- Refs #1149. ## What the header does `src/raw_buffer_srv.h` defines `make_raw_buffer_srv`, which turns a GPU byte address and a first element inside an already-owned buffer into a raw (`R32_TYPELESS`, `D3D12_BUFFER_SRV_FLAG_RAW`) buffer SRV description. It refuses (`E_INVALIDARG`) a null base, an address outside the buffer, a zero count, an address that is not DWORD-aligned, a first element or count that does not fit the remaining whole DWORDs, and a view start that is not 16-byte aligned. ## Tests that reach it Only `vm_raw_srv_warp` and `vm_raw_srv_hardware` (`tests/vm_copy_queue_check.cpp`). They resolve two views inside one 128 KiB buffer (a cross-page view and the same view shifted by four elements) and refuse a misaligned address, the address one past the buffer and a count one element too long. Nothing checks the header without a device, and nothing exercises widths or offsets above 4 GiB. ## Mutation probe 28 single-point mutants of the header, one at a time, rebuilding `vm_copy_queue_check` and `raw_buffer_srv_check` and running `^(vm_raw_srv_warp|raw_buffer_srv)$`. Killed means at least one of the selected tests failed. | Mutant | `vm_raw_srv_warp` | with `raw_buffer_srv` | |---|---|---| | drop the `!base` guard | survived | killed | | drop `address < base` | survived | survived (equivalent) | | `address - base >= width` to `>` | survived | survived (equivalent) | | drop `address - base >= width` | survived | killed | | drop `!count` | survived | killed | | available elements rounded up (`(width - offset + 3) / 4`) | survived | killed | | drop `offset % element_bytes` | survived | survived (equivalent) | | `first_element > available` to `>=` | survived | survived (equivalent) | | drop `first_element > available` | survived | killed | | `count > available - first` to `>=` (exact fit refused) | survived | killed | | 16-byte alignment taken from `offset` instead of `start` | survived | killed | | drop the 16-byte alignment check | killed | killed | | alignment refusal returns `E_FAIL` | killed | killed | | alignment `% 16` to `% 4` | killed | killed | | first refusal returns `E_FAIL` | killed | killed | | bounds refusal returns `E_FAIL` | killed | killed | | `Format` = `R32_UINT` | killed | killed | | component mapping left 0 | killed | killed | | `FirstElement` = `start` (bytes) | killed | killed | | `FirstElement` ignores `first_element` | killed | killed | | `NumElements` = `count - 1` | killed | killed | | `Flags` = `NONE` | killed | killed | | drop `result = {}` (earlier `StructureByteStride` kept) | survived | killed | | offset truncated to 32 bits | survived | killed | | available element count truncated to 32 bits | survived | killed | | `first_element` truncated to 32 bits in `start` | survived | killed | | `FirstElement` truncated to 32 bits | survived | killed | | width truncated to 32 bits | survived | killed | Existing check: 11 of 28 killed. With the new check: 24 of 28 killed. The 4 survivors are equivalent mutants: - An address below the base wraps `address - base` to a value that is never below a real buffer width. - With `address - base == width` there are 0 available elements, and the nonzero count is refused anyway. - `start = offset + 4 * first_element`, so an offset that is not a multiple of 4 always gives a start that is not 16-aligned. - `first_element == available` leaves 0 elements, and the nonzero count is refused anyway. ## New cases `tests/raw_buffer_srv_check.cpp` is a device-free check next to `raw_buffer_uav_check`. It needs only the D3D12 headers. Expected values are worked by hand in the comments. Each accepted view starts from a description filled with `0xcd` and must come back with `R32_TYPELESS`, `BUFFER`, the default component mapping, the expected `FirstElement` and `NumElements`, a zero `StructureByteStride` and the `RAW` flag. Resolved (7): - the whole 0x100-byte buffer (0x40 elements); - from byte 0x10 with first element 4, 0x38 elements ending exactly at the buffer end (first element 8); - the last 16 bytes (first element 0x3c); - an unaligned address (byte 4) made 16-aligned by first element 3 (first element 4); - a 0x102-byte width, which holds 0x40 whole elements; - offset 0x1'0000'0000 into a 0x5'0000'0010-byte buffer with first element 0x1'0000'0000 (first element 0x1'4000'0000, exact fit); - offset 0x10 into a 0x4'0000'0010-byte buffer, where exactly 0x1'0000'0000 elements remain (first element 0x1'0000'0000). Refused with `E_INVALIDARG` (9): a null base, an address below the base, an address past the buffer end, zero elements, one element past the buffer end, one element too many for the 0x102-byte width, a first element past the available elements, an aligned address with an unaligned first element, and one element past what remains in a 0x1'0000'0010-byte buffer. ## Negative control `raw_buffer_srv_first_32_control` runs `raw_buffer_srv_check --mutate first-32` with `WILL_FAIL TRUE`. The mutation expects the 32-bit truncation (0x4000'0000) of the first element above 4 GiB, so the check must fail: ``` FAIL offset and first element above 4 GiB: hr=0x00000000 format=39 dimension=1 mapping=0x1688 first=0x140000000 elements=0x4 stride=0 flags=1, expected S_OK first=0x40000000 elements=0x4 raw_buffer_srv: 1 FAILED ``` ## Not pinned - Whether the result is left unchanged on refusal. Unlike `src/raw_buffer_uav.h`, this header does not document it, so the check does not depend on it. - The four equivalent mutants listed above. ## Commands and results ```powershell cmake --preset dev cmake --build --preset dev --target raw_buffer_srv_check vm_copy_queue_check raw_buffer_uav_check ctest --preset dev --no-tests=error -R '^(raw_buffer_srv(_first_32_control)?|vm_raw_srv_warp|raw_buffer_uav(_adjacent_control)?)$' ``` ``` 1/5 Test #1044: vm_raw_srv_warp ................... Passed 0.07 sec 2/5 Test #1050: raw_buffer_srv .................... Passed 0.02 sec 3/5 Test #1051: raw_buffer_srv_first_32_control ... Passed 0.01 sec 4/5 Test #1052: raw_buffer_uav .................... Passed 0.01 sec 5/5 Test #1053: raw_buffer_uav_adjacent_control ... Passed 0.01 sec 100% tests passed, 0 tests failed out of 5 ``` `raw_buffer_srv_check` prints `raw_buffer_srv: PASS (7 resolved, 9 refused)`. `python -B tests/docs_links_check.py` passes (17 Markdown files, 364 links). No `_hardware` test was run for this change, and no capability skips occurred. ## Environment Windows 11 Pro 26300.9974, MSVC from Visual Studio, Windows SDK 10.0.26100.0, `dev` preset (Debug). `vm_raw_srv_warp` uses Microsoft WARP. The new check uses no device. Commit: `99e2e324` AI-assisted (Claude Code).
upstream-sync closed this pull request 2026-11-24 18:02:43 +00:00
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
R0Y00/Xbox2Windows!1706
No description provided.