fix(victory-gpu): avoid TEXTURES self-deadlock and UAF in let_go_idle -> slot_evict #398

Manually merged
github merged 1 commit from github-bot/gh-398 into main 2026-11-26 17:19:47 +00:00 AGit
Owner

@⁠Lewandox on GitHub · 2026-11-26 17:08 UTC · original
Lewandox:fix/resource-slot-evict-deadlock → main · +136 −78 · 1 files · 1 commits · merged 2026-11-26 17:14 UTC

Summary

Fixes a guaranteed TEXTURES mutex self-deadlock (and a follow-on use-after-free window) in victory-gpu's let_go_idle -> slot_evict eviction path (third_party/victory/crates/victory-gpu/src/resource.rs), as flagged unchecked in docs/research/stutter-2026-11-26.md:

  1. Self-deadlock fix: let_go_idle previously acquired let all = textures(); and kept the TEXTURES mutex guard live across the slot_evict(...) call. Whenever VICTORY_SLOT_EVICT=1 was enabled and VRAM usage exceeded VICTORY_SLOT_EVICT_PERCENT (need > 0), slot_evict immediately called textures().iter() on the same thread, permanently deadlocking the submitting thread. The idle sweep loop now drops the TEXTURES guard before calling slot_evict_with.
  2. Use-after-free & lock-ordering safety in slot_evict_with:
    • Drops the TEXTURES lock after scanning candidates and before calling crate::descriptor::evictable_slots / crate::descriptor::evict_slots (avoiding holding TEXTURES across descriptor heap locks).
    • Re-acquires TEXTURES and verifies all.contains(&at) before dereferencing at as *const Resource during eviction, so a texture concurrently freed by Drop for Resource between the scan and eviction is safely skipped instead of causing a use-after-free.
    • Drops TEXTURES before calling crate::host::retire or crate::descriptor::texture_made.
  3. Regression test: Extracts let_go_idle_with / slot_evict_with and adds let_go_idle_with_slot_evict_above_threshold_does_not_deadlock verifying the full let_go_idle -> slot_evict path completes above threshold without deadlocking.

Verification

  • cargo test -p victory-gpu --lib resource::tests (default and --features diagnostics)
  • cargo xtask policy inside third_party/victory
**@⁠Lewandox** on GitHub · 2026-11-26 17:08 UTC · [original](https://github.com/LooperSalty/AnyXboxX/pull/398) `Lewandox:fix/resource-slot-evict-deadlock` → `main` · +136 −78 · 1 files · 1 commits · merged 2026-11-26 17:14 UTC ## Summary Fixes a guaranteed `TEXTURES` mutex self-deadlock (and a follow-on use-after-free window) in `victory-gpu`'s `let_go_idle` -> `slot_evict` eviction path (`third_party/victory/crates/victory-gpu/src/resource.rs`), as flagged unchecked in `docs/research/stutter-2026-11-26.md`: 1. **Self-deadlock fix**: `let_go_idle` previously acquired `let all = textures();` and kept the `TEXTURES` mutex guard live across the `slot_evict(...)` call. Whenever `VICTORY_SLOT_EVICT=1` was enabled and VRAM usage exceeded `VICTORY_SLOT_EVICT_PERCENT` (`need > 0`), `slot_evict` immediately called `textures().iter()` on the same thread, permanently deadlocking the submitting thread. The idle sweep loop now drops the `TEXTURES` guard before calling `slot_evict_with`. 2. **Use-after-free & lock-ordering safety in `slot_evict_with`**: - Drops the `TEXTURES` lock after scanning candidates and before calling `crate::descriptor::evictable_slots` / `crate::descriptor::evict_slots` (avoiding holding `TEXTURES` across descriptor heap locks). - Re-acquires `TEXTURES` and verifies `all.contains(&at)` before dereferencing `at as *const Resource` during eviction, so a texture concurrently freed by `Drop for Resource` between the scan and eviction is safely skipped instead of causing a use-after-free. - Drops `TEXTURES` before calling `crate::host::retire` or `crate::descriptor::texture_made`. 3. **Regression test**: Extracts `let_go_idle_with` / `slot_evict_with` and adds `let_go_idle_with_slot_evict_above_threshold_does_not_deadlock` verifying the full `let_go_idle` -> `slot_evict` path completes above threshold without deadlocking. ## Verification - `cargo test -p victory-gpu --lib resource::tests` (default and `--features diagnostics`) - `cargo xtask policy` inside `third_party/victory`
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 17:14:11 +00:00
github manually merged commit ef4791e62e into main 2026-11-26 17:19:47 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.