startup: a view description at a readable page boundary loses the shim's view checks under the Agility headers #3538

Closed
opened 2026-11-30 02:28:11 +00:00 by github-bot · 0 comments
Owner

@⁠KelboLive on GitHub · 2026-11-30 02:26 UTC · original

startup: a view description at a readable page boundary loses the shim's view checks under the Agility headers

Summary

Two view-description reads in view_slot() take their length from the desktop struct's sizeof instead
of from the guest record. The Agility SDK 1.620.2 header makes D3D12_UNORDERED_ACCESS_VIEW_DESC 48 bytes
where the record the title supplies is 40, so when a description ends exactly at a readable page boundary
the 48-byte read fails readable() and the surrounding check is skipped rather than failing.

This is the third instance of the same assumption. #3512 (compute output tokens) and #3525 (pixel UAV views)
were the other two and are merged.

Sites

src/startup_stubs/d3d12_xs_device.cpp:

5608:  x2w_local::readable(described, sizeof(D3D12_UNORDERED_ACCESS_VIEW_DESC))   // 3D UAV
5614:  x2w_local::readable(described, sizeof(D3D12_UNORDERED_ACCESS_VIEW_DESC))   // 1D UAV
5650:  constexpr std::size_t view_bytes = N == 18 ? sizeof(D3D12_SHADER_RESOURCE_VIEW_DESC) :
5651:      N == 19 ? sizeof(D3D12_UNORDERED_ACCESS_VIEW_DESC) : ...
5653:  std::memcpy(desc_copy, args[desc_index], view_bytes);

The record width is already in the tree as ViewRecord::uav_desc_bytes and ViewRecord::srv_desc_bytes
(both 40, d3d12_capture.inl:55-56) and is what note_view() uses when it writes the record
(d3d12_xs_device.cpp:5586-5587), so the two sets of numbers disagree under the Agility header.

Consequence

  • 5608 / 5614: if the description sits at a page end, the readable() test fails and neither branch
    runs. The volume_uav_range_error() / 1D mip check is then skipped, so an out-of-range mip is
    accepted instead of refused. This is a missed validation, not a crash.
  • 5650 / 5653: the same failure skips the whole desc_copy block, so console-format mapping and the
    packed-target detection do not run for that view and it is created with the title's raw format.

There is also a plain over-read: memcpy(desc_copy, args[desc_index], 48) copies 8 bytes beyond a 40-byte
guest record into a local buffer. desc_copy is currently uninitialised
(alignas(D3D12_SHADER_RESOURCE_VIEW_DESC) unsigned char desc_copy[64];, line 5648), so those 8 bytes are
both read past the guest object and left indeterminate.

Why it has not been fixed yet

No test or run has produced this failure, because it needs a description placed at a page boundary. Under
the in-box headers sizeof is already 40, so both main CI jobs are also blind to it. Fixing it without a
repro would be a change with no failing case behind it, which this project asks contributors not to submit.

Suggested reproduction

  1. VirtualAlloc two pages and commit only the first.
  2. Place a 40-byte 3D UAV description at page_end - 40, so bytes 40..47 are in the uncommitted page, with
    Texture3D.MipSlice past the resource's mip count.
  3. Create a 3D texture that cannot take that mip and call view slot 19 with that pointer.
  4. Expect the existing refusal (an output 3D texture mip is outside the resource). Today the branch is
    skipped and the view is created.

The same shape covers 5650 by checking that a console format in the description is still mapped when the
description sits at the boundary.

Suggested fix

Use the record widths, as #3512 and #3525 do: ViewRecord::uav_desc_bytes / srv_desc_bytes, plus the
20-byte and 16-byte widths note_view() already uses for slots 20 and 21, with desc_copy zero-initialised
and the copy limited to the record width. A shared helper holding the width, the copy and the
static_assert would be the right shape, since this is the third site.

