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

Merged
Lewandox merged 1 commit from upstream-pr/398 into main 2026-11-26 17:14:58 +00:00
Lewandox commented 2026-11-26 17:08:52 +00:00 (Migrated from github.com)

Imported from LooperSalty/AnyXboxX. Originally posted by Lewandox on 2026-11-26T17:08:52Z.


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
<!-- greyfinch-sync:LooperSalty/AnyXboxX:issue:6631641206 --> Imported from [LooperSalty/AnyXboxX](https://github.com/LooperSalty/AnyXboxX/pull/398). Originally posted by [Lewandox](https://github.com/Lewandox) on 2026-11-26T17:08:52Z. --- ## 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`
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
LooperSalty/AnyXboxX!398
No description provided.