GPU/draw: evict CBV-backed fresh_tables on State::replay across cut lists #742

Open
github-bot wants to merge 1 commit from github-bot/gh-742 into main AGit
Owner

@⁠AscilCH on GitHub · 2026-11-25 06:09 UTC · original
AscilCH:fix/gpu-draw-replay-cbv-fresh-tables-uaf → main · +55 −5 · 1 files · 1 commits · open

Summary

Fixes a GPU use-after-free and stale-constant bug when a command list is cut at a memory wait (crates/victory-gpu/src/draw.rs):

  • When State::tables populates a dynamic descriptor table containing a View::Constant(address, size), the CBV points to the current HostList's scratch upload memory (list.scratch(size)) and registers list.defer_fill(...) only on that HostList.
  • When list::cut splits the command list at a memory wait and runs State::replay on a fresh HostList (H2), State::replay previously retained all fresh_tables entries. If H2 reused a cached CBV table, it pointed into H1's scratch upload buffer without registering defer_fill on H2.
  • Because H1 executes and resets (list::recycle -> H1.reset()) before H2 is released from its value wait, H1's upload buffers are dropped or returned to the scratch pool while H2 still references their GPU VAs (and any constant-buffer updates written before H2 runs are never copied).
  • State::fresh_tables now tracks (first_slot, has_cbv) and State::replay evicts all CBV-backed entries (retain(|_, &mut (_, has_cbv)| !has_cbv)), while preserving non-CBV tables and keeping self.dynamic alive until the final part's state drops.

Verification

  • cargo test -p victory-gpu --locked -- draw::replay_tests: 1 passed, 0 failed
  • cargo clippy -p victory-gpu --all-targets --all-features --locked: 0 new warnings (pre-existing 8dd30ab warnings in draw.rs:2377 and indirect.rs:1322 untouched)
  • cargo xtask policy: 171 files ok

(AI-assisted; synthetic unit tests only, no game data.)

**@⁠AscilCH** on GitHub · 2026-11-25 06:09 UTC · [original](https://github.com/fxceless/victory-fork/pull/742) `AscilCH:fix/gpu-draw-replay-cbv-fresh-tables-uaf` → `main` · +55 −5 · 1 files · 1 commits · open ### Summary Fixes a GPU use-after-free and stale-constant bug when a command list is cut at a memory wait (`crates/victory-gpu/src/draw.rs`): - When `State::tables` populates a dynamic descriptor table containing a `View::Constant(address, size)`, the CBV points to the current `HostList`'s scratch upload memory (`list.scratch(size)`) and registers `list.defer_fill(...)` only on that `HostList`. - When `list::cut` splits the command list at a memory wait and runs `State::replay` on a fresh `HostList` (`H2`), `State::replay` previously retained all `fresh_tables` entries. If `H2` reused a cached CBV table, it pointed into `H1`'s scratch upload buffer without registering `defer_fill` on `H2`. - Because `H1` executes and resets (`list::recycle` -> `H1.reset()`) before `H2` is released from its value wait, `H1`'s upload buffers are dropped or returned to the scratch pool while `H2` still references their GPU VAs (and any constant-buffer updates written before `H2` runs are never copied). - `State::fresh_tables` now tracks `(first_slot, has_cbv)` and `State::replay` evicts all CBV-backed entries (`retain(|_, &mut (_, has_cbv)| !has_cbv)`), while preserving non-CBV tables and keeping `self.dynamic` alive until the final part's state drops. ### Verification - `cargo test -p victory-gpu --locked -- draw::replay_tests`: **1 passed, 0 failed** - `cargo clippy -p victory-gpu --all-targets --all-features --locked`: 0 new warnings (pre-existing `8dd30ab` warnings in `draw.rs:2377` and `indirect.rs:1322` untouched) - `cargo xtask policy`: `171 files ok` *(AI-assisted; synthetic unit tests only, no game data.)*
When a command list is cut at a memory wait (`list::cut`), `State::replay`
prepares a fresh `HostList` for the continuing part. Previously it preserved
all `State::fresh_tables` entries unchanged, even though any table containing
a `View::Constant` wrote a CBV pointing into the earlier part's
`HostList::scratch` upload memory and only registered `defer_fill` on that
earlier part.

Once the earlier part completes and resets/recycles before the later part
runs, the cached CBV points into freed/reused scratch memory (GPU UAF /
corrupted constants) and misses any constant updates written while the later
part was waiting. Track whether each `fresh_tables` entry contains a CBV and
evict CBV-backed entries in `State::replay`, while keeping non-CBV tables
and `self.dynamic` intact.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:50:04 +00:00
This pull request has changes conflicting with the target branch.
  • crates/victory-gpu/src/draw.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

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

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-742'
git switch 'github-bot/gh-742'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-742'
git switch 'github-bot/gh-742'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-742'
git switch 'main'
git merge --squash 'github-bot/gh-742'
git switch 'main'
git merge --ff-only 'github-bot/gh-742'
git switch 'main'
git merge 'github-bot/gh-742'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.