Skip to content

d3d12_xs: slot 14 takes the console layout only for committed, writable descriptor memory - #1387

Closed
JoshRob297 wants to merge 1 commit into
ProjectLeonida:mainfrom
JoshRob297:fix/descriptor-heap-validated-console-layout
Closed

JoshRob297 wants to merge 1 commit into
ProjectLeonida:mainfrom
JoshRob297:fix/descriptor-heap-validated-console-layout

Conversation

@JoshRob297

Copy link
Copy Markdown

d3d12_xs: slot 14 takes the console layout only for committed, writable descriptor memory

Fixes #3.

The false positive reported here has a second shape after #4: a size-only guard accepts a plain PC
D3D12_DESCRIPTOR_HEAP_DESC whose trailing caller words happen to be (1, 32), so
GetCPUDescriptorHandleForHeapStart() returns address 1 (#1148). This replaces the shape test with a
check on the memory the console layout names.

What changes

runtime/shims/d3d12_xs_device.cpp

  • Adds committed_writable_range(address, bytes): walks the range with VirtualQuery, requiring every
    page to be MEM_COMMIT with PAGE_READWRITE or PAGE_WRITECOPY.
  • console_heap_range_plausible() now takes the heap's actual increment and accepts the console layout
    only when all of these hold:
    • address is a user-mode address (>= 0x10000, below the canonical user limit);
    • NumDescriptors != 0 and does not overflow;
    • size == 0 (caller left it unset) or size == NumDescriptors * increment, using
      GetDescriptorHandleIncrementSize(desc->Type) (32 for CBV/SRV/UAV and RTV, as measured);
    • [address, address + NumDescriptors * increment) is committed and writable.
  • When any condition fails, the call follows the PC path exactly as if the descriptor had no console
    trailer: no address is applied, and an ordinary PC heap is created.
  • Logs the accepted console address and size once per heap, so a run shows which layout was taken.

runtime/test/d3d12_console_descriptor_heap_test.cpp

Why this is a positive check, not a heuristic

The console layout is not identified by the bytes after the PC description; those bytes are the
caller's, and any readable non-zero word there is a coincidence. It is identified by what the pair
(address, size) claims: descriptor memory the title owns for this heap. That claim is checkable:

  • the range is the process's own committed memory (VirtualQuery, not a readable probe of one word);
  • it is writable, which descriptor memory must be and an unrelated readable buffer need not be;
  • its length is exactly the heap's length for this descriptor type.

A PC caller's trailing words are arbitrary. The only way they satisfy all three conditions is if the
caller really holds a committed, writable buffer of exactly NumDescriptors * increment bytes at the
word after its descriptor, which is the console layout's contract. The shapes that produced the
reported crashes — address 1, or an unbacked synthetic address with a matching size — are rejected by
construction, not by a threshold.

Negative control, measured: with the previous size-only rule restored, the new (1, 32) case takes
the console layout (descriptor heap takes the console address 0x1 (size 32)) and the test fails with
CPU start 0x1. With this change the same case reaches the PC path and both tests pass.

Measurement on the retail title

The call that motivated the console path carries, after the 16-byte PC description:

field value
address 0x10000
size 39845888
NumDescriptors 1245184
increment (CBV/SRV/UAV) 32
NumDescriptors * 32 39845888

[0x10000, 0x10000 + 39845888) is committed and writable in the title, so the validated check accepts
the layout and the heap keeps the console address. The same numbers pass the size comparison alone,
which is why the size rule was necessary but not sufficient.

Build and test

Base: upstream/main at 0f98d193c (the working mirror was 137 commits behind, so the branch was cut
from upstream to keep the patch applicable).

cmake -S runtime -B /tmp/b-desc --toolchain "$PWD/runtime/cmake/clang-cl-xwin.cmake" \
  -DXWIN_DIR=$HOME/.local/share/xwin-sdk -DCMAKE_BUILD_TYPE=Release \
  -DLEONIDA_BUILD_WINDOWS_RUNTIME=ON -DLEONIDA_VULKAN_HEADERS_FETCH=ON
cmake --build /tmp/b-desc --target d3d12_descriptor_test d3d12_console_descriptor_heap_test -j8

Built with clang-cl 23.1.4 + xwin, run under Wine 11.22 (Staging) on an Intel Graphics (MTL) Vulkan
device.

binary before (upstream main) after
d3d12_descriptor_test (ctest d3d12_descriptor) exit 0 exit 0
d3d12_console_descriptor_heap_test exit 0 exit 0
new (1, 32) regression with the size-only guard — exit 1, CPU start 0x1
new (1, 32) regression with this change — exit 0

The SEGFAULT in the report is GPU/driver-specific and does not reproduce on this Intel MTL box:
upstream main already exits 0 here, matching the report from another machine on current main. The
regression is therefore demonstrated by the (1, 32) case, which fails under the size-only guard and
passes here.

Not run: the full ctest suite (278+ tests), and the retail title on this machine. No game data is
included.

@JoshRob297

Copy link
Copy Markdown
Author

Closing this as superseded: main already carries console_heap_range_plausible (address and size non-zero, size == NumDescriptors * 32) plus the writability check through accessible_range, which is the same shape this PR proposed and the same one the issue asked for.

Two data points from running the retail title, in case they are useful for the tests behind it:

  • The call arrives with address 0x10000 and size 39845888, and 1245184 * 32 is exactly that, so the size rule holds on the real thing.
  • GetCPUDescriptorHandleForHeapStart must return that address: the title compares the value against 0x10000 right after creating the heap and breaks on int3 when they differ. The range is committed and writable at that point, so a strict check like yours accepts it.

One difference worth keeping in mind: this PR accepted size == 0 as "no size word" and fell back to the PC path; yours requires a non-zero size. I have not seen a call with a zero size word, so strict is probably right.

Nothing else here is needed.

@JoshRob297 JoshRob297 closed this Nov 25, 2026
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.

slot 14: a normal 16-byte descriptor heap description is read as the console layout, and d3d12_descriptor SEGFAULTs

1 participant