Loader: a clwb in the last bytes of a page is emulated instead of faulting #941
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/941"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from Marvisak/VIctory. Originally posted by BastienRodz on 2026-11-24T14:23:55Z.
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
Imported from Marvisak/VIctory. Originally posted by Zipettte on 2026-11-24T15:40:44Z.
Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at
60d2cf9:cargo test -p victory-loaderpasses, 26 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed).Tested with AI assistance (Claude).
Imported from Marvisak/VIctory. Originally posted by mercuryVM on 2026-11-24T16:26:28Z.
Review: APPROVED
Tested
60d2cf9on Windows 11, RTX 5070, MSVC: builds,cargo test --workspace --no-fail-fast576 passed, 0 failed (on our fork main), with victory-shader single-threaded.a_clwb_at_the_end_of_a_page_is_decodedpasses, including the twoemulate_amd_onlycases at the end of a page followed by aPAGE_NOACCESSpage.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.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).
Imported from Marvisak/VIctory. Originally posted by hadrianhola on 2026-11-24T18:39:55Z.
Tested on a real pre-Ice Lake CPU: Intel Core i7-5820K (Haswell-E; CPUID leaf 7 EBX bit 24 = 0, so no
clwb), Windows 10 22H2 (19045.7846), Rust 1.98.1, debug. No game data used.The tests in this PR call
emulate_amd_onlywith a built context, so I added a local test (not part of this PR) that runs a realclwband lets the CPU raise#UDthrough the installed handler. TwoPAGE_EXECUTE_READWRITEpages; theclwb(66 0f ae 30and66 41 0f ae 31) sits in the last 4/5 bytes of the first page, withretas the first byte of the second, and is called on a local variable:mainffe310e, the sameclwbat page offset0x800(control)mainffe310e,clwbin the last bytes of the page0xc000001d(STATUS_ILLEGAL_INSTRUCTION)60d2cf9, merged ontoffe310etogether with #214 and #362), same casecargo test -p victory-loader --libon that merge: everything else passes exceptunwinds_like_the_system_walk, which fails the same way onmainhere (#742).The local test (in
crash.rs'smod tests)The control run is the same test with
page.add(0x800)for theclwband theretright after it.AI-assisted (Claude Code); run on my machine.