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

Closed
reeledMarek wants to merge 1 commit from upstream-pr/2552 into main
reeledMarek commented 2026-11-25 15:40:12 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by reeledMarek on 2026-11-25T15:40:12Z.


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.
<!-- greyfinch-sync:Marvisak/VIctory:issue:6608187980 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2552). Originally posted by [reeledMarek](https://github.com/reeledMarek) on 2026-11-25T15:40:12Z. --- ### 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.
Marvisak commented 2026-11-25 19:06:25 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T18:36:48Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7171150210 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2552#issuecomment-7171150210). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T18:36:48Z. --- <!-- 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)_
reeledMarek commented 2026-11-25 20:06:31 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by reeledMarek on 2026-11-25T20:05:44Z.


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!

<!-- greyfinch-sync:Marvisak/VIctory:comment:7173183554 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2552#issuecomment-7173183554). Originally posted by [reeledMarek](https://github.com/reeledMarek) on 2026-11-25T20:05:44Z. --- 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!
upstream-sync closed this pull request 2026-11-25 21:02:35 +00:00

Pull request closed

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
Marvisak/VIctory!2550
No description provided.