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

Open
github-bot wants to merge 2 commits from github-bot/gh-2224 into main AGit
Owner

@⁠Xvania7 on GitHub · 2026-11-25 08:18 UTC · original
Xvania7:fix/execute-indirect-offset-overflow → main · +79 −2 · 2 files · 2 commits · open

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.

**@⁠Xvania7** on GitHub · 2026-11-25 08:18 UTC · [original](https://github.com/Marvisak/VIctory/pull/2224) `Xvania7:fix/execute-indirect-offset-overflow` → `main` · +79 −2 · 2 files · 2 commits · open ## 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.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:59:00 +00:00
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 13:30 UTC · original · edited 2026-11-25 16:48 UTC

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

**@⁠Marvisak** on GitHub · 2026-11-25 13:30 UTC · [original](https://github.com/Marvisak/VIctory/pull/2224#issuecomment-7163873356) · edited 2026-11-25 16:48 UTC <!-- 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)_
Author
Owner

@⁠Xvania7 on GitHub · 2026-11-25 15:13 UTC · original

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.

**@⁠Xvania7** on GitHub · 2026-11-25 15:13 UTC · [original](https://github.com/Marvisak/VIctory/pull/2224#issuecomment-7166511135) 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 can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2224/head:github-bot/gh-2224'
git switch 'github-bot/gh-2224'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2224'
git switch 'github-bot/gh-2224'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2224'
git switch 'github-bot/gh-2224'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2224'
git switch 'main'
git merge --squash 'github-bot/gh-2224'
git switch 'main'
git merge --ff-only 'github-bot/gh-2224'
git switch 'main'
git merge 'github-bot/gh-2224'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!2224
No description provided.