Repository navigation
D3D12.X: check pointer alignment in is_adopted before dereferencing (#1130) - #1139
GamingChelsea wants to merge 1 commit into
Conversation
|
Independent verification on current Machine: Windows 11, Ryzen 9 7900X + RTX 3060 Ti; Rust stable MSVC, debug.
AI use: test runs by Devin (Cognition, SWE-2); no code changes. |
towiice
left a comment
There was a problem hiding this comment.
Tested (as reporter of #1130):
- Hardware: NVIDIA GeForce GTX 1650 SUPER (Turing TU116, 4 GB VRAM, wave32, driver 610.88), Windows 11 x64 (26H2 / build 26300), DXC v1.9.2609 (
01b62ad4), toolchainstable-x86_64-pc-windows-gnullvm(llvm-mingw 23.1.6), debug build — the exact setup where #1130 aborted withSTATUS_STACK_BUFFER_OVERRUN. - Test command:
cargo test -p xcl --lib hle::d3d12x::real -- --test-threads=1 - Result: 19 passed, 0 failed (1.54 s), including the new
this_first_tests::misaligned_return_buffer_is_not_adopted_and_does_not_panic.
Checking pointer alignment before dereferencing cleanly fixes the misaligned-read UB in is_adopted(). Once this lands, we can also drop the #[repr(align(8))] workaround in #1132.
Not tested: full workspace suite, release builds, retail titles (smoke.ps1).
|
Tested on NVIDIA: passes
Note: #1132 adds an integration test with the same name, Not tested: AMD, any title (no smoke run). AI use: Claude Code (Claude Opus 5.5) ran the tests and wrote this report. |
|
Test report for head Tested
Not tested: retail titles (no smoke run), RDNA3/RDNA4. AI use: the tests were run and this report was written by an AI agent, Claude Code (Claude Opus 5.5), on the hardware above. The numbers are copied from the actual test output. |
|
A regression run under Wine on Linux, on a retail title. Tested
Regression run main (first run): this PR: The last Not tested
AI use
|
…vall#1142, ivall#1150, ivall#1156, ivall#1182, ivall#1191, ivall#1195, ivall#1221 Integrate 10 high-impact open upstream PRs on top of upstream/main (930e8b4): - ivall#1182: share video memory across render targets aliased onto one physical page (~1.85-2.1 GB VRAM saved) - ivall#1142: declare tiled texture pools texture-only (D3D12_HEAP_FLAG_DENY_BUFFERS) for vkd3d-proton - ivall#1097: report process memory under Wine via PagefileUsage fallback - ivall#1078: bound BCPack record scratch memory to 2 KiB stack batches - ivall#1150: convert console clear-value formats in CreatePlacedResource - ivall#1156: release the interface returned by QueryInterface in class_for - ivall#1139: check pointer alignment in is_adopted before dereferencing - ivall#1195: skip ExecuteIndirect dispatch of untranslated console compute pipelines - ivall#1191: VirtualProtect commits lazy pages in its range first - ivall#1221: unmark lazy away mappings in FreeTitlePhysicalPages Assisted-by: Antigravity (Google DeepMind)
…ll#1221, and updated Linux PRs Update fork README for upstream/main 930e8b4 (BCPack BC1-BC7, XCL_PSO_WAIT_MS, low-VA ASLR < 2^40, alloc_pool, sparse tile parking/pool reuse, direct page moves, write-watch merge), newly integrated PRs (ivall#1078, ivall#1097, ivall#1139, ivall#1142, ivall#1150, ivall#1156, ivall#1182, ivall#1191, ivall#1195, ivall#1221), and updated Linux PRs (ivall#867, ivall#871, ivall#877). Assisted-by: Antigravity (Google DeepMind)
|
Two contributors checked independently and found that #1522 solves the same problem (for #1130) in a different way: #1607, group D67. You may want to compare them with the other author and agree on one, or say in the PR why both are needed. This is a hint from the community triage in #1607, not a maintainer decision. AI use: Claude Code (Claude Opus 5.5), posted by a script from the #1607 table. |
…cl-dev#1130) is_adopted() previously dereferenced *(obj as *const usize) without checking pointer alignment. When this_first(a, b) inspects both arguments of a struct-returning device hook such as GetCustomHeapProperties (whose return buffer D3D12_HEAP_PROPERTIES is [u32; 5], 4-byte aligned), a 4-byte-aligned stack buffer triggers UB and aborts debug builds with a misaligned pointer dereference panic. Require pointer alignment in is_adopted() before readable() and the vtable read (adopted COM objects are always pointer-aligned), cache the this_first() result once in get_resource_allocation_info2_x(), and add unit and host-driver ABI parity tests for 4-byte-aligned return buffers in both C++ and C calling conventions. Fixes xcl-dev#1130 Assisted-by: Antigravity (Gemini 4 Neon)
20a893f to
63afbb8
Compare
Fixes #1130.
d3d12x::real::is_adoptedpreviously dereferenced*(obj as *const usize)without checking pointer alignment. Becausethis_first(a, b)probes both arguments of struct-returning device hooks — includingGetCustomHeapProperties(slot 26, returning[u32; 5], 4-byte aligned) — passing a 4-byte-aligned return buffer caused undefined behavior and aborted debug builds with a misaligned pointer dereference panic.What is in it
crates/xcl/src/hle/d3d12x/real.rs: require pointer alignment ((obj as usize) & (std::mem::align_of::<usize>() - 1) == 0) inis_adoptedbeforereadable()and the vtable read (adopted COM objects are always pointer-aligned); add unit testthis_first_tests::misaligned_return_buffer_is_not_adopted_and_does_not_paniccovering 4-byte-aligned stack buffers (including one containing a stale vtable copy).crates/xcl/src/hle/d3d12x/device_x.rs: cachereal::this_first(a, b)once inget_resource_allocation_info2_x; add GPU host-driver parity testcustom_heap_properties_match_host_in_cpp_and_c_abiverifyingget_custom_heap_properties_xin both C++(this, ret, ...)and C(ret, this, ...)ABI orders with a 4-byte-aligned[u32; 5]return buffer.Tested
rustc 1.100.0 (0ef1bc386 2026-11-09), debug (tests) and release (smoke).cargo test --workspace -- --test-threads=1: 1267 passed, 0 failed, 46 ignored.SKIPPEDGPU tests on this adapter: 25 (22 wave64-onlyno wave64skips + 3#1426f16/f32 direct-DXIL per-lane skips).Regression run
main:
PR head:
Not tested
stable-x86_64-pc-windows-gnullvmtoolchain (tested onstable-x86_64-pc-windows-msvc).AI use
this_firstcaching, wrote the unit and host-driver ABI parity tests, rebased onto06c9f55, ran the workspace test suite and smoke regression, and updated this PR description.