HLE: guard zero-length range panic in xmem::aliases and map/unmap size overflows #2552

Closed
github-bot wants to merge 1 commit from gh-pr/2552/head into gh-pr/2552/base
Owner

@⁠reeledMarek on GitHub · 2026-11-25 15:40 UTC · original
reeledMarek:fix/hle-xmem-aliases-and-overflow → main · +35 −9 · 1 files · 1 commits · closed without merging

Problem

  1. xmem::aliases(at, len, out) computed end = at.saturating_add(len) and passed at.saturating_add(1)..end to BTreeMap::range. When len == 0 (or at == usize::MAX), start > end unconditionally panicked inside BTreeMap::range.
  2. XMemMapPhysicalPages computed unchecked n * PAGE, and unmap computed unchecked base + len and base + 1..end.

Fix

  • Return early when end <= at in aliases and end <= base in unmap (using saturating_add(1) for the range start).
  • Guard n.checked_mul(PAGE) and base.checked_add(bytes) in XMemMapPhysicalPages, returning null on overflow.

Testing

  • Added aliases_and_map_reject_zero_length_and_overflowing_ranges in crates/victory-hle/src/modules/xmem.rs.
  • Verified cargo test -p xtask --locked passes asset policy.
**@⁠reeledMarek** on GitHub · 2026-11-25 15:40 UTC · [original](https://github.com/Marvisak/VIctory/pull/2552) `reeledMarek:fix/hle-xmem-aliases-and-overflow` → `main` · +35 −9 · 1 files · 1 commits · closed without merging ### Problem 1. `xmem::aliases(at, len, out)` computed `end = at.saturating_add(len)` and passed `at.saturating_add(1)..end` to `BTreeMap::range`. When `len == 0` (or `at == usize::MAX`), `start > end` unconditionally panicked inside `BTreeMap::range`. 2. `XMemMapPhysicalPages` computed unchecked `n * PAGE`, and `unmap` computed unchecked `base + len` and `base + 1..end`. ### Fix - Return early when `end <= at` in `aliases` and `end <= base` in `unmap` (using `saturating_add(1)` for the range start). - Guard `n.checked_mul(PAGE)` and `base.checked_add(bytes)` in `XMemMapPhysicalPages`, returning null on overflow. ### Testing - Added `aliases_and_map_reject_zero_length_and_overflowing_ranges` in `crates/victory-hle/src/modules/xmem.rs`. - Verified `cargo test -p xtask --locked` passes asset policy.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:09:02 +00:00
github-bot closed this pull request 2026-11-26 05:09:02 +00:00
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 18:36 UTC · original

Automated triage for the maintainers.

This adds zero-length and overflow guards to aliases, unmap and XMemMapPhysicalPages in crates/victory-hle/src/modules/xmem.rs. The guards cover cases that cannot occur:

  • xmem::aliases has no caller in main except the module's own test, which passes PAGE.
  • unmap already returns early for len == 0.
  • For n * PAGE to overflow in XMemMapPhysicalPages, the title would have to pass more than 2^48 pages. That call is already invalid at the from_raw_parts(pages, n) that follows.
  • Addresses near usize::MAX are not user-mode addresses.

The rest is reformatting. CI passes (check).

Proposed for closing as no value: it guards cases that cannot occur. The PR will be closed in 48 hours unless the author pushes a change or a maintainer removes the label. A caller that really passes a zero length or an overflowing count, with the path that reaches it, would change this.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 18:36 UTC · [original](https://github.com/Marvisak/VIctory/pull/2552#issuecomment-7171150210) <!-- victory-triage v1 head=1d74535816d883cebafc6bc5d6fe885704c5ebad verdict=proposed-close at=2026-11-25T18:36:37Z --> Automated triage for the maintainers. This adds zero-length and overflow guards to `aliases`, `unmap` and `XMemMapPhysicalPages` in `crates/victory-hle/src/modules/xmem.rs`. The guards cover cases that cannot occur: - `xmem::aliases` has no caller in `main` except the module's own test, which passes `PAGE`. - `unmap` already returns early for `len == 0`. - For `n * PAGE` to overflow in `XMemMapPhysicalPages`, the title would have to pass more than 2^48 pages. That call is already invalid at the `from_raw_parts(pages, n)` that follows. - Addresses near `usize::MAX` are not user-mode addresses. The rest is reformatting. CI passes (`check`). Proposed for closing as no value: it guards cases that cannot occur. The PR will be closed in 48 hours unless the author pushes a change or a maintainer removes the label. A caller that really passes a zero length or an overflowing count, with the path that reaches it, would change this. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠reeledMarek on GitHub · 2026-11-25 20:05 UTC · original

Closing per triage — agreed these guards cover unreachable cases (aliases only called from tests with PAGE, unmap already checks len == 0, impossible page counts). Thanks for the review!

**@⁠reeledMarek** on GitHub · 2026-11-25 20:05 UTC · [original](https://github.com/Marvisak/VIctory/pull/2552#issuecomment-7173183554) Closing per triage — agreed these guards cover unreachable cases (`aliases` only called from tests with `PAGE`, `unmap` already checks `len == 0`, impossible page counts). Thanks for the review!

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No reviewers
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/Marvisak--VIctory!2552
No description provided.