descriptor/host.rs: FLIPS and NEW_PENDING keyed by HostHeap address; a heap at a reused address can read freed memory #232

Open
opened 2026-11-26 12:15:59 +00:00 by github-bot · 0 comments
Owner

@⁠kekonn on GitHub · 2026-11-26 12:11 UTC · original

crates/victory-gpu/src/descriptor/host.rs keys pending slot flips and pending new textures by std::ptr::from_ref(self) as usize (lines 2388, 2416, 2435, 3364, 3386). texture_slots_flip drains only entries whose f.heap == own and keeps every other entry for good (~2435-2438).

Drop for Heap (descriptor.rs ~834-841) removes the heap only from SHADER_HEAPS, and HostHeap has no Drop. If a shader-visible heap is freed while a flip is pending, and a new heap later lands at the same address, the new heap's texture pass treats the old flip as its own. It then evaluates record_key(f.handle) (~2462) on the old heap's handle, a read of freed memory (or an access violation if a large heap's pages were released).

When: the default path (VICTORY_SHOW_NEW_LATER is on), but it needs a heap freed mid-flip and then its address reused. Console titles normally keep their shader-visible heap for the whole run, so this is rare and has not been seen. Without address reuse the entries just stay forever (small).

Sketch (~18 lines): give HostHeap a unique id (from a static AtomicU64) and key on it instead of the address. Optionally add impl Drop for HostHeap that purges its FLIPS and NEW_PENDING entries.

Upstream: #72 turns HostHeap into Arc<HeapInner> with its own id and Drop, but does not re-key these. This fix should come after #72, or reuse its id. #142 carries an older copy of the same code.


Generated by Claude Code

**@⁠kekonn** on GitHub · 2026-11-26 12:11 UTC · [original](https://github.com/avatarmanz/VIctory-7900XTX/issues/232) `crates/victory-gpu/src/descriptor/host.rs` keys pending slot flips and pending new textures by `std::ptr::from_ref(self) as usize` (lines 2388, 2416, 2435, 3364, 3386). `texture_slots_flip` drains only entries whose `f.heap == own` and keeps every other entry for good (~2435-2438). `Drop for Heap` (`descriptor.rs` ~834-841) removes the heap only from `SHADER_HEAPS`, and `HostHeap` has no `Drop`. If a shader-visible heap is freed while a flip is pending, and a new heap later lands at the same address, the new heap's texture pass treats the old flip as its own. It then evaluates `record_key(f.handle)` (~2462) on the old heap's handle, a read of freed memory (or an access violation if a large heap's pages were released). **When:** the default path (`VICTORY_SHOW_NEW_LATER` is on), but it needs a heap freed mid-flip and then its address reused. Console titles normally keep their shader-visible heap for the whole run, so this is rare and has not been seen. Without address reuse the entries just stay forever (small). **Sketch (~18 lines):** give `HostHeap` a unique `id` (from a static `AtomicU64`) and key on it instead of the address. Optionally add `impl Drop for HostHeap` that purges its `FLIPS` and `NEW_PENDING` entries. **Upstream:** #72 turns `HostHeap` into `Arc<HeapInner>` with its own `id` and `Drop`, but does not re-key these. This fix should come after #72, or reuse its id. #142 carries an older copy of the same code. --- _Generated by [Claude Code](https://claude.ai/code)_
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 12:15:59 +00:00
This discussion has been locked. Commenting is limited to contributors.
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/avatarmanz--VIctory-7900XTX#232
No description provided.