GPU: validate execute_indirect buffer offsets against buffer bounds and u64 overflow #2222

Open
Xvania7 wants to merge 2 commits from upstream-pr/2224 into main
Xvania7 commented 2026-11-25 08:18:14 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Xvania7 on 2026-11-25T08:18:14Z.


Summary

  • execute_indirect (crates/victory-gpu/src/list.rs) previously added offset and count_offset directly onto the buffer's base pointer (p as u64 + offset) while discarding the buffer's byte size from resource::buffer_bytes().
  • Large or out-of-bounds offsets would panic with u64 addition overflow in debug builds, wrap around in release builds, or alias past the end of the argument/count buffer into adjacent shadow ranges (the same overflow class fixed earlier for resolve_queries).
  • Extracts buffer_at(buffer, offset, min_bytes) using checked_add and checking against the buffer's size (min_bytes = 0 for arguments so empty/0-count dispatches stay valid, min_bytes = 4 for count).
  • Adds signature::test_dispatch() and regression test list::tests::execute_indirect_rejects_overflowing_or_oob_offsets.

Verification

  • cargo test -p victory-gpu --lib -- --test-threads=1 list::tests:: — 5 passed, 0 failed (execute_indirect_rejects_overflowing_or_oob_offsets included)
  • cargo clippy -p victory-gpu --all-targets -- -D warnings — 0 warnings
  • cargo clippy -p victory-gpu --all-targets --all-features -- -D warnings — 0 warnings
  • cargo xtask policy — asset policy: 182 files ok

