Repository navigation
PE loader: relocation targets outside the image fail the load - #291
honestlyBroke wants to merge 1 commit into
Conversation
|
Independent static code audit of Summary: Looks solid
Minor non-blocking notes
(AI-assisted) |
…v#106) The relocation entries come from the file, and map_image patched base + rva without checking it against the mapping: a target past SizeOfImage, or a DIR64 whose 8 bytes straddle its end, wrote outside the image (an access violation in the new test without the check). The check is in the loader rather than in Pe::relocations, which also reads file-layout images and has no mapping size.
227e1a0 to
c1776d8
Compare
|
Test run of Tested
Review: A relocation whose target plus width (8 for DIR64, 4 for HIGHLOW) goes past Not tested: no retail title or regression run (I have no unpacked game), no Run and review by Claude Code (Claude Opus 5.5) on this machine; the review points were checked against the code. |
|
Regression run on a retail title for #291, since Not tested lists it: head Tested
The second block is the local merge onto Not tested
AI use
|
|
Regression run of Against the limits in CONTRIBUTING.md: 90 % of AMD Radeon RX 9070 (RDNA4, driver 32.0.32029.2010), Ryzen 7 7800X3D, 32 GB, Windows 11 build 26300, Rust 1.100.0, AI use: Claude Code (Claude Opus 5.5) built both trees and ran |
|
Verification on RTX 3060 Ti (Windows 11), branch merged with current
Thanks! |
…ge relocations fail (port upstream xcl-dev#1416 + xcl-dev#291, loader pair) Windows loader.rs: verbatim xcl-dev#1416 (section_protect_range, wrapping_sub/ wrapping_add delta incl. TLS adj, checked_add section copies, header clamp) + xcl-dev#291 (rva+width>size guard). 3 upstream tests land verbatim. Linux loader_linux.rs twin: wrapping u64 delta in apply_relocations (unknown-kind guard now runs before warn-continue, matching upstream), checked_add section copies. 2 Linux-shaped twin tests (high-base wrapping, outside-image errors); protect_image already clamped via saturating_add. Failing-first: grafted high-base test on pre-fix tree FAILED (attempt to subtract with overflow); green post-fix.
…stream xcl-dev#1367) Ports live head 8dbc465 (still OPEN vs upstream/main). pe.rs: directory descriptor/block sizes bounded by remaining dir data; export AddressOf tables bounded by dir+image; thunk slot/entry RVAs + name strings checked_add-bounded with size_of_image clamps; Mapped rva_to_offset/tail image clamps; all 5 parser tests as-is. loader.rs: section va+mapped outside-image fail; import IAT-slot and delay-HMODULE outside-image fails. Loader reloc guards + page-span clamp already on linux (xcl-dev#291 / section_protect_range helper) — not re-ported. Failing-first: truncated_directories_are_rejected FAILED pre-fix; Mapped-layout probe proved past-dir-end acceptance pre-fix (removed). Gates: both checks 0 errors, lib 737/0/1 (+5), title e2e 12 GPU-only FAILs, retail HOLDS at +0x2237320.
| // the preferred address is taken, so the image is relocated | ||
| let blocker = unsafe { VirtualAlloc(BASE as *const c_void, 0x10000, MEM_RESERVE, PAGE_NOACCESS) }; | ||
| assert!(!blocker.is_null()); | ||
| for (target, name) in [(0x10_0000u32, "xcl_reloc_past_end.dll"), (0x1FFC, "xcl_reloc_straddles_end.dll")] { |
There was a problem hiding this comment.
Could this regression also emit an IMAGE_REL_BASED_HIGHLOW entry whose 4-byte target straddles SizeOfImage? The bound check has a separate width-4 branch for HIGHLOW, but with_reloc currently hardcodes DIR64, so the new boundary test only exercises the 8-byte path. This focused case would guard the 4-byte relocation boundary too. AI-assisted review: I inspected the diff and existing test; I did not run tests.
|
Overlap: #1367 (opened later) adds the same width-aware relocation bounds check in loader.rs map_image_ex, along with wider PE parser, import and section bounds checks. It has no loader test of the relocation path. This PR is first and its test AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human. |
Hardening, not a playability fix: no title is known to hit this path.
map_imagepatchedbase + rvafor every relocation without checking the target against the mapping. The entries come from the file, so a target pastSizeOfImage, or a DIR64 whose 8 bytes straddle its end, wrote outside the image. #178 made the RVA arithmetic overflow-safe but did not bound the targets. The check is in the loader, not inPe::relocations, because that also reads file-layout images and has no mapping size.Part of #106.
What is in it
crates/xcl/src/loader.rs: before patching, the target plus its width (8 for DIR64, 4 for HIGHLOW) must fit inSizeOfImage. Otherwise the load fails with "relocation at … outside the image" and the mapping is freed.crates/xcl/src/loader.rs(tests):relocations_outside_the_image_are_errorsusestiny_dllwith its preferred address taken. Covers a target past the end, a DIR64 straddling the end, and a control target inside the image that is still relocated by the right delta.Tested
cargo test --workspace -- --test-threads=4: 652 passed, 0 failed, 40 ignored. SKIPPED GPU tests:gpu_wave32_program_in_wave64_hardware,gpu_geometry_wave32_prefix_count_over_a_mask(no wave64)Regression run
Not run yet. I'll add both
xcl-smokeblocks (main and this PR's head) and mark the PR ready once I have a title folder to run against. Until then it stays a draft.Not tested
scripts/smoke.ps1regression run on a real title (see above)AI use