GPU: pin descriptor view resources against concurrent Resource::Release #3234
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!3234
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3234"
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 14:06 UTC · original
fuzeofficlal:fix/gpu-descriptor-view-drop-uaf→main· +403 −25 · 5 files · 1 commits · openProblem
descriptor::VIEWSstoresView::Shader(r, ...)andView::Unordered(r, counter, ...)as raw*const Resourcepointers without holding COM references. Bothdescriptor::view_atanddescriptor::viewdrop theVIEWSlock immediately after cloningView, leaving callers to dereference those raw resource pointers without synchronization against a concurrentID3D12Resource::Release()on another title thread.Under legal multi-threaded D3D12 usage — for example, when
descriptor::sync_heaps()scans a dirty 64 KiB page of a placed shader-visible heap containing an abandoned slot for a resource being concurrently released on a title thread, whenHostHeap::mirror()dropsself.madeto runprepare(&view), or whendescriptor::make_read()creates placed textures in parallel acrosscrate::texture::in_parallel—Resource::dropcan rundescriptor::forgetand deallocateBox<Resource>while the mirroring, read-back, or drawing thread still holds the clonedViewand subsequently dereferences it inprepare,note_address(buffer_bytes/texture_desc),make_marked(host_copy/buffer_bytes/title_format),null_for,viewed.set,view_addresses,evict,stamp_read,placed_texture, ordraw::State.Fix
object::try_add_refandobject::release_boxed_withincrates/victory-gpu/src/object.rs.resource::resource_release, invokedescriptor::forget(r as usize)viarelease_boxed_withbeforeBox::from_rawconstructs&mut Resource, so anytry_add_refunder theVIEWSlock either observesrefs == 0(and treats the view as stale) or increments a live reference count without racingBox::from_rawor deallocation.descriptor::PinnedView(aSend + SyncRAII guard storingresources: [usize; 2], implementingDeref<Target = View>andDebug, and releasing its pinnedResourceCOM references onDrop) returned bydescriptor::view_at,descriptor::pinned_view,HostHeap::mirror, andHostHeap::unmade_placed.r == counter) are pinned once.VIEWSis dropped before releasing the earlier pin soresource_releasenever re-entersVIEWS.HostHeap(mirror,view_addresses,evict,unmade_placed,stamp_read,describe_slot),descriptor::make_read(holdingVec<PinnedView>acrossin_paralleland dropping before re-lockingSHADER_HEAPS), anddraw.rsview lookups throughPinnedView.Verification
Added two regression tests in
crates/victory-gpu/src/descriptor/host.rs:descriptor::host::tests::mirrored_view_pins_its_resource_until_dropped: verifies that a mirrored texture SRV, a dual-resource(buffer, counter)UAV, and a self-counter UAV keep their resources alive across a concurrentRelease()(refs == 1) and complete final destruction (invalidating the view with zero leaked references) when thePinnedViewdrops. Fails deterministically onmain(left: 0, right: 1).descriptor::host::tests::concurrent_mirror_and_sync_survive_resource_release: 64-roundBarrier(2)multi-threaded race betweensync_slots/mirror/stamp_read/pinned_view/view_addressesand concurrentRelease()in alternating release orders (covering dual-resource partial-pin rollback), asserting zero crashes, zero deadlocks, zero leaked references, and zero D3D12 debug errors.Verified across all gates:
rustfmt --edition 2024, hardware D3D12 and WARP (includingVICTORY_D3D12_DEBUG=1 --features diagnostics), fullvictory-gpuWARP suite (248 passed, 0 failed, 1 ignored), workspaceclippy --all-targets(default and--all-features) with-D warnings, andxtaskrepository policy.@Dukestar69 on GitHub · 2026-11-26 14:53 UTC · original · approved these changes
Reviewed the diff and verified locally on Windows 11 x64 (RTX 5090 + WARP):
object::try_add_ref/release_boxed_with(runningdescriptor::forgetafter refcount reaches 0 and beforeBox::from_raw) and returning RAIIPinnedViewfrom descriptor lookups (dropping theVIEWSlock before releasing partial pins) cleanly closes the concurrentResource::ReleaseUAF race across descriptor mirroring, sync, and draw paths.cargo test -p victory-gpu --lib descriptor:: -- --test-threads=1 --skip dynamic_slots_are_held_until_released(RTX 5090): 23 passed, 0 failed (includingconcurrent_mirror_and_sync_survive_resource_releaseandmirrored_view_pins_its_resource_until_dropped).cargo test -p victory-gpu --lib draw:: -- --test-threads=1(RTX 5090): 20 passed, 0 failed.VICTORY_FORCE_WARP=1 cargo test -p victory-gpu --lib descriptor::host::tests:: -- --test-threads=1: 16 passed (only pre-existing #1744dynamic_slots_are_held_until_releasedfailed).cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.cargo clippy -p victory-gpu --features diagnostics --all-targets -- -D warnings: clean.cargo xtask policy: 191 files ok.Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
@oni-swr on GitHub · 2026-11-26 15:03 UTC · original
WARP verification at head
1b08f76c(main63bcca43as control).mirrored_view_pins_its_resource_until_droppedandconcurrent_mirror_and_sync_survive_resource_release: both pass on the head.mirrored_view_pins_its_resource_until_droppedfails (mirrored SRV must pin its texture against concurrent Release, left 0, right 1).concurrent_mirror_and_sync_survive_resource_releasecan't build on main as written becausedescriptor::pinned_viewdoesn't exist; withpinned_viewswapped forviewit passes on main, so on WARP that race test does not catch the bug without the fix. Only the pin test discriminates.Software adapter (WARP, Microsoft Basic Render Driver), not a physical GPU. Synthetic tests only, no game files. Run with
VICTORY_WARP=1 VICTORY_D3D12_WARP=1 cargo test -p victory-gpu --lib --features diagnostics -j 4and dxil.dll available. Test report only, no code changes.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.