loader/crash: prevent RSP overflow and unaligned read UB in unwind_into #791

Open
github-bot wants to merge 1 commit from github-bot/gh-791 into main AGit
Owner

@⁠AscilCH on GitHub · 2026-11-25 07:35 UTC · original
AscilCH:fix/loader-crash-unwind-overflow-and-unaligned-read → main · +38 −6 · 1 files · 1 commits · open

Summary

Fix stack-unwinder safety and bounds-check issues in crates/victory-loader/src/crash.rs:

  1. unwind_into() rsp + 8 > high integer overflow:

    • Unchecked rsp + 8 panics in debug builds or wraps past high in release builds when a crashing thread has a corrupted Rsp > usize::MAX - 8.
    • Use rsp.checked_add(8).is_none_or(|end| end > high) and stop unwinding if an iteration makes no (Rip, Rsp) progress.
  2. Unaligned return-address read UB in unwind_into():

    • In the leaf-frame fallback (entry.is_null()), (rsp as *const u64).read() is UB (and panics in debug builds) if the crashing thread has a misaligned Rsp.
    • Use (rsp as *const u64).read_unaligned() and wrapping_add(8).
  3. Defensive module_of() checks:

    • Return None if GetModuleFileNameW fails (len == 0) or if address < module as usize.

Verification

  • cargo test -p victory-loader --locked: 25 passed; 0 failed unit tests (including new crash::tests::unwind_into_handles_overflowing_and_unaligned_rsp), plus 2 passed (load_probe) and 1 passed (title_dlls).
  • cargo clippy -p victory-loader --all-targets --all-features --locked -- -D warnings: 0 warnings.
  • cargo xtask policy: 171 files ok.

(AI-assisted; synthetic unit tests only, no game data.)

**@⁠AscilCH** on GitHub · 2026-11-25 07:35 UTC · [original](https://github.com/fxceless/victory-fork/pull/791) `AscilCH:fix/loader-crash-unwind-overflow-and-unaligned-read` → `main` · +38 −6 · 1 files · 1 commits · open ## Summary Fix stack-unwinder safety and bounds-check issues in `crates/victory-loader/src/crash.rs`: 1. **`unwind_into()` `rsp + 8 > high` integer overflow**: - Unchecked `rsp + 8` panics in debug builds or wraps past `high` in release builds when a crashing thread has a corrupted `Rsp > usize::MAX - 8`. - Use `rsp.checked_add(8).is_none_or(|end| end > high)` and stop unwinding if an iteration makes no `(Rip, Rsp)` progress. 2. **Unaligned return-address read UB in `unwind_into()`**: - In the leaf-frame fallback (`entry.is_null()`), `(rsp as *const u64).read()` is UB (and panics in debug builds) if the crashing thread has a misaligned `Rsp`. - Use `(rsp as *const u64).read_unaligned()` and `wrapping_add(8)`. 3. **Defensive `module_of()` checks**: - Return `None` if `GetModuleFileNameW` fails (`len == 0`) or if `address < module as usize`. ## Verification - `cargo test -p victory-loader --locked`: `25 passed; 0 failed` unit tests (including new `crash::tests::unwind_into_handles_overflowing_and_unaligned_rsp`), plus `2 passed` (`load_probe`) and `1 passed` (`title_dlls`). - `cargo clippy -p victory-loader --all-targets --all-features --locked -- -D warnings`: 0 warnings. - `cargo xtask policy`: `171 files ok`. *(AI-assisted; synthetic unit tests only, no game data.)*
Fix two stack-unwinder safety bugs in `crates/victory-loader/src/crash.rs`:

1. `unwind_into()` checked `rsp + 8 > high` using unchecked addition. If a
   crashing thread has a corrupted `Rsp > usize::MAX - 8`, `rsp + 8` panics in
   debug builds or wraps past the bounds check in release builds and faults on
   dereference. Use `rsp.checked_add(8).is_none_or(|end| end > high)` instead,
   and break if an unwind step makes no `(Rip, Rsp)` progress.
2. In the leaf-frame fallback (`entry.is_null()`), `unwind_into()` read the
   return address via `(rsp as *const u64).read()`, which is UB (and panics in
   debug builds) when the crashing thread has an unaligned `Rsp`. Use
   `read_unaligned()`.
3. In `module_of()`, return `None` if `GetModuleFileNameW` returns 0 or if
   `address < module as usize`.

Add `crash::tests::unwind_into_handles_overflowing_and_unaligned_rsp`.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:51:14 +00:00
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/791/head:github-bot/gh-791'
git switch 'github-bot/gh-791'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-791'
git switch 'github-bot/gh-791'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-791'
git switch 'github-bot/gh-791'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-791'
git switch 'main'
git merge --squash 'github-bot/gh-791'
git switch 'main'
git merge --ff-only 'github-bot/gh-791'
git switch 'main'
git merge 'github-bot/gh-791'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.