Loader: clwb_len() requires 15 remaining bytes in the page, causing unhandled #UD when clwb sits at page offset 0xFF2..0xFFB #924
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory#924
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
@hyperland956-lgtm on GitHub · 2026-11-24 14:12 UTC · original
Summary
In
crates/victory-loader/src/crash.rs:176, single-instructionclwbemulation is gated onn >= 15(remaining bytes before the end of the 4 KiB page):A
clwb m8instruction (66 [rex] 0f ae /6 [SIB] [disp8/disp32]) is only 4 to 10 bytes long. If a standaloneclwb(or one not matched byclwb_loop) sits within the last 14 bytes of a page (Rip & 0xfffin0xFF2..=0xFFB),n < 15, soclwb_lenis skipped entirely and the exception falls through tosse4a()→false→ unhandledSTATUS_ILLEGAL_INSTRUCTION(0xc000001d) on pre-Ice Lake Intel CPUs (and any CPU withoutCLWB).Suggested fix
Change
clwb_lento accept a slice&[u8](just likeclwb_loop(&[u8])right above it) and bounds-check each byte as it decodes66, optional REX,0f ae, ModRM, optional SIB, and displacement, returningSome(len)wheneverlen <= code.len(). Then remove then >= 15guard inemulate_amd_only.Synthetic unit test
In
crates/victory-loader/src/crash.rs(mod tests):clwb_len(&[0x66, 0x0f, 0xae, 0x31])(4-byte slice, simulatingRip & 0xfff == 0xffc) → expectSome(4).clwb_len(&[0x66, 0x41, 0x0f, 0xae, 0x31])(5-byte slice) → expectSome(5).clwb_len(&[0x66, 0x0f, 0xae, 0x70])(truncateddisp8) → expectNone.@Super-cod on GitHub · 2026-11-24 15:35 UTC · original
I have implemented and verified a fix for this issue:
Summary of Changes
@winne42 on GitHub · 2026-11-24 19:53 UTC · original
I tested the three fixes side by side, as Windows builds (
x86_64-pc-windows-msvc) run under Wine 10.0 on Linux: #941 (60d2cf9), Super-cod's branch (958f998), and thecrash.rspart of #1330 (fb40a8f). All three fix the bug and decode the same way.maincrash::testsmain's decoder (4,289,152)clwbemulated near a page end, unreadable page after (136 placements)-D warningsclwb-shaped encoding (no REX or REX0x40–0x4f, every ModRM, and every SIB where one is read), cut at every length from 0 to 15, plus 2M random slices. The expected answer ismain's decoder on the zero-padded bytes, kept only if that length fits in the slice.PAGE_NOACCESSpage, run through the realemulate_amd_only.mainfails exactly when fewer than 15 bytes remain.Differences: #941 is the only one that tests the handler end to end, with a guard-page test. Super-cod's branch also reformats six unrelated spots in
crash.rs(log_crash,append_to_log,title_output,sse4a,thrown); CI doesn't check formatting, but it's noise and conflict risk next to the other open PRs on this file. #1330 bundles the fix into a 76-file PR. #941 looks like the one to merge.Related, outside this issue, and still in all three:
emulate_amd_onlyfirst reads 3 bytes atRip(code.cast::<[u8; 3]>()). So a 1- or 2-byte illegal instruction in a page's last bytes, before an unreadable page, faults inside the handler. Withud2(0f 0b) in the last 2 bytes, the process dies with a page fault at the next page's first byte, onmainand on every candidate. Closed #1038 had addressed that read.AI-assisted (Claude Code). Tests were synthetic, with no game files.