D3D12.X: sparse::release_if_unused bypasses #2345 GPU fence quarantine on unpin, and place_buffer races FORGOTTEN pointer reuse across dev_create_reserved_resource #2457
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
goal:world-load
good first issue
help wanted
invalid
keep-open
off-goal
question
stale
test-only
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/xcl-dev--xcl#2457
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
@microwave805 on GitHub · 2026-11-25 19:30 UTC · original
Static audit on
main @ c7e1799found two critical tile-lifetime / GPU UAF bugs incrates/xcl/src/hle/d3d12x/sparse.rs(affecting #2345 and #1981). Part of #1773, Part of #1833.1. [Critical]
release_if_unusedbypasses #2345's GPU fence quarantine when a released placed buffer unpins a parked tilecrates/xcl/src/hle/d3d12x/sparse.rs:1411-1419(release_if_unused),1497-1518(flush_parked),1710-1730(forget_buffer,forget_in), andreal.rs:1692, 1705(res_release)flush_parked()(sparse.rs:1507-1509) unmaps parked tiles onself.queueand advancesself.fence, but skips adding any tile inself.pinnedtoquarantine_tiles.Bhits its last titleRelease,real.rs:1692callssparse::forget_buffer(B)immediately, beforelate_release::hold(B)(real.rs:1705) waits for in-flight GPU work referencingB.forget_in()(sparse.rs:1719-1730) decrementss.pinned[tile]to0and callss.release_if_unused(tile)(sparse.rs:1411-1419), which pushestiledirectly ontoself.freewithout waiting on eitherself.fence(the window unmap) orself.queue_fences(title queues still executing commands onB).Pis pinned by placed bufferB(in-flight on queueQ), its VA is decommitted and flushed byflush_parked(), thenBis released whileQis still reading/writingB→Pgoes straight toself.free, gets reallocated bytake_tile(), and is overwritten byupload_zeros/upload_dirtywhileQstill accessesB(GPU UAF / corruption / device removal).self.freeinrelease_if_unused, queue unpinned unused tiles in apending_quarantine: Vec<(u32, u32)>(avoidingq.Signalinsideres_releasewhere D3D12 may hold internal locks) and drainpending_quarantinethroughquarantine_tiles()inbefore_execute,take_tile, andflush_parked(and exclude pools withpending_quarantinetiles fromretire_free_pools).2. [Critical]
place_bufferholdsSTATEacrossdev_create_reserved_resource, racing withFORGOTTENpointer reusecrates/xcl/src/hle/d3d12x/sparse.rs:1647-1684(place_buffer),1688-1717(FORGOTTEN,lock_state,forget_released,forget_buffer),real.rs:1692, 1705,late_release.rs:102-112place_buffer()acquireslock_state()(drainingFORGOTTEN) at line 1648, then holdsSTATEacrossreal::dev_create_reserved_resource(...)(line 1667) before inserting the returned pointerrawintos.buffers(line 1681).STATEis held, another thread running finalReleaseon a resource at addressPcallssparse::forget_buffer(P)→STATE.try_lock()returnsWouldBlock, leavingPqueued inFORGOTTEN.Pis then freed (immediately underXCL_LATE_RELEASE=0, or synchronously insidelate_release::hold'sdrain_known(true)/ idle spin atlate_release.rs:105-109when queues are idle) and reused bydev_create_reserved_resourcefor the new placed bufferB2.place_bufferinsertss.buffers[P] = B2_tiles(also silently leakingB1's pins ifPwas previously a sparse buffer), releasesSTATE, and the very nextlock_state()drainsFORGOTTEN→forget_in(s, P)deletes liveB2and unpins all ofB2's tiles whileB2is active on the GPU.STATE(matchingvram::place_on_pages), or drainforget_released(&mut g)again right afterdev_create_reserved_resourcereturns and befores.buffers.insert(raw as usize, ...).AI use
main @ c7e1799and issue drafting.@razormontana on GitHub · 2026-11-25 20:16 UTC · original
I’ll take item 1 and keep the tile pool from making a newly unpinned tile available until the relevant fence retirement completes. I’ll add a synthetic allocator-state test for both the final-pin and fence completion orders.
Assisted by OpenAI Codex (GPT-6.2 Sol).
@thehollowedone on GitHub · 2026-11-26 00:11 UTC · original
Item 2 follow-up for the two open fixes: #2528 at
237882eand #2539 at23e129a. The #2539 test-only reproduction and control cover the ordering where an old object's final-Release notification arrives after a replacement has registered at the same COM address.I checked that ordering against #2528 separately. In its existing
a_buffer_released_during_a_placement_does_not_take_the_new_one_with_ittest, the only code change was movingFORGOTTEN.lock().unwrap().push(RES)from beforerecord_buffer(&mut g, RES, vec![new])to immediately after it. With that test-only change,cargo test -p xcl --lib a_buffer_released_during_a_placement_does_not_take_the_new_one_with_it -- --nocapture --test-threads=1failed 0 passed, 1 failed:the new buffer was let go(left: None,right: Some([(7, 2)])). After restoring the exact clean PR head, the same test passed 1/1.The production ordering is possible because the original COM
Releasereturns zero beforesparse::forget_bufferis called. Both current tests cover notifications delivered before the new registration; this added case is a synthetic bookkeeping check, not an observed driver race or retail title failure. A release identity captured before the driver can destroy the old object would let deferred cleanup target that object rather than whichever buffer currently occupies its address. Other address-keyed final-release cleanup may need the same ownership audit.Windows 11 build 26300, RTX 3080 Ti / 621.35, rustc 1.99.1. No game data or title run. AI use: Codex (GPT-6.2 Sol) ran the two test variants and drafted this report; GPT-6.2 Astra reviewed the ownership ordering.