Repository navigation
Loader: a clwb in the last bytes of a page is emulated instead of faulting - #941
Conversation
…lting emulate_amd_only copies only the bytes left in the faulting page and gated clwb_len on n >= 15 because clwb_len took a fixed [u8; 15]. A 4- to 10-byte clwb starting in the last 14 bytes of a page (or falling back from a clwb_loop that straddles the page end) was therefore skipped, leaving pre-Ice Lake Intel CPUs with an unhandled STATUS_ILLEGAL_INSTRUCTION. Change clwb_len to take &[u8], bounds-checking each byte read and returning Some(len) only when len <= code.len(), and drop the n >= 15 guard in emulate_amd_only. Fixes Marvisak#924. Co-Authored-By: Gemini 4 Neon <noreply@google.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… page is emulated instead of faulting Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
mercuryVM
left a comment
There was a problem hiding this comment.
Tested 60d2cf9 on Windows 11, RTX 5070, MSVC: builds, cargo test --workspace --no-fail-fast 576 passed, 0 failed (on our fork main), with victory-shader single-threaded. a_clwb_at_the_end_of_a_page_is_decoded passes, including the two emulate_amd_only cases at the end of a page followed by a PAGE_NOACCESS page.
- Every byte
clwb_lenreads now goes throughfirst/get, including the prefix, the0f aepair, ModRM and SIB. The finallen <= code.len()covers displacements cut off by the page end, so a truncated encoding returnsNoneinstead of a length past readable memory. - Decoding is unchanged otherwise: the old cases pass as slices.
emulate_amd_onlypasses exactly thenbytes it copied, so there's no read past the page.
Merged into our fork's main.
AI-assisted (Claude Code).
Merges Marvisak#188 Marvisak#213 Marvisak#214 Marvisak#219 Marvisak#221 Marvisak#311 Marvisak#324 Marvisak#363 Marvisak#406 Marvisak#454 Marvisak#529 Marvisak#560 Marvisak#708 Marvisak#937 Marvisak#941 Marvisak#963 Marvisak#1111 Marvisak#1159 Marvisak#1304 Marvisak#1306 onto main (ffe310e), each head unchanged, no conflicts. One change of mine: the long-format import descriptor code Marvisak#963 adds nests `if size == 0` in an `if let`, which clippy::collapsible_if rejects under -D warnings; it is now one `if let ... && size == 0` (clippy --fix, no change of behaviour). cargo clippy --workspace --all-targets --locked -- -D warnings, with and without --all-features, is clean and cargo test --workspace --locked passes (388 passed, 7 ignored; main has 342 passed, 6 ignored). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
Tested on a real pre-Ice Lake CPU: Intel Core i7-5820K (Haswell-E; CPUID leaf 7 EBX bit 24 = 0, so no The tests in this PR call
The local test (in
|
…lated instead of faulting
…lated instead of faulting
…lated instead of faulting
What's wrong
As #924 describes,
emulate_amd_only(crates/victory-loader/src/crash.rs) copies only the bytes left in the faulting instruction's page, then callsclwb_lenonly when at least 15 were copied, becauseclwb_lentook a[u8; 15]:A
clwb m8is 4 to 10 bytes. One that starts in the last 14 bytes of a page is not emulated, and on Intel CPUs before Ice Lake the title dies withSTATUS_ILLEGAL_INSTRUCTION. The same happens to a write-back loop that straddles the page end:clwb_loopcannot match the cut bytes, and the single-instruction fallback is skipped too.What the fix does
clwb_lentakes&[u8], asclwb_loopalready does. It reads every byte throughfirst/get, so a prefix, ModRM, SIB or displacement past the slice givesNoneinstead of a panic. It returnsSome(len)only whenlen <= code.len().emulate_amd_onlydrops then >= 15guard and passes&bytes[..n]. The decoding is otherwise unchanged.Tests
crash::tests::clwb_lengths: the existing cases, now passing slices.crash::tests::a_clwb_at_the_end_of_a_page_is_decoded, which has three parts:Nonewithout panicking: disp32 6 of 8 bytes, disp8 4 of 5, SIB missing, SIB with disp32 cut short, ModRM missing, 1 byte, and empty.emulate_amd_onlyon a 4-byte and a 5-byteclwbplaced at the very end of a page, followed by aPAGE_NOACCESSpage, steps over each one.main, the page-endemulate_amd_onlycase fails atassert!(emulate_amd_only(&mut pointers)):n = 4 < 15skipsclwb_len, and the handler returnsfalse.On GitHub's
windows-latestwith the upstream CI's commands (clippy-D warningswith and without--all-features, thencargo test --workspace --locked), everything passes, andvictory-loaderhas 23 passed, 0 failed: https://github.com/BastienRodz/VIctory/actions/runs/45413158495On a real pre-Ice Lake CPU (@hadrianhola, comment): i7-5820K (Haswell-E, no
clwb), Windows 10, a realclwbraising#UDthrough the installed handler, placed in the last 4 and 5 bytes of a page. Onmainthe process dies with0xc000001d. With this PR it passes, 10 of 10 runs. The control, the sameclwbmid-page, passes on both.No game data used. AI-assisted: implemented with Gemini 4 Neon, reviewed and verified with Claude Code.
Fixes #924.
🤖 Generated with Claude Code