startup: reject a writable range whose size wraps the address space #1524

Manually merged
github merged 1 commit from gh-pr/1524/head into gh-pr/1524/base 2026-11-26 23:14:03 +00:00
Owner

@⁠RenzoWit35 on GitHub · 2026-11-24 13:37 UTC · original
RenzoWit35:startup/local-log-probe-range → main · +9 −1 · 2 files · 1 commits · merged 2026-11-24 14:26 UTC

Change

x2w_local::accessible in src/startup_stubs/local_log.h (behind readable and writable) checked the write path with start + bytes > end, where end is the end of the region VirtualQuery returned. For a size near SIZE_MAX the sum wraps below end, so the check passed and writable(p, SIZE_MAX - 8) returned true for something that is not a range. No earlier guard catches it: only a start below 0x10000, a start above the user limit and a zero size are rejected.

The read path was not affected. probe_readable computes its own end = start + bytes, which wraps too, so its loop does not run and it reports zero bytes.

The comparison is now bytes > end - start. start lies inside the queried region, so that difference cannot wrap. Nothing else in the header changes.

This builds on the test added in #1477: tests/startup_local_log_check.cpp gains three wrapping-size checks next to its other boundary cases. No new test target.

Verification

Windows 11, MSVC 14.51.36231, cmake --preset dev, base origin/main 60c72330.

cmake --build out/build/dev --target startup_local_log_check
ctest --test-dir out/build/dev --no-tests=error -R '^startup_local_log' --timeout 120

Negative control, with local_log.h from main and the three new checks:

FAIL accessible rejects a size that wraps start + bytes (GetLastError=0)
FAIL writable rejects SIZE_MAX bytes (GetLastError=0)
FAIL writable rejects a wrapping size from inside the region (GetLastError=0)
startup_local_log: 3 of 78 FAILED

With the fix: startup_local_log Passed and startup_local_log_guard_drop_control Passed (2/2).

Not run: the other startup tests, GPU tests and the full suite. I did not search for a caller that passes such a size today; the change makes the helper's answer correct for any size.

Evidence and follow-up

The inputs are sizes computed in the test against pages it allocates itself; no external data.

AI-assisted.

**@⁠RenzoWit35** on GitHub · 2026-11-24 13:37 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1524) `RenzoWit35:startup/local-log-probe-range` → `main` · +9 −1 · 2 files · 1 commits · merged 2026-11-24 14:26 UTC ## Change `x2w_local::accessible` in `src/startup_stubs/local_log.h` (behind `readable` and `writable`) checked the write path with `start + bytes > end`, where `end` is the end of the region `VirtualQuery` returned. For a size near `SIZE_MAX` the sum wraps below `end`, so the check passed and `writable(p, SIZE_MAX - 8)` returned true for something that is not a range. No earlier guard catches it: only a start below 0x10000, a start above the user limit and a zero size are rejected. The read path was not affected. `probe_readable` computes its own `end = start + bytes`, which wraps too, so its loop does not run and it reports zero bytes. The comparison is now `bytes > end - start`. `start` lies inside the queried region, so that difference cannot wrap. Nothing else in the header changes. This builds on the test added in #1477: `tests/startup_local_log_check.cpp` gains three wrapping-size checks next to its other boundary cases. No new test target. ## Verification Windows 11, MSVC 14.51.36231, `cmake --preset dev`, base `origin/main` 60c72330. ``` cmake --build out/build/dev --target startup_local_log_check ctest --test-dir out/build/dev --no-tests=error -R '^startup_local_log' --timeout 120 ``` Negative control, with `local_log.h` from `main` and the three new checks: ``` FAIL accessible rejects a size that wraps start + bytes (GetLastError=0) FAIL writable rejects SIZE_MAX bytes (GetLastError=0) FAIL writable rejects a wrapping size from inside the region (GetLastError=0) startup_local_log: 3 of 78 FAILED ``` With the fix: `startup_local_log` Passed and `startup_local_log_guard_drop_control` Passed (2/2). Not run: the other startup tests, GPU tests and the full suite. I did not search for a caller that passes such a size today; the change makes the helper's answer correct for any size. ## Evidence and follow-up The inputs are sizes computed in the test against pages it allocates itself; no external data. AI-assisted.
x2w_local::accessible compared start + bytes with the end of the queried
region. For a size near SIZE_MAX the sum wraps below the end, so
writable(p, SIZE_MAX - 8) returned true for a range that is not a range.
The read path was not affected: its own end wraps too and it reports
zero bytes.

Compare bytes with end - start instead. start lies inside the queried
region, so that difference cannot wrap.

tests/startup_local_log_check.cpp gains three wrapping-size checks next
to its other boundary cases.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 23:14:00 +00:00
github manually merged commit 9fd77e965d into gh-pr/1524/base 2026-11-26 23:14:03 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.