GPU: return pinned HostTexture from alias_source to avoid source Release UAF #3245
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!3245
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3245"
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:24 UTC · original
fuzeofficlal:fix/gpu-alias-source-drop-uaf→main· +388 −33 · 5 files · 1 commits · openProblem
Use-after-free across
resource::alias_source→texture::alias_copy:resource::alias_source(placed: This)locksTEXTURES_AT, finds a GPU-written aliased textureaat the same backing address whosemade(a)differs frommade(placed), drops the clonedArc<HostTexture>and releasesTEXTURES_AT, and returns the raw unowned pointerSome(a)(This = *const Object) without taking a COM reference.Under legal multi-threaded D3D12 usage (for example, releasing a transient placed render target / UAV / depth resource on another thread while a recording thread draws with an incompatible-format aliased texture at the same address),
a->Release()removesafromTEXTURES_ATand freesBox<Resource>beforetexture::alias_copyruns.alias_copythen dereferences the freedResourcein bothresource::host_resource(from)andlist::ensure_state(list, from, COPY_SOURCE).Destination identity split under concurrent eviction in
texture::alias_copy:alias_copyseparately calledresource::host_resource(to),texture::host_writes(list, to), andlist::ensure_state(list, to, COPY_DEST). Because a title-written placed destination texture is evictable beforehost_writesruns at submission, a concurrentresource::evict_unused()between those calls could recreate a newHostTextureforhost_writesandensure_statewhileCopyTextureRegionwrote into the earlier, untransitioned and unpinnedID3D12Resource.Fix
resource::alias_source(placed: This)to returnOption<Arc<HostTexture>>, cloning the sourceArc<HostTexture>while still holdingTEXTURES_AT(whichResource::dropmust acquire before dropping fields or freeingBox<Resource>).HostList::transition_copy(&self, copy: &Arc<HostTexture>, wanted: u32)(preserving depth-twin routing viatwin::route) andlist::ensure_copy_statesoalias_copytransitions and retains pinnedArc<HostTexture>values directly without dereferencingfrom: This.texture::alias_copyto takefrom: &Arc<HostTexture>, pinto_copy = resource::host_copy(to)?once at entry (skipping self-copy ifArc::ptr_eq(from, &to_copy)), and use the same pinnedfromandto_copyacrossfirst_use,GetDesc,host_writes_copy,ensure_copy_state,CopyTextureRegion, and log deduplication.crates/victory-gpu/src/draw.rs(&a) and the null-view unit test incrates/victory-gpu/src/resource.rs.Verification
crates/victory-gpu/src/texture.rs:alias_copy_survives_source_resource_release_after_alias_source: reproduces the bug deterministically on unmodifiedmain(BC1 block (0, 0)reads[0, 0]instead of[0x3f800000, 0x40000000]afterRelease(src)and slot reuse) and passes with exact readback and zero D3D12 debug errors after the fix.alias_source_and_copy_handle_concurrent_release_and_destination_eviction: exercises a two-threadBarrier(2)race betweenalias_source+alias_copyandsrc->Release(), plusresource::give_up_now(dst)eviction betweenalias_sourceandalias_copy.VICTORY_D3D12_DEBUG=1 --features diagnostics), WARP (VICTORY_D3D12_DEBUG=1 --features diagnosticsand fullvictory-gpusuite: 248 passed, 0 failed, 1 ignored), both workspaceclippy -D warningsconfigurations,rustfmt --edition 2024, andxtaskpolicy::tests::repository_passes_policy.@Dukestar69 on GitHub · 2026-11-26 14:29 UTC · original · approved these changes
Reviewed the diff and verified locally on Windows 11 x64 (RTX 5090 + WARP):
Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
@KainanP on GitHub · 2026-11-26 14:50 UTC · original
Heads-up: #3258 (a per-draw CPU optimization) also adds a path that moves a host copy the caller already holds (
HostList::transition_held/list::ensure_held_state). It touches the same lines ofHostList::transitionandlist::ensure_stateas this PR'stransition_copy/ensure_copy_state, so the two conflict textually. Whichever lands second should use the other's helper. I'll rebase #3258 if this one goes in first.AI use: Claude Code (Claude Opus 5.5) drafted this comment.
@fuzeofficlal on GitHub · 2026-11-26 16:41 UTC · original
Thanks for the heads-up @KainanP! Sounds great — whichever lands first, the other can cleanly reuse the shared held-texture transition helper.
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.