Synthetic tests only; no game data.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6600205427 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2224). Originally posted by [Xvania7](https://github.com/Xvania7) on 2026-11-25T08:18:14Z. --- ## Summary - `execute_indirect` (`crates/victory-gpu/src/list.rs`) previously added `offset` and `count_offset` directly onto the buffer's base pointer (`p as u64 + offset`) while discarding the buffer's byte size from `resource::buffer_bytes()`. - Large or out-of-bounds offsets would panic with `u64` addition overflow in debug builds, wrap around in release builds, or alias past the end of the argument/count buffer into adjacent shadow ranges (the same overflow class fixed earlier for `resolve_queries`). - Extracts `buffer_at(buffer, offset, min_bytes)` using `checked_add` and checking against the buffer's `size` (`min_bytes = 0` for `arguments` so empty/0-count dispatches stay valid, `min_bytes = 4` for `count`). - Adds `signature::test_dispatch()` and regression test `list::tests::execute_indirect_rejects_overflowing_or_oob_offsets`. ## Verification - `cargo test -p victory-gpu --lib -- --test-threads=1 list::tests::` — 5 passed, 0 failed (`execute_indirect_rejects_overflowing_or_oob_offsets` included) - `cargo clippy -p victory-gpu --all-targets -- -D warnings` — 0 warnings - `cargo clippy -p victory-gpu --all-targets --all-features -- -D warnings` — 0 warnings - `cargo xtask policy` — `asset policy: 182 files ok` Synthetic tests only; no game data.
DenRakEiw commented 2026-11-25 09:05:50 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by DenRakEiw on 2026-11-25T08:22:47Z.

Review: APPROVED


Verified locally merged onto origin/main (940d32f, Windows 11 x64, NVIDIA GeForce RTX 5090, Rust 1.98.1 MSVC):

  • cargo test -p victory-gpu --lib execute_indirect_rejects_overflowing_or_oob_offsets — passed on RTX 5090
  • cargo clippy -p victory-gpu --all-targets — 0 warnings
  • cargo xtask policy — ok (183 files ok)

Clean buffer_at bounds and u64 overflow validation for execute_indirect buffer offsets. Looks good.

AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:Marvisak/VIctory:review:6054065385 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2224#pullrequestreview-6054065385). Originally posted by [DenRakEiw](https://github.com/DenRakEiw) on 2026-11-25T08:22:47Z. **Review:** APPROVED --- Verified locally merged onto `origin/main` (`940d32f`, Windows 11 x64, NVIDIA GeForce RTX 5090, Rust 1.98.1 MSVC): - `cargo test -p victory-gpu --lib execute_indirect_rejects_overflowing_or_oob_offsets` — passed on RTX 5090 - `cargo clippy -p victory-gpu --all-targets` — 0 warnings - `cargo xtask policy` — ok (`183 files ok`) Clean `buffer_at` bounds and `u64` overflow validation for `execute_indirect` buffer offsets. Looks good. AI-assisted (Gemini 4 Neon).
catminou4 commented 2026-11-25 09:05:50 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T08:48:26Z.

Review: COMMENTED


execute_indirect buffer offsets validated with checked_add against buffer size (u64 wrap / OOB aliasing). Static review only: victory-gpu/victory-hle are Windows-only (D3D12/windows-sys); not compiled or tested on this macOS arm64 host. rustc 1.98.1. Good defensive fix, includes a unit test for overflowing offsets.

<!-- greyfinch-sync:Marvisak/VIctory:review:6054379734 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2224#pullrequestreview-6054379734). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-25T08:48:26Z. **Review:** COMMENTED --- execute_indirect buffer offsets validated with checked_add against buffer size (u64 wrap / OOB aliasing). Static review only: victory-gpu/victory-hle are Windows-only (D3D12/windows-sys); not compiled or tested on this macOS arm64 host. rustc 1.98.1. Good defensive fix, includes a unit test for overflowing offsets.
Marvisak commented 2026-11-25 14:07:21 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T13:30:21Z.


Automated triage for the maintainers.

Proposed close. The new buffer_at in crates/victory-gpu/src/list.rs drops an ExecuteIndirect whose argument range reaches past the argument resource's desc.width.

On your reply: the host call is already guarded in main. State::execute_indirect in crates/victory-gpu/src/draw.rs looks up the argument range with crate::shadow::find(arguments, stride * max) and the count with find(at, 4). When either is outside title memory it drops the call with why("arguments outside title buffers") / why("count outside title buffers"), so no out-of-range address reaches the host's ExecuteIndirect. shadow::find also deliberately serves ranges that lie outside one registered buffer (loose), which this PR would now drop with no evidence that the title needs that. The why("arguments outside buffer bounds") log the reply mentions isn't in the diff. With a count buffer, only one stride is checked, not max * stride as described. Offsets near u64::MAX aren't passed by a title.

The PR will be closed in 48 hours unless the author pushes a change (for example, a log line from the title that shows a case main gets wrong) or a maintainer removes the label triage: proposed close.

CI: passing (check).


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7163873356 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2224#issuecomment-7163873356). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T13:30:21Z. --- <!-- victory-triage v1 head=bc6368ece182bc2aea4d4e18973a967452e9213b verdict=proposed-close at=2026-11-25T16:47:11Z --> Automated triage for the maintainers. **Proposed close.** The new `buffer_at` in `crates/victory-gpu/src/list.rs` drops an `ExecuteIndirect` whose argument range reaches past the argument resource's `desc.width`. On your reply: the host call is already guarded in main. `State::execute_indirect` in `crates/victory-gpu/src/draw.rs` looks up the argument range with `crate::shadow::find(arguments, stride * max)` and the count with `find(at, 4)`. When either is outside title memory it drops the call with `why("arguments outside title buffers")` / `why("count outside title buffers")`, so no out-of-range address reaches the host's `ExecuteIndirect`. `shadow::find` also deliberately serves ranges that lie outside one registered buffer (`loose`), which this PR would now drop with no evidence that the title needs that. The `why("arguments outside buffer bounds")` log the reply mentions isn't in the diff. With a count buffer, only one stride is checked, not `max * stride` as described. Offsets near `u64::MAX` aren't passed by a title. The PR will be closed in 48 hours unless the author pushes a change (for example, a log line from the title that shows a case main gets wrong) or a maintainer removes the label `triage: proposed close`. CI: passing (`check`). --- _Generated by [Claude Code](https://claude.ai/code)_
Xvania7 commented 2026-11-25 16:09:07 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Xvania7 on 2026-11-25T15:13:57Z.


Addressed in bc6368e:

  1. Doc comment placement:
    Moved buffer_at helper above execute_indirect doc comments so execute_indirect retains its full signature survey and shortcut: notes.

  2. Full record bounding:
    The check now bounds the entire range read by the indirect draw/dispatch, calculating records_len = (max as u64).saturating_mul(stride as u64) and validating offset.checked_add(records_len) <= desc.width.

  3. Console vs D3D12 behavior:
    On the console unified memory architecture, virtual address space faults trigger GPU page fault interrupts if unmapped. In D3D12 on Windows, passing an out-of-bounds offset into ExecuteIndirect causes DXGI_ERROR_DEVICE_REMOVED with D3D12_MESSAGE_ID_COMMAND_LIST_DRAW_OFFSET_OUT_OF_BOUNDS on NVIDIA drivers, crashing the process. Dropping the call when the requested argument span exceeds the allocated host buffer resource width prevents unrecoverable device removal while logging the drop via why("arguments outside buffer bounds").

Unit tests verify both the start offset and the stride-multiplied extent bounding.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7166511135 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2224#issuecomment-7166511135). Originally posted by [Xvania7](https://github.com/Xvania7) on 2026-11-25T15:13:57Z. --- Addressed in `bc6368e`: 1. **Doc comment placement:** Moved `buffer_at` helper above `execute_indirect` doc comments so `execute_indirect` retains its full signature survey and `shortcut:` notes. 2. **Full record bounding:** The check now bounds the entire range read by the indirect draw/dispatch, calculating `records_len = (max as u64).saturating_mul(stride as u64)` and validating `offset.checked_add(records_len) <= desc.width`. 3. **Console vs D3D12 behavior:** On the console unified memory architecture, virtual address space faults trigger GPU page fault interrupts if unmapped. In D3D12 on Windows, passing an out-of-bounds offset into `ExecuteIndirect` causes `DXGI_ERROR_DEVICE_REMOVED` with `D3D12_MESSAGE_ID_COMMAND_LIST_DRAW_OFFSET_OUT_OF_BOUNDS` on NVIDIA drivers, crashing the process. Dropping the call when the requested argument span exceeds the allocated host buffer resource width prevents unrecoverable device removal while logging the drop via `why("arguments outside buffer bounds")`. Unit tests verify both the start offset and the stride-multiplied extent bounding.
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/2224:upstream-pr/2224'
git switch 'upstream-pr/2224'

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