GPU: hold SHADER_HEAPS across descriptor mirror and check query offsets #52

Merged
AndyLatimer merged 1 commit from upstream-pr/52 into main 2026-11-25 00:10:07 +00:00
AndyLatimer commented 2026-11-23 23:52:40 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by AndyLatimer on 2026-11-23T23:52:40Z.


Fixes a concurrent lifetime bug in descriptor mirroring and three bounds/overflow edge cases in victory-gpu:

  1. descriptor::mirror concurrent Heap::drop UAF (descriptor.rs): shader_slot previously locked SHADER_HEAPS, dereferenced the raw *const Heap into &Heap, and dropped the SHADER_HEAPS lock before returning to mirror. A concurrent Heap::drop on another thread could free the heap before mirror accessed heap.pending / heap.host. mirror now holds the SHADER_HEAPS lock across the access (matching release_dynamic's locking discipline; HostHeap::mirror never locks SHADER_HEAPS).
  2. descriptor::copy_simple and create_heap guards (descriptor.rs): returns early on an unknown descriptor heap kind instead of looping count times calling mirror(dst), and rejects placed heaps whose address + size overflows u64.
  3. list::resolve_queries offset overflow (list.rs): offset + u64::from(count) * bytes > size could overflow u64 (panic in debug builds, wrap in release into an out-of-bounds write). Now uses checked_add with a regression test (resolve_queries_rejects_overflowing_offset).

Testing

  • cargo test -p victory-gpu: 37 passed, 0 failed (including the new resolve_queries_rejects_overflowing_offset test).
  • cargo clippy -p victory-gpu --all-targets: 0 warnings.
  • cargo xtask policy: pass (148 files).
  • Tested with synthetic unit tests only (not run against a title).
<!-- greyfinch-sync:Marvisak/VIctory:issue:6571323269 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/52). Originally posted by [AndyLatimer](https://github.com/AndyLatimer) on 2026-11-23T23:52:40Z. --- Fixes a concurrent lifetime bug in descriptor mirroring and three bounds/overflow edge cases in `victory-gpu`: 1. **`descriptor::mirror` concurrent `Heap::drop` UAF** (`descriptor.rs`): `shader_slot` previously locked `SHADER_HEAPS`, dereferenced the raw `*const Heap` into `&Heap`, and dropped the `SHADER_HEAPS` lock before returning to `mirror`. A concurrent `Heap::drop` on another thread could free the heap before `mirror` accessed `heap.pending` / `heap.host`. `mirror` now holds the `SHADER_HEAPS` lock across the access (matching `release_dynamic`'s locking discipline; `HostHeap::mirror` never locks `SHADER_HEAPS`). 2. **`descriptor::copy_simple` and `create_heap` guards** (`descriptor.rs`): returns early on an unknown descriptor heap kind instead of looping `count` times calling `mirror(dst)`, and rejects placed heaps whose `address + size` overflows `u64`. 3. **`list::resolve_queries` offset overflow** (`list.rs`): `offset + u64::from(count) * bytes > size` could overflow `u64` (panic in debug builds, wrap in release into an out-of-bounds write). Now uses `checked_add` with a regression test (`resolve_queries_rejects_overflowing_offset`). ## Testing - `cargo test -p victory-gpu`: 37 passed, 0 failed (including the new `resolve_queries_rejects_overflowing_offset` test). - `cargo clippy -p victory-gpu --all-targets`: 0 warnings. - `cargo xtask policy`: pass (148 files). - Tested with synthetic unit tests only (not run against a title).
lordon1a commented 2026-11-24 06:54:37 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by lordon1a on 2026-11-24T00:19:57Z.


Verified 628b95da5 on Windows 11 (x86_64-pc-windows-gnullvm, rustc 1.100.0, applied cleanly to main@35b054ec0): pass.

  • cargo xtask policy: 150 files ok
  • cargo test -p victory-gpu: 40 passed, 0 failed (including the new query offset / descriptor heap mirror test + host D3D12 tests).

AI-assisted.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7117956318 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/52#issuecomment-7117956318). Originally posted by [lordon1a](https://github.com/lordon1a) on 2026-11-24T00:19:57Z. --- Verified `628b95da5` on Windows 11 (`x86_64-pc-windows-gnullvm`, `rustc 1.100.0`, applied cleanly to `main@35b054ec0`): **pass**. - `cargo xtask policy`: 150 files ok - `cargo test -p victory-gpu`: **40 passed, 0 failed** (including the new query offset / descriptor heap mirror test + host D3D12 tests). AI-assisted.
DaviTostes commented 2026-11-24 06:54:47 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by DaviTostes on 2026-11-24T00:57:32Z.


Tested 628b95d under Wine 11.22 + vkd3d-proton 3.1 on Arch Linux x86_64 (AMD RX 9060 XT, RADV 26.3.1), Windows build with cargo xwin ... --target x86_64-pc-windows-msvc: pass, no regression.

  • victory_gpu: 35 passed, 2 failed — the PR adds one test, and the two failures are the environment-only ones present on this base (argument_clamp_builds, buffer_data_reaches_the_host_texture, the latter now tracked as #128).
  • Note the branch is based on 97c78d1; the pipeline-library test that fails on vkd3d only exists on newer main, so this run is otherwise clean.

No game data used. AI-assisted (DeepSeek V4.1 Flash coding agent).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7118610026 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/52#issuecomment-7118610026). Originally posted by [DaviTostes](https://github.com/DaviTostes) on 2026-11-24T00:57:32Z. --- Tested `628b95d` under **Wine 11.22 + vkd3d-proton 3.1** on Arch Linux x86_64 (AMD RX 9060 XT, RADV 26.3.1), Windows build with `cargo xwin ... --target x86_64-pc-windows-msvc`: **pass, no regression**. - `victory_gpu`: **35 passed, 2 failed** — the PR adds one test, and the two failures are the environment-only ones present on this base (`argument_clamp_builds`, `buffer_data_reaches_the_host_texture`, the latter now tracked as #128). - Note the branch is based on `97c78d1`; the pipeline-library test that fails on vkd3d only exists on newer `main`, so this run is otherwise clean. No game data used. AI-assisted (DeepSeek V4.1 Flash coding agent).
mercuryVM commented 2026-11-24 10:11:38 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by mercuryVM on 2026-11-24T10:11:38Z.

Review: APPROVED


Tested 628b95d on Windows 11, RTX 5070, MSVC: cargo test -p victory-gpu 37 passed, including resolve_queries_rejects_overflowing_offset. cargo clippy -p victory-gpu --all-targets is clean.

  • Lock order: mirror now holds SHADER_HEAPS and then takes heap.pending, and Heap::host takes pending while it builds or mirrors into HostHeap. Neither of those paths takes SHADER_HEAPS (only drop, release_dynamic and create_heap do, and they take nothing else first), so there is no inversion.
  • copy_simple returning early on an unknown kind is better than the old behaviour: with step = 0, every mirror(dst) call hit the same handle.
  • count * bytes in resolve_queries cannot overflow (u32 × at most 88 fits in u64), so checked_add on the offset alone is enough.

AI-assisted (Claude Code).

<!-- greyfinch-sync:Marvisak/VIctory:review:6037312110 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/52#pullrequestreview-6037312110). Originally posted by [mercuryVM](https://github.com/mercuryVM) on 2026-11-24T10:11:38Z. **Review:** APPROVED --- Tested 628b95d on Windows 11, RTX 5070, MSVC: `cargo test -p victory-gpu` 37 passed, including `resolve_queries_rejects_overflowing_offset`. `cargo clippy -p victory-gpu --all-targets` is clean. - Lock order: `mirror` now holds `SHADER_HEAPS` and then takes `heap.pending`, and `Heap::host` takes `pending` while it builds or mirrors into `HostHeap`. Neither of those paths takes `SHADER_HEAPS` (only `drop`, `release_dynamic` and `create_heap` do, and they take nothing else first), so there is no inversion. - `copy_simple` returning early on an unknown kind is better than the old behaviour: with `step = 0`, every `mirror(dst)` call hit the same handle. - `count * bytes` in `resolve_queries` cannot overflow (u32 × at most 88 fits in u64), so `checked_add` on the offset alone is enough. AI-assisted (Claude Code).
upstream-sync closed this pull request 2026-11-25 01:02:34 +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
Marvisak/VIctory!52
No description provided.