era_gpu_alias: validate full committed span before calling D3D12 #1511

Merged
tedin7 merged 2 commits from upstream-pr/1518 into main 2026-11-24 14:17:59 +00:00
tedin7 commented 2026-11-24 13:30:00 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T13:30:00Z.


Summary

  • src/era_gpu_alias.cpp: in era_gpu_alias::open, validate that base + size does not wrap std::uintptr_t and walk [base, base + size) with VirtualQuery to verify every region in the span belongs to base's allocation (AllocationBase == base), is committed (MEM_COMMIT), has a valid non-zero region covering cursor, and is accessible (not PAGE_NOACCESS, PAGE_GUARD, or protection 0) before calling D3D12. Previously only the first MEMORY_BASIC_INFORMATION region was checked, allowing oversized spans, address-space wraps, partially committed reservations, and PAGE_NOACCESS/PAGE_GUARD tails to reach OpenExistingHeapFromAddress.
  • tests/gpu_alias.cpp: add negative controls for null device/base, zero size, oversized size, address-space wrap, partially committed reservations, and PAGE_NOACCESS / PAGE_GUARD committed tails.
  • tests/era_physical_check.cpp: add negative controls for invalid era_physical::allocate and era_physical::release arguments (null buffers, zero/oversized counts, invalid flags including upper 32 bits, out-of-range page numbers).

Verification

AI-assisted; commands listed were executed locally.

  • git diff --check origin/main...HEAD
  • python3 tests/docs_links_check.py
  • python3 tests/bidi_controls_check.py
  • Windows Server 2025 Debug & Release /O2 verification posted below.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6582893126 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1518). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T13:30:00Z. --- ## Summary - `src/era_gpu_alias.cpp`: in `era_gpu_alias::open`, validate that `base + size` does not wrap `std::uintptr_t` and walk `[base, base + size)` with `VirtualQuery` to verify every region in the span belongs to `base`'s allocation (`AllocationBase == base`), is committed (`MEM_COMMIT`), has a valid non-zero region covering `cursor`, and is accessible (not `PAGE_NOACCESS`, `PAGE_GUARD`, or protection `0`) before calling D3D12. Previously only the first `MEMORY_BASIC_INFORMATION` region was checked, allowing oversized spans, address-space wraps, partially committed reservations, and `PAGE_NOACCESS`/`PAGE_GUARD` tails to reach `OpenExistingHeapFromAddress`. - `tests/gpu_alias.cpp`: add negative controls for null `device`/`base`, zero `size`, oversized `size`, address-space wrap, partially committed reservations, and `PAGE_NOACCESS` / `PAGE_GUARD` committed tails. - `tests/era_physical_check.cpp`: add negative controls for invalid `era_physical::allocate` and `era_physical::release` arguments (null buffers, zero/oversized counts, invalid flags including upper 32 bits, out-of-range page numbers). ## Verification AI-assisted; commands listed were executed locally. - `git diff --check origin/main...HEAD` - `python3 tests/docs_links_check.py` - `python3 tests/bidi_controls_check.py` - Windows Server 2025 Debug & Release `/O2` verification posted below.
ChazY11 commented 2026-11-24 14:03:25 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by ChazY11 on 2026-11-24T13:37:38Z.


Ownership check is covered; the wrap guard turns out to be redundant with the span walk

Independent reviewer, not the author. Reviewed 57d3e2d5; nothing pushed to the branch. Mutations were made locally in
src/era_gpu_alias.cpp, rebuilt, reverted; working tree is clean.

Environment: Windows 11 build 26300.9974, MSVC 14.44.35207, SDK 10.0.26100.

cmake --preset dev
cmake --build --preset dev
ctest --preset dev --no-tests=error -R '^(era_physical_controls|era_physical_lifetime|gpu_alias_warp|gpu_alias_registry_warp)$' -V

4 of 4 pass, and era_physical_controls prints all seven policy/lenient rows as before.

Mutation A — the ownership half of the walk

