xmem: XMemMapPhysicalPages trusts n (unchecked n * PAGE and slice length) #226

Closed
opened 2026-11-26 12:04:49 +00:00 by github-bot · 0 comments
Owner

@⁠kekonn on GitHub · 2026-11-26 12:01 UTC · original

crates/victory-hle/src/modules/xmem.rs:1198 builds the page list with std::slice::from_raw_parts(pages, n), and ~1216 calls unmap(&mut physical, base, n * PAGE). Neither is checked. Release builds don't check for overflow, so n * PAGE and base + len in unmap (~1852) can wrap. XMemAllocatePhysicalPages already uses checked_mul (~651), so this function is the odd one out.

When: only with an absurd n from the title, which a valid title never passes. This is hardening.

Proposed fix (~5 lines)

At the top, let Some(len) = n.checked_mul(PAGE).filter(|&l| base.checked_add(l).is_some()) else { return null_mut(); };, then use len in the unmap call. Since PAGE is 64 KiB, this also keeps from_raw_parts's length precondition. Optionally add the same guard to XMemFreePhysicalPages and the scatter variant.

Upstream: none (#142's xmem.rs is identical to main's; #191 only adds a test).
Status: a fix is being prepared in kekonn/VIctory-7900XTX on branch claude/gifted-clarke-uxuqw8.


Generated by Claude Code

**@⁠kekonn** on GitHub · 2026-11-26 12:01 UTC · [original](https://github.com/avatarmanz/VIctory-7900XTX/issues/226) `crates/victory-hle/src/modules/xmem.rs:1198` builds the page list with `std::slice::from_raw_parts(pages, n)`, and ~1216 calls `unmap(&mut physical, base, n * PAGE)`. Neither is checked. Release builds don't check for overflow, so `n * PAGE` and `base + len` in `unmap` (~1852) can wrap. `XMemAllocatePhysicalPages` already uses `checked_mul` (~651), so this function is the odd one out. **When:** only with an absurd `n` from the title, which a valid title never passes. This is hardening. ### Proposed fix (~5 lines) At the top, `let Some(len) = n.checked_mul(PAGE).filter(|&l| base.checked_add(l).is_some()) else { return null_mut(); };`, then use `len` in the `unmap` call. Since `PAGE` is 64 KiB, this also keeps `from_raw_parts`'s length precondition. Optionally add the same guard to `XMemFreePhysicalPages` and the scatter variant. **Upstream:** none (#142's `xmem.rs` is identical to main's; #191 only adds a test). **Status:** a fix is being prepared in kekonn/VIctory-7900XTX on branch `claude/gifted-clarke-uxuqw8`. --- _Generated by [Claude Code](https://claude.ai/code)_
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 12:04:49 +00:00
This discussion has been locked. Commenting is limited to contributors.
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/avatarmanz--VIctory-7900XTX#226
No description provided.