Crash reports: end the stack walk where rtlvirtualunwind faults #1895

Open
imjustprism wants to merge 3 commits from upstream-pr/1897 into main
imjustprism commented 2026-11-25 00:19:00 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by imjustprism on 2026-11-25T00:19:00Z.


a crash on a smashed frame (a frame register or return address pointing at memory that is not there) made RtlVirtualUnwind fault inside our vectored handler, so the report was lost and the process died in the handler. the unwind call now runs through a small trampoline: on a memory fault raised inside ntdll the handler ends that call and the walk stops with a walk ended: ... line naming the fault. only the first exception of a call is recovered, and a guard page read on another thread's stack is put back.

three commits: the walk moves to its own module, walks are bounded by the committed stack (an rsp in the reserved part of the stack with no function entry was read unguarded), then the guarded call.

tested on windows 11 26200, ryzen 7 9800x3d, full gate green. the child tests die with 0xc0000005 without the recovery. 10,000 recovered faults leave function tables and panic unwinding usable. not covered: a fault inside the search of a registered function table whose entries are gone, and statuses RtlVirtualUnwind raises itself (those end the process as before). it relies on the exe not being shadow-stack (cet) compatible, which it is not today.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6594182323 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1897). Originally posted by [imjustprism](https://github.com/imjustprism) on 2026-11-25T00:19:00Z. --- a crash on a smashed frame (a frame register or return address pointing at memory that is not there) made RtlVirtualUnwind fault inside our vectored handler, so the report was lost and the process died in the handler. the unwind call now runs through a small trampoline: on a memory fault raised inside ntdll the handler ends that call and the walk stops with a `walk ended: ...` line naming the fault. only the first exception of a call is recovered, and a guard page read on another thread's stack is put back. three commits: the walk moves to its own module, walks are bounded by the committed stack (an rsp in the reserved part of the stack with no function entry was read unguarded), then the guarded call. tested on windows 11 26200, ryzen 7 9800x3d, full gate green. the child tests die with 0xc0000005 without the recovery. 10,000 recovered faults leave function tables and panic unwinding usable. not covered: a fault inside the search of a registered function table whose entries are gone, and statuses RtlVirtualUnwind raises itself (those end the process as before). it relies on the exe not being shadow-stack (cet) compatible, which it is not today.
catminou4 commented 2026-11-25 03:02:39 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T02:17:17Z.

Review: COMMENTED


Static review only: crash-handler/stack-walk code is Windows-only (rtlvirtualunwind) — nothing compiles on macOS; source review of the diff.

Bounding the stack walk where rtlvirtualunwind faults prevents the crash handler itself from crashing — good hardening, pairs with #1539's crash.rs work.

<!-- greyfinch-sync:Marvisak/VIctory:review:6050699180 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1897#pullrequestreview-6050699180). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-25T02:17:17Z. **Review:** COMMENTED --- Static review only: crash-handler/stack-walk code is Windows-only (rtlvirtualunwind) — nothing compiles on macOS; source review of the diff. Bounding the stack walk where rtlvirtualunwind faults prevents the crash handler itself from crashing — good hardening, pairs with #1539's crash.rs work.
AgneyaK commented 2026-11-25 07:03:09 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by AgneyaK on 2026-11-25T06:18:33Z.


Native test report: Windows 11 26300 (i7-13700H), MSVC, PR head 4dd75410 merged onto main 940d32f (clean merge).

  • Stability: cargo test -p victory-loader -p victory-pe --locked, 10 full runs, all identical and green: loader 56 + 1 + 2 + 1, pe 36, 0 failed. That matters here, since several tests fault on purpose in child processes and on guard pages.
  • The tests exercise the recovery. I made recover_unwind_fault decline everything (if true || … on its early-return line) and ran the lib tests again. The test process died partway (28 of 56 done) with exit code 0x80000001 (STATUS_GUARD_PAGE_VIOLATION), so the guard-page and fault tests do depend on the recovery and aren't passing vacuously.
  • Clippy: cargo clippy -p victory-loader -p victory-pe --all-targets --locked -- -D warnings, with and without --all-features: clean.
  • Read-through of the trampoline:
    • The prologue's .seh_* directives match the saves: 8 pushes, 232 bytes, xmm6–15 at 64…208. rsp stays 16-byte aligned for the movaps and the call.
    • The recovery path restores MXCSR, the x87 control word and DF before the shared epilogue.
    • Recovery is limited to faults inside ntdll's image range while GUARDED is set, and GUARDED is taken with replace(null), so a second fault in the same call isn't recovered. That matches the description.
    • I didn't find a problem.

Not tested: a real title crash with a smashed frame. None of my recent title runs crashed in a way that would reach this path.

AI use: Claude Code (Claude Opus 5.5) ran these checks and wrote this.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7154657374 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1897#issuecomment-7154657374). Originally posted by [AgneyaK](https://github.com/AgneyaK) on 2026-11-25T06:18:33Z. --- Native test report: Windows 11 26300 (i7-13700H), MSVC, PR head `4dd75410` merged onto `main` `940d32f` (clean merge). - **Stability:** `cargo test -p victory-loader -p victory-pe --locked`, 10 full runs, all identical and green: loader 56 + 1 + 2 + 1, pe 36, 0 failed. That matters here, since several tests fault on purpose in child processes and on guard pages. - **The tests exercise the recovery.** I made `recover_unwind_fault` decline everything (`if true || …` on its early-return line) and ran the lib tests again. The test process died partway (28 of 56 done) with exit code `0x80000001` (`STATUS_GUARD_PAGE_VIOLATION`), so the guard-page and fault tests do depend on the recovery and aren't passing vacuously. - **Clippy:** `cargo clippy -p victory-loader -p victory-pe --all-targets --locked -- -D warnings`, with and without `--all-features`: clean. - **Read-through of the trampoline:** - The prologue's `.seh_*` directives match the saves: 8 pushes, 232 bytes, xmm6–15 at 64…208. `rsp` stays 16-byte aligned for the `movaps` and the call. - The recovery path restores MXCSR, the x87 control word and DF before the shared epilogue. - Recovery is limited to faults inside ntdll's image range while `GUARDED` is set, and `GUARDED` is taken with `replace(null)`, so a second fault in the same call isn't recovered. That matches the description. - I didn't find a problem. Not tested: a real title crash with a smashed frame. None of my recent title runs crashed in a way that would reach this path. AI use: Claude Code (Claude Opus 5.5) ran these checks and wrote this.
Marvisak commented 2026-11-25 09:06:09 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T08:16:12Z.


Automated triage for the maintainers.

Merge candidate. Rebased onto main; merges cleanly, in three commits:

  • The stack walk moves to crates/victory-loader/src/unwind.rs.
  • Walks are bounded by the committed stack.
  • RtlVirtualUnwind runs through the victory_guarded_call trampoline.

recover_unwind_fault recovers only an access violation, guard-page violation or in-page error raised inside ntdll's image range during a guarded call. It takes GUARDED with replace, so only the first exception counts, and it puts back a cleared guard page. The prologue saves and .seh_* offsets match (8 pushes, 232 bytes, xmm6-15 at 64..208), and the recovery path restores MXCSR, the x87 control word and DF. Because it rewrites Rip/Rsp in an exception handler, a maintainer should read it carefully. Optional: the long rustdoc on recover_unwind_fault, which includes a measurement log, could be trimmed.

CI: passing.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7156818591 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1897#issuecomment-7156818591). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T08:16:12Z. --- <!-- victory-triage v1 head=7e71820b1e291cea69c26155173b80c493b60f6e verdict=merge-candidate at=2026-11-26T07:20:44Z --> Automated triage for the maintainers. **Merge candidate.** Rebased onto `main`; merges cleanly, in three commits: - The stack walk moves to `crates/victory-loader/src/unwind.rs`. - Walks are bounded by the committed stack. - `RtlVirtualUnwind` runs through the `victory_guarded_call` trampoline. `recover_unwind_fault` recovers only an access violation, guard-page violation or in-page error raised inside ntdll's image range during a guarded call. It takes `GUARDED` with `replace`, so only the first exception counts, and it puts back a cleared guard page. The prologue saves and `.seh_*` offsets match (8 pushes, 232 bytes, xmm6-15 at 64..208), and the recovery path restores MXCSR, the x87 control word and DF. Because it rewrites `Rip`/`Rsp` in an exception handler, a maintainer should read it carefully. Optional: the long rustdoc on `recover_unwind_fault`, which includes a measurement log, could be trimmed. CI: passing. --- _Generated by [Claude Code](https://claude.ai/code)_
upstream-sync changed title from [PR #1897] end the stack walk where rtlvirtualunwind faults to [PR #1897] Crash reports: end the stack walk where rtlvirtualunwind faults 2026-11-26 09:05:09 +00:00
fuzeofficlal commented 2026-11-26 12:05:12 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T11:15:37Z.

Review: CHANGES_REQUESTED


The guarded unwind trampoline design looks very solid: the x64 Win64 prologue/epilogue and .seh_* directives align the stack properly and preserve all nonvolatile GPRs, XMM6–XMM15, MXCSR, x87 CW, and DF; single-shot GUARDED consumption, UNWINDER_IMAGE filtering, guard-page re-arming, and post-GetThreadContext TEB reads in stacks.rs all check out cleanly. All 57 victory-loader dev tests and integration tests pass.

Two issues need attention before merge:

  1. Blocking — two new tests fail in --release builds (crates/victory-loader/src/unwind.rs:776):
    Running cargo test --release -p victory-loader --lib fails deterministically (55 passed, 2 failed) on:

    • unwind::tests::a_frame_register_outside_the_stack_ends_the_walk
    • unwind::tests::a_frame_register_in_the_uncommitted_stack_ends_the_walk

    Both child processes panic at crates/victory-loader/src/unwind.rs:776:

    assertion `left == right` failed: rbp is not the frame register
      left: 0
     right: 5
    

    In walk_with_frame_register:

    #[repr(align(64))]
    struct Line([u8; 64]);
    std::hint::black_box(&Line([0; 64]).0);
    

    Because &Line([0; 64]).0 is a shared reference to a constant all-zero rvalue, rustc promotes it to static .rdata under --release, so the function no longer needs 64-byte stack realignment and LLVM omits the rbp frame pointer. Binding a mutable local on the stack (let mut line = Line([0; 64]); std::hint::black_box(&mut line.0);) prevents static promotion and keeps the frame register in release builds as well.

  2. Overflow in stack-bounds check (crates/victory-loader/src/unwind.rs:104):
    In unwind_into:

    let rsp = context.Rsp as usize;
    if rsp < low || rsp + 8 > high {
        break;
    }
    

    If a corrupted frame leaves context.Rsp in u64::MAX - 6..=u64::MAX, rsp >= low holds while rsp + 8 either panics on arithmetic overflow in debug builds (inside the vectored handler) or wraps to 0..=6 < high in release builds, bypassing the bounds check and dereferencing (rsp as *const u64).read() outside ntdll (where recover_unwind_fault declines recovery). Using rsp.checked_add(8).is_none_or(|end| end > high) closes that gap cleanly.

<!-- greyfinch-sync:Marvisak/VIctory:review:6073184855 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1897#pullrequestreview-6073184855). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T11:15:37Z. **Review:** CHANGES_REQUESTED --- The guarded unwind trampoline design looks very solid: the x64 Win64 prologue/epilogue and `.seh_*` directives align the stack properly and preserve all nonvolatile GPRs, XMM6–XMM15, MXCSR, x87 CW, and DF; single-shot `GUARDED` consumption, `UNWINDER_IMAGE` filtering, guard-page re-arming, and post-`GetThreadContext` TEB reads in `stacks.rs` all check out cleanly. All 57 `victory-loader` dev tests and integration tests pass. Two issues need attention before merge: 1. **Blocking — two new tests fail in `--release` builds (`crates/victory-loader/src/unwind.rs:776`)**: Running `cargo test --release -p victory-loader --lib` fails deterministically (55 passed, 2 failed) on: - `unwind::tests::a_frame_register_outside_the_stack_ends_the_walk` - `unwind::tests::a_frame_register_in_the_uncommitted_stack_ends_the_walk` Both child processes panic at `crates/victory-loader/src/unwind.rs:776`: ```text assertion `left == right` failed: rbp is not the frame register left: 0 right: 5 ``` In `walk_with_frame_register`: ```rust #[repr(align(64))] struct Line([u8; 64]); std::hint::black_box(&Line([0; 64]).0); ``` Because `&Line([0; 64]).0` is a shared reference to a constant all-zero rvalue, rustc promotes it to static `.rdata` under `--release`, so the function no longer needs 64-byte stack realignment and LLVM omits the `rbp` frame pointer. Binding a mutable local on the stack (`let mut line = Line([0; 64]); std::hint::black_box(&mut line.0);`) prevents static promotion and keeps the frame register in release builds as well. 2. **Overflow in stack-bounds check (`crates/victory-loader/src/unwind.rs:104`)**: In `unwind_into`: ```rust let rsp = context.Rsp as usize; if rsp < low || rsp + 8 > high { break; } ``` If a corrupted frame leaves `context.Rsp` in `u64::MAX - 6..=u64::MAX`, `rsp >= low` holds while `rsp + 8` either panics on arithmetic overflow in debug builds (inside the vectored handler) or wraps to `0..=6 < high` in release builds, bypassing the bounds check and dereferencing `(rsp as *const u64).read()` outside `ntdll` (where `recover_unwind_fault` declines recovery). Using `rsp.checked_add(8).is_none_or(|end| end > high)` closes that gap cleanly.
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/1897:upstream-pr/1897'
git switch 'upstream-pr/1897'

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/1897'
git switch 'upstream-pr/1897'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/1897'
git switch 'upstream-pr/1897'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/1897'
git switch 'main'
git merge --squash 'upstream-pr/1897'
git switch 'main'
git merge --ff-only 'upstream-pr/1897'
git switch 'main'
git merge 'upstream-pr/1897'
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
Marvisak/VIctory!1895
No description provided.