-            info.AllocationBase != base || info.State != MEM_COMMIT || info.RegionSize == 0) {
+            info.State != MEM_COMMIT || info.RegionSize == 0) {
gpu_alias_warp .......... ***Failed
gpu_alias_registry_warp . ***Failed
era_physical_controls ... Passed
era_physical_lifetime ... Passed

Good: the AllocationBase == base requirement is what makes a foreign committed span fail, and two cases notice its
absence. That is the part of the change I most wanted to see exercised, and it is.

Mutation B — the wrap guard

-    if (size > (std::numeric_limits<std::uintptr_t>::max)() - start) {
+    if (false) {
gpu_alias_warp .......... Passed
gpu_alias_registry_warp . Passed

Nothing fails, and I do not read that as a coverage gap. The control that is meant to cover this is
open(device, base, UINT64_MAX, interior), and with the guard gone the VirtualQuery walk still refuses that input,
because the span cannot be committed past the end of the address space. So the two checks are redundant for the input you
test, and the fixture asserts the observable (refusal with E_INVALIDARG), not which check produced it.

Worth knowing rather than fixing: the wrap guard could be deleted without any test changing colour, so it is
belt-and-braces. If you want it to stay, a one-line comment saying it exists to reject the input before the walk touches
it would explain why both are there. If you would rather have it covered by its own observation, that needs a seam that
lets a test observe which branch refused — I would not add that for this.

Verdict

Reviewed 57d3e2d5. Builds clean, the four cases pass, the ownership check is genuinely exercised, and the only part not
distinguishable by the fixture is redundant rather than unprotected. No objection from me.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7133101762 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1518#issuecomment-7133101762). Originally posted by [ChazY11](https://github.com/ChazY11) on 2026-11-24T13:37:38Z. --- ## Ownership check is covered; the wrap guard turns out to be redundant with the span walk Independent reviewer, not the author. Reviewed `57d3e2d5`; nothing pushed to the branch. Mutations were made locally in `src/era_gpu_alias.cpp`, rebuilt, reverted; working tree is clean. Environment: Windows 11 build 26300.9974, MSVC 14.44.35207, SDK 10.0.26100. ```powershell cmake --preset dev cmake --build --preset dev ctest --preset dev --no-tests=error -R '^(era_physical_controls|era_physical_lifetime|gpu_alias_warp|gpu_alias_registry_warp)$' -V ``` 4 of 4 pass, and `era_physical_controls` prints all seven policy/lenient rows as before. ### Mutation A — the ownership half of the walk ```diff - info.AllocationBase != base || info.State != MEM_COMMIT || info.RegionSize == 0) { + info.State != MEM_COMMIT || info.RegionSize == 0) { ``` ```text gpu_alias_warp .......... ***Failed gpu_alias_registry_warp . ***Failed era_physical_controls ... Passed era_physical_lifetime ... Passed ``` Good: the `AllocationBase == base` requirement is what makes a foreign committed span fail, and two cases notice its absence. That is the part of the change I most wanted to see exercised, and it is. ### Mutation B — the wrap guard ```diff - if (size > (std::numeric_limits<std::uintptr_t>::max)() - start) { + if (false) { ``` ```text gpu_alias_warp .......... Passed gpu_alias_registry_warp . Passed ``` Nothing fails, and I do not read that as a coverage gap. The control that is meant to cover this is `open(device, base, UINT64_MAX, interior)`, and with the guard gone the `VirtualQuery` walk still refuses that input, because the span cannot be committed past the end of the address space. So the two checks are redundant for the input you test, and the fixture asserts the observable (refusal with `E_INVALIDARG`), not which check produced it. Worth knowing rather than fixing: the wrap guard could be deleted without any test changing colour, so it is belt-and-braces. If you want it to stay, a one-line comment saying it exists to reject the input before the walk touches it would explain why both are there. If you would rather have it covered by its own observation, that needs a seam that lets a test observe which branch refused — I would not add that for this. ### Verdict Reviewed `57d3e2d5`. Builds clean, the four cases pass, the ownership check is genuinely exercised, and the only part not distinguishable by the fixture is redundant rather than unprotected. No objection from me.
tedin7 commented 2026-11-24 14:03:26 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T13:41:49Z.


Thanks @ChazY11 for the independent review and mutation testing! Good catch on Mutation B — the upfront uintptr_t wrap check is intentionally belt-and-braces to reject wrapping spans in O(1) before walking VirtualQuery and to keep the cursor + covered loop invariant overflow-free.

In 5f57a8d7 (rebased onto main), era_gpu_alias::open was also tightened to reject committed regions with PAGE_NOACCESS, PAGE_GUARD, or protection 0 (with matching negative controls in tests/gpu_alias.cpp), and local-path wording was removed from the PR body.


AI-assisted; commands listed were executed locally.

Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit 5f57a8d77a21de8f6475013f69c39edca46a6616:

  • Debug (--preset dev):
    • Build (cmake --build --preset dev --target offscreen_check era_physical_check era_title_gpu_alloc_check -- -j 6): 27.75s (configure 0.00s)
    • Test (ctest --preset dev -R '^(gpu_alias.*_warp|era_physical_|era_title_gpu_alloc)' --parallel 4 --no-tests=error --output-on-failure): 8/8 passed (0.35s: gpu_alias_lookup_writes_warp 0.06s, gpu_alias_warp 0.07s, gpu_alias_registry_warp 0.07s, era_physical_controls 0.01s, era_title_gpu_alloc 0.02s, gpu_alias_lookup_warp 0.05s, gpu_alias_window_warp 0.05s, era_physical_lifetime 0.27s)
  • Release /O2 (--preset release):
    • Build (cmake --build --preset release --target offscreen_check era_physical_check era_title_gpu_alloc_check -- -j 6): 39.00s (configure 0.00s)
    • Test (ctest --preset release -R '^(gpu_alias.*_warp|era_physical_|era_title_gpu_alloc)' --parallel 4 --no-tests=error --output-on-failure): 8/8 passed (0.20s: gpu_alias_window_warp 0.04s, gpu_alias_lookup_writes_warp 0.06s, gpu_alias_lookup_warp 0.06s, era_title_gpu_alloc 0.01s, era_physical_controls 0.01s, era_physical_lifetime 0.11s, gpu_alias_warp 0.05s, gpu_alias_registry_warp 0.06s)
  • sccache: 90/100 hits; wall 72.9s
<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7133203000 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1518#issuecomment-7133203000). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T13:41:49Z. --- Thanks `@ChazY11` for the independent review and mutation testing! Good catch on Mutation B — the upfront `uintptr_t` wrap check is intentionally belt-and-braces to reject wrapping spans in O(1) before walking `VirtualQuery` and to keep the `cursor + covered` loop invariant overflow-free. In `5f57a8d7` (rebased onto `main`), `era_gpu_alias::open` was also tightened to reject committed regions with `PAGE_NOACCESS`, `PAGE_GUARD`, or protection `0` (with matching negative controls in `tests/gpu_alias.cpp`), and local-path wording was removed from the PR body. --- AI-assisted; commands listed were executed locally. Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit `5f57a8d77a21de8f6475013f69c39edca46a6616`: - **Debug (`--preset dev`)**: - Build (`cmake --build --preset dev --target offscreen_check era_physical_check era_title_gpu_alloc_check -- -j 6`): `27.75s` (configure `0.00s`) - Test (`ctest --preset dev -R '^(gpu_alias.*_warp|era_physical_|era_title_gpu_alloc)' --parallel 4 --no-tests=error --output-on-failure`): **8/8 passed** (`0.35s`: `gpu_alias_lookup_writes_warp` `0.06s`, `gpu_alias_warp` `0.07s`, `gpu_alias_registry_warp` `0.07s`, `era_physical_controls` `0.01s`, `era_title_gpu_alloc` `0.02s`, `gpu_alias_lookup_warp` `0.05s`, `gpu_alias_window_warp` `0.05s`, `era_physical_lifetime` `0.27s`) - **Release `/O2` (`--preset release`)**: - Build (`cmake --build --preset release --target offscreen_check era_physical_check era_title_gpu_alloc_check -- -j 6`): `39.00s` (configure `0.00s`) - Test (`ctest --preset release -R '^(gpu_alias.*_warp|era_physical_|era_title_gpu_alloc)' --parallel 4 --no-tests=error --output-on-failure`): **8/8 passed** (`0.20s`: `gpu_alias_window_warp` `0.04s`, `gpu_alias_lookup_writes_warp` `0.06s`, `gpu_alias_lookup_warp` `0.06s`, `era_title_gpu_alloc` `0.01s`, `era_physical_controls` `0.01s`, `era_physical_lifetime` `0.11s`, `gpu_alias_warp` `0.05s`, `gpu_alias_registry_warp` `0.06s`) - `sccache`: 90/100 hits; wall `72.9s`
chatgpt-codex-connector[bot commented 2026-11-24 14:03:26 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T13:42:00Z.


Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-24T13:45:05.337878Z 5f57a8d Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7133207660 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1518#issuecomment-7133207660). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T13:42:00Z. --- <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"5f57a8d77a21de8f6475013f69c39edca46a6616","has_any_findings":false,"has_unresolved_findings":false,"status":"completed"},"security_review":{"commit_sha":null,"has_any_findings":null,"has_unresolved_findings":null,"status":null}} --> <details> <summary><strong>Codex Review Summary</strong>: ✅ Completed</summary> This comment shows the latest Codex review activity on this pull request. | Review | Status | Commit | Review trigger | | --- | --- | --- | --- | | 📝 **Code Review** | ✅ **Completed** <relative-time datetime="2026-11-24T13:45:05.337878Z">2026-11-24T13:45:05.337878Z</relative-time> | `5f57a8d` | Draft marked ready | <details> <summary>ℹ️ About Codex in GitHub</summary> <br/> [Your team has set up Codex to review pull requests in this repo](https://chatgpt.com/codex/cloud/settings/general). Reviews are triggered when you - Open a pull request for review - Mark a draft as ready - Comment "@codex review" or "@codex security review". Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. </details> </details>
upstream-sync closed this pull request 2026-11-24 15:01:49 +00:00
Sign in to join this conversation.
No reviewers
No labels
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.

Reference
R0Y00/Xbox2Windows!1511
No description provided.