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

Open
github-bot wants to merge 3 commits from github-bot/gh-1897 into main AGit
Owner

@⁠imjustprism on GitHub · 2026-11-25 00:19 UTC · original
imjustprism:fix/unwind-frame-register → main · +1780 −226 · 6 files · 3 commits · open

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.

**@⁠imjustprism** on GitHub · 2026-11-25 00:19 UTC · [original](https://github.com/Marvisak/VIctory/pull/1897) `imjustprism:fix/unwind-frame-register` → `main` · +1780 −226 · 6 files · 3 commits · open 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.
a smashed frame made rtlvirtualunwind fault inside the crash handler and
lose the report. it now runs through a trampoline the handler resumes on
a memory fault raised in ntdll, and the walk ends with a line naming the
fault.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:48:01 +00:00
github-bot force-pushed github-bot/gh-1897 from 4dd7541044 to 7e71820b1e 2026-11-26 06:55:39 +00:00 Compare
Author
Owner

@⁠AgneyaK on GitHub · 2026-11-25 06:18 UTC · original

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.

**@⁠AgneyaK** on GitHub · 2026-11-25 06:18 UTC · [original](https://github.com/Marvisak/VIctory/pull/1897#issuecomment-7154657374) 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.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 08:16 UTC · original · edited 2026-11-26 07:20 UTC

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

**@⁠Marvisak** on GitHub · 2026-11-25 08:16 UTC · [original](https://github.com/Marvisak/VIctory/pull/1897#issuecomment-7156818591) · edited 2026-11-26 07:20 UTC <!-- 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)_
github-bot changed title from end the stack walk where rtlvirtualunwind faults to Crash reports: end the stack walk where rtlvirtualunwind faults 2026-11-26 09:03:14 +00:00
Author
Owner

@⁠catminou4 on GitHub · 2026-11-25 02:17 UTC · original · reviewed

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.

**@⁠catminou4** on GitHub · 2026-11-25 02:17 UTC · [original](https://github.com/Marvisak/VIctory/pull/1897#pullrequestreview-6050699180) · **reviewed** 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.
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-26 11:15 UTC · original · requested changes

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.

**@⁠fuzeofficlal** on GitHub · 2026-11-26 11:15 UTC · [original](https://github.com/Marvisak/VIctory/pull/1897#pullrequestreview-6073184855) · **requested changes** 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 can be merged automatically.
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/1897/head:github-bot/gh-1897'
git switch 'github-bot/gh-1897'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1897'
git switch 'github-bot/gh-1897'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1897'
git switch 'github-bot/gh-1897'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1897'
git switch 'main'
git merge --squash 'github-bot/gh-1897'
git switch 'main'
git merge --ff-only 'github-bot/gh-1897'
git switch 'main'
git merge 'github-bot/gh-1897'
git push origin 'main'
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!1897
No description provided.