D3D12.X: concurrent COM use-after-free (AddRef on freed ID3D12Resource) in title_textures and res_release #1359
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#1359
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-24 15:12 UTC · original
Checked on
main(930e8b4).Problem
title_textures::TEXTURES(crates/xcl/src/hle/d3d12x/title_textures.rs:75-89) stores raw, un-AddRef'dID3D12Resource*pointers and revives them into owned handles viaID3D12Resource::from_raw_borrowed(&p).map(|r| r.clone())(IUnknown::AddRef) under theTEXTURESlock inrefresh_once(title_textures.rs:775) andclone_resources(title_textures.rs:298-305).In
real::res_release(crates/xcl/src/hle/d3d12x/real.rs:1547-1595), the COM refcount can drop to0and destroy/freethisbeforetitle_textures::forget(this as usize)runs at line1581:Two failure paths:
AddRefon freed vtable): Whenever a tracked texture has refcount 2 (e.g., title holds 1 ref andtitle_textures::upload_allholds 1 ref fromrefresh_once) and both threads enterres_releaseconcurrently, both failadd(this) == 2(as noted at line 1550) and the secondf(this)destroys/freesthiswhile it is still present inTEXTURESacross lines 1566–1580. WithXCL_LATE_RELEASE=0, every final release hits this window. Any concurrentrefresh_once,register,retire_overlapping, orforgetcallsr.clone()(AddRef) on the freed COM object.late_releaseenabled and no concurrent release): Betweenf(this)at line 1556 (held = true, refcount 1) andtitle_textures::forgetat line 1581,refresh_oncecanAddRefthis(1 -> 2) and scheduleupload_allwhileres_releasetears down itsvramtiles/arena andUMA_BUFFERSbacking.(Related to #1040 / #1070, which defer backing-memory teardown for held resources, but does not synchronize
TEXTURESremoval before the COM object itself is destroyed.)Suggested fix
Synchronize
title_texturesunregistration with final release sothisis removed fromTEXTURESbefore the underlyingReleasecan drop the COM refcount to zero (and before tearing downvram/UMA_BUFFERS).AI use: Antigravity (Gemini 4 Neon) performed the read-only source audit and drafted this issue; checked and verified on
930e8b4before opening.github-bot referenced this issue2026-11-26 04:52:56 +00:00
github-bot referenced this issue2026-11-26 04:59:09 +00:00
@Pipodi on GitHub · 2026-11-24 21:03 UTC · original
A data point from a retail-title run, which may be the same race seen from the texture's memory rather than its COM object. One occurrence; it did not repeat in the next run, which ended at 50 s for another reason.
Tree:
mainb9b6ea6with #929 (b3a969b) merged locally. #929 changes onlyhle/d3d12x/title_list.rs. RTX 4090 (driver 617.42), Windows 11, release build,XCL_PSO_WAIT_MS=50.What happened: at 34.57 s, while the title was presenting its loading screen at full rate, there was an unhandled
0xc0000005inVCRUNTIME140.dll+0x1cc66, a read at0xc49256000. The process then hung and was killed after 60 s of log silence. The address lies in the title's CPU memory; the log shows title textures in that range being "kept in step with 0xc49…". Symbolized with the build's PDB (return address − 1):So
refresh_oncewas detiling a tracked texture from its title VA (title_bytes(va, …)at :1180) after that memory had been released. This is consistent with a texture still registered inTEXTURESafter the title released it, which is what #1404 and #1527 address. I have not checked whether either PR covers this path (a read of the texture's title memory, notAddRefon the resource). I have not run either PR yet.AI use: Claude Code (Claude Opus 5.5) ran the run, symbolized the stack and wrote this comment.
@Anon64 on GitHub · 2026-11-25 00:28 UTC · original
Two more occurrences of the crash @Pipodi describes, on another machine: RTX 3060 12 GB (581.80), Windows 11 26200, release builds of
main20cf130+ #1818 andmain80f4819+ #253, retail title, A pressed every 4 s.0xc0000005inVCRUNTIME140.dll+0x1cc66(memcpy) ←gpu::tiling::Chain::detile_level(tiling.rs:438) ←title_textures::subresources(title_textures.rs:1182), at 36.7 s and 36.8 s, while the loading screen ran at full rate.0xc49076010and0xc490d0000, in the same range as yours (0xc49256000). The second is exactly on a 64 KiB boundary, so the copy ran onto a page that was no longer readable, aftertitle_byteshad found the whole range readable and borrowed it in place.title_bytesat title_textures.rs:1158 checksreadable(at, len)and then hands out a borrow of the title's memory. If the title frees or decommits that memory before the detile reads it, the read faults. That check-then-use gap is separate from the COM-reference race in this issue's description.Written with Claude Code (Claude Opus 5.5) from runs on this machine.
@Anon64 on GitHub · 2026-11-25 02:52 UTC · original
Follow-up to my two occurrences above: 0 in 20 on
maincbc296a. Same machine and setup: 20scripts/smoke.ps1runs of 60 s, A pressed every 4 s, default settings. Nodetile_level/VCRUNTIME140.dll+0x1cc66access violation, and no hang.The three crashes I saw were all on builds from
80f4819or earlier: two single-thread ones and one with five threads at once. Since thentitle_textures.rsgot #1986 (fb9d059, upload batches capped by count and 32 MiB), which would shorten the window betweentitle_bytesand the detile but does not close it. So I would read this as "much rarer here now", not fixed. #751's safe copy, or a lock around title-memory frees, still covers the gap itself.Written with Claude Code (Claude Opus 5.5) from runs on this machine.