KernelX: reject cross-allocation boundary overruns in map_pages (#1488) #1635

Open
github-bot wants to merge 1 commit from github-bot/gh-1635 into main AGit
Owner

@⁠slopgobblercobbler on GitHub · 2026-11-24 18:27 UTC · original
slopgobblercobbler:fix/phys-pages-boundary → main · +88 −4 · 1 files · 1 commits · open

Summary

Rejects cross-allocation boundary overruns in kernelx::map_pages in crates/xcl/src/hle/kernelx.rs (Issue #1488, finding XCL-BT-007):

  1. Physical allocation boundary validation:
    • Factored out page_block(page: usize) -> Option<(usize, usize, usize, usize)> helper to safely retrieve (first_index, count, live, home) from PHYS_BLOCKS.
    • In map_pages: for consecutive page requests (consecutive == true), validates that the requested range [first_idx..first_idx + n] does not cross or overrun the enclosing PHYS_BLOCKS allocation boundary (end_index <= block_end).
    • If an allocation boundary overrun or cross-allocation crossing is detected, sets last error to ERROR_INVALID_PARAMETER (87) and returns null_mut(), preventing commit_homes from committing unallocated memory past allocation bounds.
  2. Unit tests:
    • Added unit test map_pages_rejects_cross_allocation_overrun: verifies valid sub-allocations within boundaries succeed; verifies consecutive ranges extending past block boundaries fail with ERROR_INVALID_PARAMETER; verifies cross-boundary ranges fail; and verifies overruns with explicit virtual addresses fail.

Changes

  • crates/xcl/src/hle/kernelx.rs:
    • page_block helper for allocation bounds queries.
    • Range validation against enclosing allocation bounds in map_pages.
    • Synthetic unit test verifying boundary enforcement.

Tested

  • Windows 11 x64, Rust MSVC stable.
  • cargo test -p xcl -- kernelx: 34 passed, 0 failed.
  • Clean diff: zero trailing whitespace, clean rebase on latest upstream/main, GPL-2.0-only compliant, zero retail game data or keys.

Not Tested

  • Retail title physical page mapping under severe low-memory page compaction.

AI Use

Co-Authored-By: Claude Code (Claude Opus 5.5) / Gemini Antigravity

**@⁠slopgobblercobbler** on GitHub · 2026-11-24 18:27 UTC · [original](https://github.com/xcl-dev/xcl/pull/1635) `slopgobblercobbler:fix/phys-pages-boundary` → `main` · +88 −4 · 1 files · 1 commits · open ## Summary Rejects cross-allocation boundary overruns in `kernelx::map_pages` in `crates/xcl/src/hle/kernelx.rs` (Issue #1488, finding `XCL-BT-007`): 1. **Physical allocation boundary validation**: - Factored out `page_block(page: usize) -> Option<(usize, usize, usize, usize)>` helper to safely retrieve `(first_index, count, live, home)` from `PHYS_BLOCKS`. - In `map_pages`: for consecutive page requests (`consecutive == true`), validates that the requested range `[first_idx..first_idx + n]` does not cross or overrun the enclosing `PHYS_BLOCKS` allocation boundary (`end_index <= block_end`). - If an allocation boundary overrun or cross-allocation crossing is detected, sets last error to `ERROR_INVALID_PARAMETER` (87) and returns `null_mut()`, preventing `commit_homes` from committing unallocated memory past allocation bounds. 2. **Unit tests**: - Added unit test `map_pages_rejects_cross_allocation_overrun`: verifies valid sub-allocations within boundaries succeed; verifies consecutive ranges extending past block boundaries fail with `ERROR_INVALID_PARAMETER`; verifies cross-boundary ranges fail; and verifies overruns with explicit virtual addresses fail. ## Changes - `crates/xcl/src/hle/kernelx.rs`: - `page_block` helper for allocation bounds queries. - Range validation against enclosing allocation bounds in `map_pages`. - Synthetic unit test verifying boundary enforcement. ## Tested - Windows 11 x64, Rust MSVC stable. - `cargo test -p xcl -- kernelx`: 34 passed, 0 failed. - Clean diff: zero trailing whitespace, clean rebase on latest `upstream/main`, GPL-2.0-only compliant, zero retail game data or keys. ## Not Tested - Retail title physical page mapping under severe low-memory page compaction. ## AI Use Co-Authored-By: Claude Code (Claude Opus 5.5) / Gemini Antigravity
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:00:07 +00:00
Author
Owner

@⁠Anon64 on GitHub · 2026-11-24 19:33 UTC · original

Regression run for this PR: head 52d87de, based on main 9e3831e. RTX 3060 12 GB (581.80, wave32), Windows 11 26200, release, XCL_NETWORK=0, A pressed every 4 s from 20 s, scripts/smoke.ps1 on a retail title for 60 s, in one batch with the main run.

main 9e3831e:

xcl-smoke v1
commit: 9e3831e1f570d3646e53ab753b19ec07eb8f1485
gpu: NVIDIA GeForce RTX 3060
title: retail-title
seconds: 60
exit: 0x0
frames shown: 1536 (PresentX 1536)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 97380 MB

this PR:

xcl-smoke v1
commit: 52d87def317c507a2970380a271cd4546b60f4e5
gpu: NVIDIA GeForce RTX 3060
title: retail-title
seconds: 60
exit: 0x0
frames shown: 1528 (PresentX 1529)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 96637 MB

No device removals or crashes; 99 % of main's frames, 99 % of its peak commit.

Peak commit on this machine is mostly the pipeline preload's DXC compiles (#1035) and varies from run to run, so it says little about this PR.

Not tested: the whole suite; whether the title reaches the changed code in these 60 s.

Written with Claude Code (Claude Opus 5.5) from runs on this machine.

**@⁠Anon64** on GitHub · 2026-11-24 19:33 UTC · [original](https://github.com/xcl-dev/xcl/pull/1635#issuecomment-7142264164) Regression run for this PR: head `52d87de`, based on `main` `9e3831e`. RTX 3060 12 GB (581.80, wave32), Windows 11 26200, release, `XCL_NETWORK=0`, A pressed every 4 s from 20 s, `scripts/smoke.ps1` on a retail title for 60 s, in one batch with the `main` run. main `9e3831e`: ``` xcl-smoke v1 commit: 9e3831e1f570d3646e53ab753b19ec07eb8f1485 gpu: NVIDIA GeForce RTX 3060 title: retail-title seconds: 60 exit: 0x0 frames shown: 1536 (PresentX 1536) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 97380 MB ``` this PR: ``` xcl-smoke v1 commit: 52d87def317c507a2970380a271cd4546b60f4e5 gpu: NVIDIA GeForce RTX 3060 title: retail-title seconds: 60 exit: 0x0 frames shown: 1528 (PresentX 1529) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 96637 MB ``` No device removals or crashes; 99 % of main's frames, 99 % of its peak commit. Peak commit on this machine is mostly the pipeline preload's DXC compiles (#1035) and varies from run to run, so it says little about this PR. **Not tested:** the whole suite; whether the title reaches the changed code in these 60 s. Written with Claude Code (Claude Opus 5.5) from runs on this machine.
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-24 20:56 UTC · original

Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

  • cargo test -p xcl --lib: all passed, 0 failed, ~22 ignored.

Thanks!

**@⁠DavidM1911** on GitHub · 2026-11-24 20:56 UTC · [original](https://github.com/xcl-dev/xcl/pull/1635#issuecomment-7144255045) Verification on RTX 3060 Ti (Windows 11), branch merged with current `main`: - `cargo test -p xcl --lib`: all passed, 0 failed, ~22 ignored. Thanks!
@ -2116,0 +2144,4 @@
#[test]
fn map_pages_rejects_cross_allocation_overrun() {
unsafe {
let Some(_u) = crate::gpu::uma::get() else { return };
Author
Owner

@⁠gut0to on GitHub · 2026-11-24 18:31 UTC · original

When UMA is unavailable this test returns normally, so the test harness counts it as passed rather than skipped. CONTRIBUTING.md asks GPU-dependent tests to call gpu::recomp::runner::skip_test(...) before returning when the adapter cannot run them. Could this report an appropriate skip reason here so the workspace totals distinguish skipped coverage from a pass? AI-assisted review; I verified the test path and guide.

**@⁠gut0to** on GitHub · 2026-11-24 18:31 UTC · [original](https://github.com/xcl-dev/xcl/pull/1635#discussion_r4684703714) When UMA is unavailable this test returns normally, so the test harness counts it as passed rather than skipped. CONTRIBUTING.md asks GPU-dependent tests to call `gpu::recomp::runner::skip_test(...)` before returning when the adapter cannot run them. Could this report an appropriate skip reason here so the workspace totals distinguish skipped coverage from a pass? AI-assisted review; I verified the test path and guide.
Author
Owner

@⁠gut0to on GitHub · 2026-11-24 18:31 UTC · original · reviewed

AI-assisted review; I checked the unavailable-UMA path against the GPU test guidance.

**@⁠gut0to** on GitHub · 2026-11-24 18:31 UTC · [original](https://github.com/xcl-dev/xcl/pull/1635#pullrequestreview-6045085250) · **reviewed** AI-assisted review; I checked the unavailable-UMA path against the GPU test guidance.
Author
Owner

@⁠luckyteagirl on GitHub · 2026-11-26 09:40 UTC · original · reviewed

On 52d87de, the new same-allocation guard runs before the mapper chooses between its contiguous-home fast path and the per-page path. If two live allocations happen to receive adjacent page IDs, [A.last, B.first] is rejected even when the caller provides a separate reserved non-home destination. That destination already follows the per-page mapping path, which resolves each page's home independently; the same two allocations with nonconsecutive IDs still reach that path. The guard is needed for commit_homes, but this location also blocks a valid explicit mapping. The new test's explicit-address case uses an overrun/nonexistent ID, which does not cover two live adjacent blocks.

Could the same-allocation check apply only when selecting the home fast path, leaving explicit non-home VA to the per-page mapper? Open PR #1143 already has a contiguous_home helper that scopes this check and may be useful to coordinate with. A fixture with known adjacent live IDs should map both into a separate reserved VA and verify their contents/order, while a null/home request for the same pair and a genuinely nonexistent ID still fail. This is exact-head source review; I did not run a UMA fixture.

**@⁠luckyteagirl** on GitHub · 2026-11-26 09:40 UTC · [original](https://github.com/xcl-dev/xcl/pull/1635#pullrequestreview-6071716903) · **reviewed** On `52d87de`, the new same-allocation guard runs before the mapper chooses between its contiguous-home fast path and the per-page path. If two live allocations happen to receive adjacent page IDs, `[A.last, B.first]` is rejected even when the caller provides a separate reserved non-home destination. That destination already follows the per-page mapping path, which resolves each page's home independently; the same two allocations with nonconsecutive IDs still reach that path. The guard is needed for `commit_homes`, but this location also blocks a valid explicit mapping. The new test's explicit-address case uses an *overrun/nonexistent* ID, which does not cover two live adjacent blocks. Could the same-allocation check apply only when selecting the home fast path, leaving explicit non-home VA to the per-page mapper? Open PR #1143 already has a `contiguous_home` helper that scopes this check and may be useful to coordinate with. A fixture with known adjacent live IDs should map both into a separate reserved VA and verify their contents/order, while a null/home request for the same pair and a genuinely nonexistent ID still fail. This is exact-head source review; I did not run a UMA fixture.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1635/head:github-bot/gh-1635'
git switch 'github-bot/gh-1635'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1635'
git switch 'github-bot/gh-1635'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1635'
git switch 'github-bot/gh-1635'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1635'
git switch 'main'
git merge --squash 'github-bot/gh-1635'
git switch 'main'
git merge --ff-only 'github-bot/gh-1635'
git switch 'main'
git merge 'github-bot/gh-1635'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.