[PR #1387] [CLOSED] d3d12_xs: slot 14 takes the console layout only for committed, writable descriptor memory #1415

Closed
opened 2026-11-26 20:21:11 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/1387
Author: @JoshRob297
Created: 11/25/2026
Status: ❌ Closed

Base: main ← Head: fix/descriptor-heap-validated-console-layout


📝 Commits (1)

  • 60b0ead [PATCH] d3d12_xs: take the console slot-14 layout only for backed

📊 Changes

2 files changed (+91 additions, -14 deletions)

View changed files

📝 runtime/shims/d3d12_xs_device.cpp (+50 -13)
📝 runtime/test/d3d12_console_descriptor_heap_test.cpp (+41 -1)

📄 Description

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

  • The slot-14 case now allocates the range it describes with VirtualAlloc, instead of using the
    unmapped constant 0x556677880000. A console heap is backed by title memory; after this change an
    unbacked address is no longer a console heap, so the test has to hand it real memory.
  • Adds the regression from #3/#1148: an RTV heap with NumDescriptors = 1 followed by the words
    (1, 32) must reach the PC path, and its CPU heap start must not be 1.

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.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/1387 **Author:** [@JoshRob297](https://github.com/JoshRob297) **Created:** 11/25/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix/descriptor-heap-validated-console-layout` --- ### 📝 Commits (1) - [`60b0ead`](https://github.com/ubiquitarianism/leonida/commit/60b0ead5e0546360f7cee502e8ad65a29fab48fe) [PATCH] d3d12_xs: take the console slot-14 layout only for backed ### 📊 Changes **2 files changed** (+91 additions, -14 deletions) <details> <summary>View changed files</summary> 📝 `runtime/shims/d3d12_xs_device.cpp` (+50 -13) 📝 `runtime/test/d3d12_console_descriptor_heap_test.cpp` (+41 -1) </details> ### 📄 Description # 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` - The slot-14 case now allocates the range it describes with `VirtualAlloc`, instead of using the unmapped constant `0x556677880000`. A console heap is backed by title memory; after this change an unbacked address is no longer a console heap, so the test has to hand it real memory. - Adds the regression from #3/#1148: an RTV heap with `NumDescriptors = 1` followed by the words `(1, 32)` must reach the PC path, and its CPU heap start must not be 1. ## 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. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
4ld0 2026-11-26 20:21:11 +01:00
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
starred/leonida#1415
No description provided.