Loader: prevent u64 wraparound in crash::clzero fast-path loop emulation #2555

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

@⁠reeledMarek on GitHub · 2026-11-25 15:40 UTC · original
reeledMarek:fix/loader-crash-clzero-wrap → main · +37 −0 · 1 files · 1 commits · closed without merging

Problem

In crash::clzero, both fast-path clzero loop emulators advance the cursor with wrapping_add(0x40) and loop until cursor >= limit. If limit > u64::MAX - 0x3f (or the cursor starts within 63 bytes of u64::MAX), the addition wraps past u64::MAX back to 0..0x3f < limit, causing the loop to zero address 0x0 and trigger a nested access violation inside the VEH.

Fix

  • Require both the cursor and limit to be <= u64::MAX - 0x3f before entering either fast-path loop; otherwise fall back to single-instruction clzero emulation so the CPU executes the loop's own add/cmp/jb.

Testing

  • Added emulated_clzero_loop_falls_back_when_limit_would_wrap in crates/victory-loader/src/crash.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/2555) `reeledMarek:fix/loader-crash-clzero-wrap` → `main` · +37 −0 · 1 files · 1 commits · closed without merging ### Problem In `crash::clzero`, both fast-path `clzero` loop emulators advance the cursor with `wrapping_add(0x40)` and loop until `cursor >= limit`. If `limit > u64::MAX - 0x3f` (or the cursor starts within 63 bytes of `u64::MAX`), the addition wraps past `u64::MAX` back to `0..0x3f < limit`, causing the loop to zero address `0x0` and trigger a nested access violation inside the VEH. ### Fix - Require both the cursor and `limit` to be `<= u64::MAX - 0x3f` before entering either fast-path loop; otherwise fall back to single-instruction `clzero` emulation so the CPU executes the loop's own `add`/`cmp`/`jb`. ### Testing - Added `emulated_clzero_loop_falls_back_when_limit_would_wrap` in `crates/victory-loader/src/crash.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:08 +00:00
github-bot closed this pull request 2026-11-26 05:09:08 +00:00
Author
Owner

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

Automated triage for the maintainers.

This PR adds a guard to the two fast-path loops in clzero (crates/victory-loader/src/crash.rs) for a cursor or limit within 63 bytes of u64::MAX. That case cannot come up. The cursor is a user-mode address the title zeroes (zero(context.Rax) would fault long before reaching the top of the address space), and the limit is the end of the title's buffer, which is also a user-mode address. The guard also does not change the outcome. On the fallback path the title's own add rax, 0x40 / cmp / jb run on the CPU and wrap the same way, and the next clzero fault lands in this handler again. So the loop runs the same, just one exception per line. The new test only covers a limit = u64::MAX that no real loop has.

This counts as a guard for a case that cannot occur, so the PR is proposed for closing. It will be closed in 48 hours unless the author pushes a change or a maintainer removes the label. A reproduction where a title really reaches this state would change the verdict.

CI: check passing.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 18:37 UTC · [original](https://github.com/Marvisak/VIctory/pull/2555#issuecomment-7171175139) <!-- victory-triage v1 head=d2f2e1b961cb643c9e52fe405bd2592f96f75377 verdict=proposed-close at=2026-11-25T18:37:33Z --> Automated triage for the maintainers. This PR adds a guard to the two fast-path loops in `clzero` (`crates/victory-loader/src/crash.rs`) for a cursor or limit within 63 bytes of `u64::MAX`. That case cannot come up. The cursor is a user-mode address the title zeroes (`zero(context.Rax)` would fault long before reaching the top of the address space), and the limit is the end of the title's buffer, which is also a user-mode address. The guard also does not change the outcome. On the fallback path the title's own `add rax, 0x40` / `cmp` / `jb` run on the CPU and wrap the same way, and the next `clzero` fault lands in this handler again. So the loop runs the same, just one exception per line. The new test only covers a `limit = u64::MAX` that no real loop has. This counts as a guard for a case that cannot occur, so the PR is proposed for closing. It will be closed in 48 hours unless the author pushes a change or a maintainer removes the label. A reproduction where a title really reaches this state would change the verdict. CI: `check` passing. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

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

Closing per triage — agreed user-mode clzero loops cannot wrap u64::MAX in practice. Thanks for the review!

**@⁠reeledMarek** on GitHub · 2026-11-25 20:05 UTC · [original](https://github.com/Marvisak/VIctory/pull/2555#issuecomment-7173184543) Closing per triage — agreed user-mode `clzero` loops cannot wrap `u64::MAX` in practice. 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!2555
No description provided.