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

Open
sharan104 wants to merge 1 commit from upstream-pr/259 into main
sharan104 commented 2026-11-26 13:33:19 +00:00 (Migrated from github.com)

Imported from avatarmanz/VIctory-7900XTX. Originally posted by sharan104 on 2026-11-26T13:33:19Z.


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

<!-- greyfinch-sync:avatarmanz/VIctory-7900XTX:issue:6627776655 --> Imported from [avatarmanz/VIctory-7900XTX](https://github.com/avatarmanz/VIctory-7900XTX/pull/259). Originally posted by [sharan104](https://github.com/sharan104) on 2026-11-26T13:33:19Z. --- `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)
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/259:upstream-pr/259'
git switch 'upstream-pr/259'

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/259'
git switch 'upstream-pr/259'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/259'
git switch 'upstream-pr/259'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/259'
git switch 'main'
git merge --squash 'upstream-pr/259'
git switch 'main'
git merge --ff-only 'upstream-pr/259'
git switch 'main'
git merge 'upstream-pr/259'
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
avatarmanz/VIctory-7900XTX!259
No description provided.