**@⁠KelboLive** on GitHub · 2026-11-30 02:26 UTC · [original](https://github.com/R0Y00/Xbox2Windows/issues/3536) # startup: a view description at a readable page boundary loses the shim's view checks under the Agility headers ## Summary Two view-description reads in `view_slot()` take their length from the desktop struct's `sizeof` instead of from the guest record. The Agility SDK 1.620.2 header makes `D3D12_UNORDERED_ACCESS_VIEW_DESC` 48 bytes where the record the title supplies is 40, so when a description ends exactly at a readable page boundary the 48-byte read fails `readable()` and the surrounding check is skipped rather than failing. This is the third instance of the same assumption. #3512 (compute output tokens) and #3525 (pixel UAV views) were the other two and are merged. ## Sites `src/startup_stubs/d3d12_xs_device.cpp`: ``` 5608: x2w_local::readable(described, sizeof(D3D12_UNORDERED_ACCESS_VIEW_DESC)) // 3D UAV 5614: x2w_local::readable(described, sizeof(D3D12_UNORDERED_ACCESS_VIEW_DESC)) // 1D UAV 5650: constexpr std::size_t view_bytes = N == 18 ? sizeof(D3D12_SHADER_RESOURCE_VIEW_DESC) : 5651: N == 19 ? sizeof(D3D12_UNORDERED_ACCESS_VIEW_DESC) : ... 5653: std::memcpy(desc_copy, args[desc_index], view_bytes); ``` The record width is already in the tree as `ViewRecord::uav_desc_bytes` and `ViewRecord::srv_desc_bytes` (both 40, `d3d12_capture.inl:55-56`) and is what `note_view()` uses when it writes the record (`d3d12_xs_device.cpp:5586-5587`), so the two sets of numbers disagree under the Agility header. ## Consequence - **5608 / 5614**: if the description sits at a page end, the `readable()` test fails and neither branch runs. The `volume_uav_range_error()` / 1D mip check is then skipped, so an out-of-range mip is **accepted** instead of refused. This is a missed validation, not a crash. - **5650 / 5653**: the same failure skips the whole `desc_copy` block, so console-format mapping and the packed-target detection do not run for that view and it is created with the title's raw format. There is also a plain over-read: `memcpy(desc_copy, args[desc_index], 48)` copies 8 bytes beyond a 40-byte guest record into a local buffer. `desc_copy` is currently uninitialised (`alignas(D3D12_SHADER_RESOURCE_VIEW_DESC) unsigned char desc_copy[64];`, line 5648), so those 8 bytes are both read past the guest object and left indeterminate. ## Why it has not been fixed yet No test or run has produced this failure, because it needs a description placed at a page boundary. Under the in-box headers `sizeof` is already 40, so both `main` CI jobs are also blind to it. Fixing it without a repro would be a change with no failing case behind it, which this project asks contributors not to submit. ## Suggested reproduction 1. `VirtualAlloc` two pages and commit only the first. 2. Place a 40-byte 3D UAV description at `page_end - 40`, so bytes 40..47 are in the uncommitted page, with `Texture3D.MipSlice` past the resource's mip count. 3. Create a 3D texture that cannot take that mip and call view slot 19 with that pointer. 4. Expect the existing refusal (`an output 3D texture mip is outside the resource`). Today the branch is skipped and the view is created. The same shape covers 5650 by checking that a console format in the description is still mapped when the description sits at the boundary. ## Suggested fix Use the record widths, as #3512 and #3525 do: `ViewRecord::uav_desc_bytes` / `srv_desc_bytes`, plus the 20-byte and 16-byte widths `note_view()` already uses for slots 20 and 21, with `desc_copy` zero-initialised and the copy limited to the record width. A shared helper holding the width, the copy and the `static_assert` would be the right shape, since this is the third site.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-30 02:28:11 +00:00
This discussion has been locked. Commenting is limited to contributors.
No milestone
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
github/R0Y00--Xbox2Windows#3538
No description provided.