Skip to content

D3D12.X: guard null and unreadable pointers in graphics and compute PSO hooks - #2297

Open
GustavoEllwanger wants to merge 1 commit into
xcl-dev:mainfrom
GustavoEllwanger:fix/d3d12x-pso-pointer-guards
Open

GustavoEllwanger wants to merge 1 commit into
xcl-dev:mainfrom
GustavoEllwanger:fix/d3d12x-pso-pointer-guards

Conversation

@GustavoEllwanger

@GustavoEllwanger GustavoEllwanger commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Follow-up to #2015 for the graphics and compute PSO hooks (CreateGraphicsPipelineState / CreateComputePipelineState).

What is in it

  • crates/xcl/src/hle/d3d12x/real.rs:
    • Adds a page-bounded C-string reader read_cstr_checked, shader/cached-PSO readability checks, validated input_layout_slice, and graphics_desc_has_unreadable_pointers / compute_desc_has_unreadable_pointers.
    • Rejects unreadable top-level desc, shader bytecode, CachedPSO, InputLayout (including overflowing NumElements and unreadable/unterminated SemanticName), and StreamOutput pointers in graphics_pso and dev_create_compute_pso with E_INVALIDARG instead of crashing inside D3D12Core or background copying.
    • Guards own_shader, own_compute, own_graphics, graphics_blob_key, and frame-trace layout logging against null SemanticName (CStr::from_ptr(null)), unreadable/overflowing InputLayout, and unreadable shader/desc pointers.
    • Guards *ppv dereferences in compute_container, translated_compute_pso_once (including the dispatch_chain and dred::label paths), and translated_graphics_pso_once with !ppv.is_null() && !(*ppv).is_null() (valid ppPipelineState == NULL probes return S_FALSE).
    • Adds unit tests in hle::d3d12x::real::pso_pointer_guard_tests.
  • crates/xcl/src/hle/d3d12x/device_x.rs: uses real::read_cstr_checked instead of raw CStr::from_ptr in note_base.
  • crates/xcl/tests/d3d12_pso_guards.rs: standalone integration tests (no game data, no vendor-specific skips) reproducing null SemanticName, unreadable/overflowing InputLayout, cross-page unterminated SemanticName, unreadable shader/CachedPSO/StreamOutput pointers, and unreadable top-level desc pointers via raw COM vtable calls.

Tested

  • Hardware / toolchain: AMD Ryzen 7 7700, Windows 11, Rust 1.95.0 (59807616e 2026-04-14), DXC 1.8.2502.11, debug build.
    • GPU 1: NVIDIA GeForce RTX 5060 (driver 32.0.16.1088)
    • GPU 2: AMD Radeon(TM) Graphics (RDNA2 iGPU, driver 32.0.21042.62)
  • Rebased cleanly onto origin/main afc5ee8 (head 5f084cc).
  • Fail-first before the fix (cargo test -p xcl --test d3d12_pso_guards -- --test-threads=1 on RTX 5060): both graphics_and_compute_pso_unreadable_shader_and_desc_pointers_return_invalidarg and graphics_pso_null_semantic_name_does_not_crash crashed with 0xc0000005 (STATUS_ACCESS_VIOLATION).
  • Post-fix targeted tests on 5f084cc:
    • cargo test -p xcl --lib hle::d3d12x::real::pso_pointer_guard_tests: 2 passed, 0 failed, 0 ignored.
    • XCL_ADAPTER=5060 cargo test -p xcl --test d3d12_pso_guards --test d3d12_mesh_stream -- --test-threads=1 (NVIDIA RTX 5060): d3d12_pso_guards 3 passed, d3d12_mesh_stream 3 passed (0 failed, 0 ignored, 0 skipped).
    • XCL_ADAPTER=Radeon cargo test -p xcl --test d3d12_pso_guards --test d3d12_mesh_stream -- --test-threads=1 (AMD Radeon RDNA2): d3d12_pso_guards 3 passed, d3d12_mesh_stream 3 passed (0 failed, 0 ignored, 0 skipped).
  • Full workspace suite on 5f084cc (XCL_ADAPTER=5060 cargo test --workspace -- --test-threads=4, NVIDIA RTX 5060): 1268 passed, 0 failed, 46 ignored (28 pre-existing runtime SKIPPED lines on wave32 NVIDIA / without D3D12 debug layer / Developer Mode / heap windows).

Not tested

  • Retail title run (scripts/smoke.ps1) on the rebased head 5f084cc: I do not have a retail title package on this machine (@Toons29 ran a clean 60 s RX 9070 pair on the pre-rebase head 5f0547e in comment, but rebasing onto afc5ee8 changed the head SHA). Any community tester with a retail title who can rerun paired scripts/smoke.ps1 blocks against afc5ee8 and 5f084cc is welcome to post them.
  • Non-Windows hosts and Intel GPUs.

AI use

  • Antigravity (Google Gemini): audited crates/xcl/src/hle/d3d12x/ for pointer/bounds safety bugs, implemented the guards in real.rs and device_x.rs, wrote the unit and integration tests, rebased onto afc5ee8, reproduced the pre-fix 0xc0000005 crashes, and ran the dual-GPU and workspace test suites.

@Toons29

Toons29 commented Nov 25, 2026

Copy link
Copy Markdown

Regression run of 5f0547e3 on the retail title, for this PR's Regression run section. Both blocks are from scripts/smoke.ps1 as printed, not edited: main on 1a0bbe3a, this PR on its head commit with no uncommitted changes, same title and time.

xcl-smoke v1
commit: 1a0bbe3a2ba91ea8f5b6fc29130a053868d3c9e6
gpu: AMD Radeon RX 9070
title: 34df7c50
seconds: 60
exit: 0x0
frames shown: 1628 (PresentX 1628)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14561 MB
xcl-smoke v1
commit: 5f0547e3c586ee44d330148ff83d5e9280ba53e7
gpu: AMD Radeon RX 9070
title: 34df7c50
seconds: 60
exit: 0x0
frames shown: 1630 (PresentX 1630)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14557 MB

Against the limits in CONTRIBUTING.md: 100 % of main's frames, 100 % of its peak commit, no crash, no device removal.

AMD Radeon RX 9070 (RDNA4, driver 32.0.32029.2010), Ryzen 7 7800X3D, 32 GB, Windows 11 build 26300, Rust 1.100.0, cargo build --release -p xcl, 60 s, XCL_NETWORK=0. This is a regression check only: it does not show whether the run reaches the code this PR changes.

AI use: Claude Code (Claude Opus 5.5) built both trees and ran scripts/smoke.ps1; a script posted this right after the run, with both blocks exactly as printed.

@GustavoEllwanger
GustavoEllwanger force-pushed the fix/d3d12x-pso-pointer-guards branch from 5f0547e to 5f084cc Compare November 25, 2026 13:46
@GustavoEllwanger

GustavoEllwanger commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor Author

Thanks @Toons29 for the earlier RX 9070 smoke run on \5f0547e! I had to rebase onto \main\ (\�fc5ee8) to resolve the conflict in
eal.rs\ after #1592 / #2080 merged (preserving \dred::label\ and \dispatch_chain\ and guarding *ppv\ there as well). Re-verified on RTX 5060 + AMD RDNA2 + full workspace (1268 passed, 0 failed, 46 ignored). New head is \5f084cc\ if anyone can rerun the paired smoke check on \5f084cc, it would be much appreciated!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants