D3D12.X: fix null device allocation info null-deref, overflow, and RowPitch truncation #1621
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1631"
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?
Imported from ivall/xcl. Originally posted by b3IKK on 2026-11-24T18:25:47Z.
Fixes three bugs in
crates/xcl/src/hle/d3d12x/null.rs:Device_GetResourceAllocationInfocomputeddescs.add(i * 56)even whendescswas null, dereferencing0x38oni = 1whenn >= 2(access violation).approx_size,new_resource,Device_GetResourceAllocationInfo, andDevice_GetCopyableFootprintsused unchecked arithmetic and aligned pointer dereferences on raw*const u8/*mut u8buffers, overflowing on large dimensions/widths and aborting on unaligned descriptors.Device_GetCopyableFootprintsmultiplied buffer widths by4and truncated((width * 4 + 255) & !255) as u32, turning a 1 GiB buffer'sRowPitchinto0.This guards
descs.is_null(), uses saturating arithmetic andread_unaligned/write_unaligned, treatsBUFFER(dim == 1) as 1 bpp, and clampsRowPitchtou32::MAX & !255.What is in it
crates/xcl/src/hle/d3d12x/null.rs: guard nulldescs, use saturating math and unaligned reads/writes inapprox_size,new_resource,Device_GetResourceAllocationInfo, andDevice_GetCopyableFootprints; clampRowPitchand handle 1-bpp buffers; add unit testnull_alloc_info_and_footprints_guard_null_and_overflow.Since the last push: rebased onto
main06c9f55; the only conflict wasstruct_returning_methods_take_the_buffer_first_or_second, a testmainhad added at the same place, and both are kept.Tested
stable-x86_64-pc-windows-msvc), DXC 1.9.2609.5, debug (scripts/test.ps1) and release (scripts/smoke.ps1).\scripts\test.ps1(cargo build --workspace+cargo test --workspace -- --test-threads=4): 1266 passed, 0 failed, 46 ignored (SKIPPED: the wave64 / direct-DXIL per-lane tests that need 64-lane hardware or a semantics mode this adapter refuses,no heap windows, andcannot disable the driver cache (Windows Developer Mode is required))cargo test -p xcl --lib hle::d3d12x::null::tests: 4 passed, 0 failedRegression run
main (
426a5a7, clean tree, no local changes):PR (
ef0cb29, clean tree, no local changes):(The main block is
426a5a7, an ancestor of the currentmain, from the same machine and data folder.)Not tested
AI use
main06c9f55, resolved the conflicts, ran the suite and thescripts/smoke.ps1pair at the head above.Imported from ivall/xcl. Originally posted by Belox17 on 2026-11-24T20:03:00Z.
Test report for
30418877on NVIDIA (RTX 3060 Ti): passes, and without the fix the test crashes with an access violationTested
30418877as is (base9e3831e), clean tree.null_alloc_info_and_footprints_guard_null_and_overflow) withcargo test -p xcl --lib <name>: 1 passed.cargo test --workspace -- --test-threads=4on the head: 777 passed, 0 failed, 41 ignored; its base9e3831eon the same machine: 776 passed, 0 failed, 41 ignored. SKIPPED on both:gpu_geometry_wave32_prefix_count_over_a_mask,gpu_wave32_program_in_wave64_hardware(no wave64),heap_window_out_of_memory_falls_back_to_the_switch_form(no heap windows).mainc160d86e(clean merge): 859 passed, 0 failed, 42 ignored;mainalone: 858 passed, 0 failed, 42 ignored, the same three SKIPPED as above.hle/d3d12x/null.rsreverted (test kept), the test process ends with0xc0000005(STATUS_ACCESS_VIOLATION).Not tested
AI use: Claude Code (Claude Opus 5.5) ran the commands on this machine and wrote this report from those runs.
Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-24T20:46:45Z.
Verification on RTX 3060 Ti (Windows 11), branch merged with current
main:cargo test -p xcl --lib: all passed, 0 failed, ~22 ignored. (Intermittent single-test flake under parallel scheduling; clean on single-threaded rerun — same flake seen on unmodifiedmain.)Thanks!
upstream-sync referenced this pull request2026-11-25 15:05:51 +00:00
Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-26T05:58:07Z.
Re-verification on RTX 3060 Ti (Windows 11), new head merged with current
main:cargo test -p xcl --lib: all passed, 0 failed, 27 ignored. The earlier merge conflict is resolved.Thanks!
— Devin
Imported from ivall/xcl. Originally posted by Decodere on 2026-11-27T14:46:30Z.
Independent desktop NVIDIA verification of PR #1631 at head
ef0cb29e0ac9513a1ee641013bc5bf1d23bab0aa(1commit; exact parent & merge-base:06c9f5505f63f10c5ec49ef932d75b2c28177324, pre-#2555ancestor ofmain).Environment
7956 MiBreported by D3D12, Wave32-only Ada), driver32.0.16.2114(NVIDIA621.14, WDDM 3.2)31.9 GiBusable), Windows 11 Home26200(Developer Mode off)rustc 1.100.0 (0ef1bc386 2026-11-09)MSVC, DXC1.9.2609.5,--releaseTargeted tests & build (
ef0cb29e)cargo test --release -p xcl --lib -- --nocapture null_alloc_info_and_footprints_guard_null_and_overflow(3 consecutive runs)1 passed; 0 failed; 0 ignored; 1222 filtered out× 3 (0.00s,0.00s,0.00s,0skipped)cargo test --release -p xcl --lib -- --nocapture hle::d3d12x::null::(3 consecutive runs)5 passed; 0 failed; 0 ignored; 1218 filtered out× 3 (0.02s,0.02s,0.02s,0skipped)cargo build --release -p xcl1m 40s, exit0,0new warnings innull.rs)Paired quiet 60 s retail smoke (
title: 29640639)Exact parent & merge-base (
06c9f5505f63f10c5ec49ef932d75b2c28177324, cached baseline on the same machine):PR #1631 (
ef0cb29e0ac9513a1ee641013bc5bf1d23bab0aa):Limits of coverage
null_alloc_info_and_footprints_guard_null_and_overflowand the fullhle::d3d12x::null::suite (5/5,0skipped) passed3/3, directly verifying the null-descriptor guard inDevice_GetResourceAllocationInfo, saturatingapprox_sizefor huge 2D textures, 1 GiB bufferRowPitchpreservation (1 << 30, no truncation to0), andu32::MAX & !255saturation on extreme widths inDevice_GetCopyableFootprints.0device removals,0crashes, steady 60 Hz); single-run frame/commit delta vs. the cached parent reflects normal startup variance.AI disclosure: test execution and report drafting assisted by Google Antigravity (Gemini 4 Neon).
Imported from ivall/xcl. Originally posted by ClosetPie107 on 2026-11-27T16:12:37Z.
Tested on AMD / Linux:
ef0cb29e(RX 9070 16 GB, RDNA4, Mesa 26.3.1 RADV; Ryzen 5 9600X, 32 GB; CachyOS; Proton Experimentalexperimental-11.0-20261112with vkd3d-proton masterec207194plus a local patch dropping thelpVtblchecks of command allocators and lists; DXC 1.9.2609.5; Rust 1.96.0,x86_64-pc-windows-gnudebug build, tests run under Wine)The head as it is (not merged onto current
main), with its base06c9f550as the baseline.Tests (
XCL_REQUIRE_GPU=wave64)cargo test -p xcl --lib -- hle::d3d12x::null:: --test-threads=1: 5 passed, 0 failed, 0 ignored (includesnull_alloc_info_and_footprints_guard_null_and_overflow).cargo test --workspace --no-fail-fast -- --test-threads=4with--skip compositor_blends_ui_plane_over_scene_plane --skip failed_restore_stops_before_importing_an_unbacked_window --skip grooming_leaves_a_window_under_1_gib_only_its_hole(here the first loses the RADV device, the other two run out of memory under Wine): lib 1181 passed, 16 failed, 26 ignored; base06c9f550(this PR's base) the same session: lib 1180 passed, 16 failed, 26 ignored. The failures are the same set as on the base. The other binaries fail the same 3 tests as on the base (e2e,pls_quota,predication_e2e).d3d12_resource_and_sync: its fence and queue test ended the process here, as it does on the base and most other trees in this setup.Not tested
AI use
Imported from ivall/xcl. Originally posted by thehollowedone on 2026-11-28T13:12:53Z.
Review of exact head ef0cb29: three overflow-boundary results remain in the null D3D12 device.
A local candidate uses one checked 64 KiB alignment helper for creation and allocation queries, checks the atomic VA reservation, and rejects an unrepresentable copy row instead of clamping it. It also leaves the resource output null on creation failure.
Test-only assertions on unchanged
ef0cb29: cargo test --offline --locked -j 4 -p xcl --lib null_ -- --nocapture --test-threads=1 -> 9 passed, 2 failed, 0 ignored. The failures were the invalid allocation-info result and the duplicate GPU VA. The footprint mismatch follows directly from the head's row-size and pitch expressions. With the candidate: the focused null-device module had 6 passed, 0 failed; cargo build --offline --locked -j 4 --workspace passed; git diff --check passed.Full workspace command on the RTX 3080 Ti: cargo test --offline --locked -j 4 --workspace --no-fail-fast -- --test-threads=4. Unchanged PR head: 1,265 passed, 1 failed, 46 ignored, 25 SKIPPED notices. Candidate: 1,266 passed, 1 failed, 46 ignored, the same 25 skips. The sole failure on both was console_mesh_caches_hlsl_compute_pass_in_memory_and_on_disk (DXIL not compiled yet). The extra pass is the added regression.
This is an uncommitted candidate on the PR head. A clean-head title smoke and integration with current main remain for the author after any change. Hardware: Windows 11 build 26300, RTX 3080 Ti / 621.35, Ryzen 7 9800X3D, rustc 1.99.1, DXC 1.8.2502.11. AI use: Codex (GPT-6.2 Astra) traced the boundary cases; Codex (GPT-6.2 Sol) wrote and tested the candidate and drafted this review.
Candidate diff (uncommitted)
```diff diff --git a/crates/xcl/src/hle/d3d12x/null.rs b/crates/xcl/src/hle/d3d12x/null.rs index cce5d484..0bb8f7c3 100644 --- a/crates/xcl/src/hle/d3d12x/null.rs +++ b/crates/xcl/src/hle/d3d12x/null.rs @@ -460,19 +460,29 @@ unsafe fn approx_size(desc: *const u8) -> usize { (width.max(1).saturating_mul(height).saturating_mul(depth).saturating_mul(16) / 3).min(256 << 20) }+fn aligned_resource_size(size: usize) -> Option {
+}
unsafe fn new_resource(desc: *const u8, ppv: *mut *mut c_void) -> HRESULT {
if ppv.is_null() {
return S_FALSE;
}
let o = new_obj(Kind::Resource);
if !desc.is_null() {
std::ptr::copy_nonoverlapping(desc, (*o).desc.as_mut_ptr(), 56);
}
*(*o).mem.lock().unwrap() = (0, size);
(*o).value.store(va, Ordering::Relaxed);
*ppv = o as *mut c_void;
S_OK
@@ -480,15 +490,23 @@ unsafe fn new_resource(desc: *const u8, ppv: *mut *mut c_void) -> HRESULT {
unsafe extern "system" fn Device_GetResourceAllocationInfo(a: *mut c_void, b: *mut c_void, _mask: u32, n: u32, descs: *const u8) -> *mut u64 {
let ret = this_and_ret(a, b).1 as *mut u64;
for i in 0..n as usize {
if !ret.is_null() {
ret
@@ -547,8 +565,15 @@ unsafe extern "system" fn Device_GetCopyableFootprints(
let height = if desc.is_null() { 1 } else { (desc.add(24) as *const u32).read_unaligned().max(1) };
let format = if desc.is_null() { 0 } else { (desc.add(32) as *const u32).read_unaligned() };
let bpp = if dim == 1 { 1u64 } else { 4u64 };
for i in 0..num as usize {
if !layouts.is_null() {
let l = layouts.add(i * 32);
@@ -886,7 +911,7 @@ mod tests {
// Null descs with n >= 2 must not compute null.add(56) and dereference 0x38.
let mut out = [99u64; 2];
alloc_info(dev, &mut out, 0, 2, std::ptr::null());
@@ -911,11 +936,36 @@ mod tests {
assert_eq!(row_pitch, 1u32 << 30, "1 GiB buffer RowPitch must not truncate to 0");
assert_eq!(row_size, 1u64 << 30);
Imported from ivall/xcl. Originally posted by throny on 2026-11-28T14:12:46Z.
merge-check claim
head:
ef0cb29e0aImported from ivall/xcl. Originally posted by throny on 2026-11-28T14:26:33Z.
merge-check
base:
b937fbabhead:
ef0cb29e0amerge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2141 passed, 1 failed, 48 ignored (26 SKIPPED lines). The one failure is gpu::dxil::msaa_tests::direct_msaa_loads_precede_get_dimensions, which fails on main without this PR too (reported on #3093) and in every tree of this batch; the nine failures main had since #2959 are gone at
b937fbab. I did not runb937fbabalone: the last base-only run ise13d6250(2130 passed, 10 failed, 48 ignored).review: an improvement, and all of it in the null device, which the default runtime does not use. The null-description guard fixes a real crash (with two or more descriptions the old code read through a null pointer). Three edge cases from an earlier review in the thread remain, none of them a regression: a buffer of the maximum width still wraps the fake address counter, so two later small resources can get the same fake address; a null description list returns size 0 where the maximum would say "invalid"; and for a buffer of 4 GiB or more the row size is the full row while the row pitch is clamped. A candidate patch for these is in the thread, without an answer.
performance: none.
verdict: safe to merge (the three edge cases as a follow-up)
hardware / tool and model: RTX 4080 16 GB (621.40), i9-12900K, Windows 11 26300, Rust 1.100.0, debug. Claude Code; merge, build and suite run by Claude Fable 5.2, diff review by Claude Opus 5.5 (every hunk read; nothing run on the GPU beyond the suite).
Imported from ivall/xcl. Originally posted by thehollowedone on 2026-11-29T04:41:46Z.
merge-check
base:
fa204595a4head:
ef0cb29e0amerge: clean (local merge commit fbe17b6b35e851016c03ba734de270691646044a; git diff --check clean)
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2607 passed, 3 failed, 49 ignored; SKIPPED: 26 notices (mainly no native wave64, plus unsupported f16 paths and no heap windows). The failing tests were console_mesh_caches_hlsl_compute_pass_in_memory_and_on_disk (1 failure) and two_pass_driver_cache_reuses_both_passes_and_recovers_corrupt_blobs (2 failed attempts within its test binary). Both reproduce at untouched base
fa204595in focused runs, with the same failure points; neither touches this PR's null-device path.review: I read the full one-file merge diff at ef0cb29. The null-description crash guard, unaligned descriptor accesses, saturating texture-size calculation, and 1 GiB buffer RowPitch result match the test that passed within the suite. The three extreme-width cases in my earlier review still need follow-up; this PR does not make them worse. The title smoke uses the real D3D12 backend and therefore does not exercise the null device.
performance: Paired 60 s smoke on the same anonymous title, debug binaries and XCL_PREPARE=0: base 1310 frames, 15082 MB peak commit; merged tree 1296 frames, 14658 MB. Both exited 0x0 with 0 device removals and 0 crashes; last three 2 s present counts were 61/61/60 and 60/61/60 respectively. One run each does not establish a performance difference. The changed null-device path is outside the default real-GPU runtime.
verdict: safe to merge (for this PR's tested scope; the previously reported extreme-width cases remain follow-up work)
hardware / tool and model: NVIDIA RTX 3080 Ti (621.35), Ryzen 7 9800X3D, Windows 11 build 26300, rustc 1.99.1 MSVC, DXC 1.8.2502.11, debug; Codex (GPT-6.2 Sol) ran the checks and reviewed the merge diff.