Loader: the illegal-instruction handler reads no byte past the faulting page (ud2 at a page end faulted inside it) #259

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

@⁠sharan104 on GitHub · 2026-11-26 13:33 UTC · original
sharan104:fix/loader-audit → main · +72 −27 · 1 files · 1 commits · open

crash.rs's emulate_amd_only handles every EXCEPTION_ILLEGAL_INSTRUCTION. console_insn::emulate passes every ud2 on to it, so this path is live. It read 3 bytes at the faulting Rip before checking where the page ends, and sse4a then read up to 6 more through a raw pointer. So two cases made the handler fault inside VIctory itself when the next page is unmapped:

  • a ud2 in the last 2 bytes of a page
  • an extrq/insertq cut off by the page end

The title's handlers then saw an access violation coming from our handler, instead of the illegal instruction they expected. The bounded copy was already there for the clwb paths; it just came too late.

Fix: the bytes left in the faulting page (up to 32) are copied once, up front, and every check reads only that copy. sse4a now takes a slice, returns None where the bytes end before the instruction does, and is no longer unsafe. Behaviour for whole instructions is unchanged.

Test: nothing_past_the_page_is_read_for_an_instruction_at_its_end places a ud2, a truncated extrq and a whole extrq in the last bytes of a page whose next page is PAGE_NOACCESS. Before the fix the test process died with STATUS_ACCESS_VIOLATION; after it, the test passes (10 runs out of 10).

Results:

  • cargo test -p victory-loader --locked passes.
  • Clippy -D warnings is clean with and without --all-features, apart from descriptor_sites.rs:277, which is already failing on main and which #169 fixes.

🤖 Generated with Claude Code

**@⁠sharan104** on GitHub · 2026-11-26 13:33 UTC · [original](https://github.com/avatarmanz/VIctory-7900XTX/pull/259) `sharan104:fix/loader-audit` → `main` · +72 −27 · 1 files · 1 commits · open `crash.rs`'s `emulate_amd_only` handles every `EXCEPTION_ILLEGAL_INSTRUCTION`. `console_insn::emulate` passes every `ud2` on to it, so this path is live. It read 3 bytes at the faulting `Rip` before checking where the page ends, and `sse4a` then read up to 6 more through a raw pointer. So two cases made the handler fault inside VIctory itself when the next page is unmapped: - a `ud2` in the last 2 bytes of a page - an `extrq`/`insertq` cut off by the page end The title's handlers then saw an access violation coming from our handler, instead of the illegal instruction they expected. The bounded copy was already there for the `clwb` paths; it just came too late. **Fix:** the bytes left in the faulting page (up to 32) are copied once, up front, and every check reads only that copy. `sse4a` now takes a slice, returns `None` where the bytes end before the instruction does, and is no longer `unsafe`. Behaviour for whole instructions is unchanged. **Test:** `nothing_past_the_page_is_read_for_an_instruction_at_its_end` places a `ud2`, a truncated `extrq` and a whole `extrq` in the last bytes of a page whose next page is `PAGE_NOACCESS`. Before the fix the test process died with `STATUS_ACCESS_VIOLATION`; after it, the test passes (10 runs out of 10). **Results:** - `cargo test -p victory-loader --locked` passes. - Clippy `-D warnings` is clean with and without `--all-features`, apart from `descriptor_sites.rs:277`, which is already failing on `main` and which #169 fixes. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
emulate_amd_only read the first three bytes at Rip unconditionally, and
sse4a read up to six more through a raw pointer, before any check of
the page. Only the clwb paths were bounded by the copy of the bytes left
in the page. A `ud2` in the last two bytes of a page (console_insn passes
it on as the title's own trap), or an `extrq`/`insertq` whose immediates
the page cuts off, with no readable page after it, made the vectored
handler itself fault. The title's handlers then saw an access violation
inside VIctory instead of its illegal instruction, and the crash report
named our handler, not the title's code.

The bytes left in the page are now copied once, up front, and every
decode reads only that slice; sse4a takes a slice and returns None where
it ends early.

The test puts a `ud2`, a cut-off `extrq` and a whole `extrq` at the end
of a page followed by a no-access one. Before the fix the test process
died with STATUS_ACCESS_VIOLATION; now the first two are left alone and
the third is emulated as before.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 13:38:10 +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/259/head:github-bot/gh-259'
git switch 'github-bot/gh-259'

Merge

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