A crash through a bad function pointer keeps its caller in the checked stack walk #378

Open
github-bot wants to merge 1 commit from github-bot/gh-378 into a-publier AGit
Owner

@⁠thejacte on GitHub · 2026-11-26 22:53 UTC · original
thejacte:claude/a-publier-unwind-null-caller → a-publier · +35 −15 · 1 files · 1 commits · open

Follow-up to #343, from JonyWater's review there: with VICTORY_UNWIND_CHECKS on, a call through a null or garbage function pointer lost its caller. The faulting RIP isn't executable, so the first step broke before the leaf rule could read the return address at [rsp]. The old walk showed that caller, and it's usually the most useful line in a crash report.

Now the first frame takes the leaf rule whatever RIP points at: null, unreadable, not executable, or outside an image. [rsp] is still read through ReadProcessMemory, and frames after the first still need executable image code. Profiles aren't affected, since a suspended thread's RIP is real code.

A second pass found one more edge case: a caller whose return address was the stack's last word was dropped, because the step after it refused RSP == high. It is kept now. The top of the loop still stops before any read past the stack.

Tests (crates/victory-loader/src/crash.rs):

  • takes_the_caller_of_a_call_through_a_null_pointer: RIP = 0 and a one-word stack. The test expects exactly [0, caller], which also covers the last-word case.
  • stops_at_a_pc_outside_an_image_after_the_first_frame: the leaf rule returns into non-executable data, and the walk stops there. This replaces stops_at_a_pc_outside_an_image.

Checked on a-publier at 4eb6cfd:

  • cargo clippy --workspace --all-targets --locked -- -D warnings: no warnings
  • the same with --all-features: no warnings
  • cargo test -p victory-loader --locked: 57 passed
  • cargo xtask policy: passes (271 files)

Not covered here: JonyWater's other note, about the clzero and write-site stubs entered by jmp (their second frame is junk, as it was with the old walk). That belongs in its own issue.

Written with Claude Code; reviewed by Codex and a rust-reviewer pass against upstream/rx9070xt (the same code; a-publier's crash.rs matches #343).

🤖 Generated with Claude Code

**@⁠thejacte** on GitHub · 2026-11-26 22:53 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/378) `thejacte:claude/a-publier-unwind-null-caller` → `a-publier` · +35 −15 · 1 files · 1 commits · open Follow-up to #343, from JonyWater's review there: with `VICTORY_UNWIND_CHECKS` on, a call through a null or garbage function pointer lost its caller. The faulting RIP isn't executable, so the first step broke before the leaf rule could read the return address at `[rsp]`. The old walk showed that caller, and it's usually the most useful line in a crash report. Now the first frame takes the leaf rule whatever RIP points at: null, unreadable, not executable, or outside an image. `[rsp]` is still read through `ReadProcessMemory`, and frames after the first still need executable image code. Profiles aren't affected, since a suspended thread's RIP is real code. A second pass found one more edge case: a caller whose return address was the stack's last word was dropped, because the step after it refused `RSP == high`. It is kept now. The top of the loop still stops before any read past the stack. **Tests** (`crates/victory-loader/src/crash.rs`): - `takes_the_caller_of_a_call_through_a_null_pointer`: RIP = 0 and a one-word stack. The test expects exactly `[0, caller]`, which also covers the last-word case. - `stops_at_a_pc_outside_an_image_after_the_first_frame`: the leaf rule returns into non-executable data, and the walk stops there. This replaces `stops_at_a_pc_outside_an_image`. **Checked** on a-publier at 4eb6cfd: - `cargo clippy --workspace --all-targets --locked -- -D warnings`: no warnings - the same with `--all-features`: no warnings - `cargo test -p victory-loader --locked`: 57 passed - `cargo xtask policy`: passes (271 files) Not covered here: JonyWater's other note, about the `clzero` and write-site stubs entered by `jmp` (their second frame is junk, as it was with the old walk). That belongs in its own issue. Written with Claude Code; reviewed by Codex and a rust-reviewer pass against `upstream/rx9070xt` (the same code; a-publier's crash.rs matches #343). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
With VICTORY_UNWIND_CHECKS on, the first frame takes the leaf rule whatever
RIP points at (null, unreadable, not executable, or outside an image), as the
old walk did, so a call through a null or garbage pointer still shows its
caller. Frames after the first still need executable image code. A caller
whose return address is the stack's last word is kept.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 00:58:46 +00:00
Author
Owner

@⁠lvndrpup on GitHub · 2026-11-27 04:55 UTC · original · reviewed

Checked on Windows 11 build 26300, Rust 1.98.1, debug. To see that the new tests catch the old behaviour, I ran them against 4eb6cfd's walk, taking crash.rs from 4eb6cfd up to mod tests and this PR's tests after it:

cargo test -p victory-loader --lib -- crash:: 4eb6cfd's walk, this PR's tests this PR (01d3f8c)
takes_the_caller_of_a_call_through_a_null_pointer fails: left: [0] (the caller is lost) passes
stops_at_a_pc_outside_an_image_after_the_first_frame fails: left: [0], right: [0, 330048724536] passes

At 01d3f8c, cargo test -p victory-loader passes (57 lib tests), and cargo clippy -p victory-loader --all-targets -- -D warnings is clean, with and without --all-features. I did not run a real crash through a bad pointer; these results come from the unit tests' synthetic stacks only.

**@⁠lvndrpup** on GitHub · 2026-11-27 04:55 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/378#pullrequestreview-6083658476) · **reviewed** Checked on Windows 11 build 26300, Rust 1.98.1, debug. To see that the new tests catch the old behaviour, I ran them against `4eb6cfd`'s walk, taking `crash.rs` from `4eb6cfd` up to `mod tests` and this PR's tests after it: | `cargo test -p victory-loader --lib -- crash::` | `4eb6cfd`'s walk, this PR's tests | this PR (`01d3f8c`) | |---|---|---| | `takes_the_caller_of_a_call_through_a_null_pointer` | fails: `left: [0]` (the caller is lost) | passes | | `stops_at_a_pc_outside_an_image_after_the_first_frame` | fails: `left: [0]`, `right: [0, 330048724536]` | passes | At `01d3f8c`, `cargo test -p victory-loader` passes (57 lib tests), and `cargo clippy -p victory-loader --all-targets -- -D warnings` is clean, with and without `--all-features`. I did not run a real crash through a bad pointer; these results come from the unit tests' synthetic stacks only.
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/378/head:github-bot/gh-378'
git switch 'github-bot/gh-378'

Merge

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