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

Open
AscilCH wants to merge 1 commit from upstream-pr/791 into main
AscilCH commented 2026-11-25 07:35:46 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by AscilCH on 2026-11-25T07:35:46Z.


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.)

<!-- greyfinch-sync:fxceless/victory-fork:issue:6599580781 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/791). Originally posted by [AscilCH](https://github.com/AscilCH) on 2026-11-25T07:35:46Z. --- ## 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.)*
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/791:upstream-pr/791'
git switch 'upstream-pr/791'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/791'
git switch 'upstream-pr/791'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/791'
git switch 'upstream-pr/791'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/791'
git switch 'main'
git merge --squash 'upstream-pr/791'
git switch 'main'
git merge --ff-only 'upstream-pr/791'
git switch 'main'
git merge 'upstream-pr/791'
git push origin 'main'
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
fxceless/victory-fork!791
No description provided.