GPU: guard bindless texture tracking and made_copy against concurrent Resource::drop #3213
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!3213
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3213"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@fuzeofficlal on GitHub · 2026-11-26 13:13 UTC · original
fuzeofficlal:fix/gpu-bindless-resource-drop-uaf→main· +224 −25 · 2 files · 1 commits · openProblem
In D3D12, a title may release a texture resource (
Release()) without first overwriting old shader-visible descriptor heap slots that previously viewed it, while another thread runs heap mirroring (HostHeap::mirror),descriptor::sync_heaps, or post-submissionHostHeap::stamp_read. Three coupled races betweenResource::drop,bindless::Viewed::set, andresource::made_copyallow freed*const Resourcepointers to survive and be dereferenced:Resource::drop:crate::bindless::forgetran before removing the texture fromTEXTURES_ATand beforecrate::descriptor::forget. Between those calls, a concurrent thread could still resolveView::Shader(r, _)and re-insertrintoViewed::inner.texturesafterbindless::forgethad already returned.bindless::Viewed::set:seen(view)resolvedSeen::Texture(r)before acquiringViewed::inner. IfResource::dropranbindless::forget(r)and freedBox<Resource>in that window,Viewed::setinserted the freed pointer intoinner.texturesandinner.slots, causing subsequentbindless::uploadssubmissions to dereference freed memory viaresource::made_copy.resource::made_copy: Callers holding a clonedView::Shader(r, _)after releasingVIEWS(bindless::seen,HostHeap::stamp_read) passed rawrdirectly toresource(this).host.lock(), dereferencing freed memory ifResource::dropcompleted concurrently.Fix
crates/victory-gpu/src/resource.rs:TEXTURES_AT(LiveTextures) alongsideby_memory(also avoiding a per-eviction temporaryHashSetallocation ingive_up).resource::is_live_texture(usize)and checkTEXTURES_ATunder lock insideresource::made_copybefore callingmade(resource(this)).Resource::dropto invalidate descriptor records (descriptor::forget) and remove the resource fromTEXTURES_ATbefore draining bindless registries (bindless::forget).crates/victory-gpu/src/bindless.rs:Viewed::set, after acquiringViewed::innerand clearing any previous entry forindex, verifycrate::resource::is_live_texture(r)before insertingSeen::Texture(r).Because
Resource::dropremoves the pointer fromTEXTURES_ATbefore acquiringViewed::innerinbindless::forget, andViewed::setchecksis_live_texturewhile holdingViewed::inner, any concurrentViewed::seteither finishes beforebindless::forgetremoves it or observes the texture no longer live and skips insertion. The lock order remains strictly acyclic (SHADER_HEAPS -> HostHeap::made -> Viewed::inner -> MEMORY -> TEXTURES_AT -> Resource::host).Verification
crates/victory-gpu/src/bindless.rs:concurrent_release_during_viewed_set_does_not_leave_dangling_texture(fails onmain, passes with this fix)release_before_viewed_set_and_made_copy_rejects_freed_texture--features diagnosticswithVICTORY_D3D12_DEBUG=1), WARP withVICTORY_D3D12_DEBUG=1, full WARPvictory-gpusuite (248 passed, 0 failed, 1 ignored),cargo clippy --workspace --all-targets --locked -- -D warnings(default and--all-features),rustfmt --edition 2024, andxtaskpolicy checks.@Dukestar69 on GitHub · 2026-11-26 13:29 UTC · original · approved these changes
Verified on RTX 5090 against
origin/main(63bcca4):cargo test -p victory-gpu --lib bindless:: -- --test-threads=1: passed.cargo test -p victory-gpu --lib resource:: -- --test-threads=1: 18/18 passed;descriptor::host::: 14/14 passed.cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.cargo xtask policy: 191 files ok.Cleanly guards bindless texture tracking and
made_copyagainst concurrentResource::drop.Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
@oni-swr on GitHub · 2026-11-26 13:49 UTC · original
WARP verification of head
92915c647fed37a42dbbf72561598c229be32ebe(on origin/main63bcca4; no earlier verification on this PR)Environment: Windows 11, no physical GPU used.
VICTORY_WARP=1andVICTORY_D3D12_WARP=1set in every process, with--features diagnostics(the host only honours the WARP switch in that build). A local probe (not committed) printed and asserted the host device's adapter:Microsoft Basic Render Driver, DXGI flags0x2(software).Commands (
-j 4,--locked,--test-threads=1):cargo test -p victory-gpu --features diagnostics --lib concurrent_release_during_viewed_setandrelease_before_viewed_set: 2 passedcargo test -p victory-gpu --features diagnostics --lib: 248 passed, 0 failed, 1 ignored (main: 246 passed, 0 failed, 1 ignored)Control (this head with only the two guards removed: the liveness re-check in
Viewed::setand theTEXTURES_ATcheck inmade_copy; test code andLiveTextureskept):concurrent_release_during_viewed_set_does_not_leave_dangling_texturefails (dangling texture remains inViewed::textures);release_before_viewed_set_and_made_copy_rejects_freed_textureaborts withSTATUS_HEAP_CORRUPTION(0xc0000374), i.e. the use-after-free the PR describes. Both tests catch the bug.Diff review: lock order
TEXTURES_ATthenResource::hostinmade_copymatchesgive_up, so no new inversion that I can see;Resource::dropnow removes the texture from the live set beforebindless::forget, which closes the window. A minor note only: liveness is by address, so a newResourceallocated at a freed one's address would passis_live_texture; that is no worse than before and not something these tests cover.AI-assisted: verification by Claude Code (Claude Sonnet 5.5).
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.