Repository navigation
Conversation
… map_image_ex Two overflow/bounds bugs in loader.rs: - Computing `delta = base as i64 - pe.image_base as i64` and applying `(v as i64 + delta)` overflowed signed i64 when `pe.image_base` was near `0x8000_0000_0000_0000` (above i64::MAX). Using unsigned wrapping_sub / wrapping_add handles every 64-bit base delta cleanly. - Step 6 passed unclamped `pe.size_of_headers` and `((s.mapped_size() as usize) + 0xFFF) & !0xFFF` to VirtualProtect, allowing oversized headers or section extents to alter page protections past `[base, base + size)`. Step 2 also used unchecked `src + raw` / `s.va + raw`. Clamp header and section VirtualProtect extents to `[0, size)` via section_protect_range() and use checked additions in section copy, with unit tests for both. Assisted-by: OpenCode (Gemini 4 Neon)
|
Full-suite run, since this PR has no test report yet. Tested exact head Tested
Not tested
AI use
|
|
Verification on RTX 3060 Ti (Windows 11), branch merged with current
Thanks! |
|
Test report for head Tested
Not tested
AI use
|
…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.
|
Nothing has happened on this PR for 3 days, so it is marked |
|
Not on main: main's AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human. |
Fixes two overflow and bounds bugs in
crates/xcl/src/loader.rs:map_image_excomputedlet delta = base as i64 - pe.image_base as i64and applied(v as i64 + delta), which panicked with signed overflow whenpe.image_basewas near0x8000_0000_0000_0000. Using unsignedwrapping_sub/wrapping_addhandles every 64-bit relocation and TLS base adjustment cleanly.pe.size_of_headersand((s.mapped_size() as usize) + 0xFFF) & !0xFFFtoVirtualProtect, allowing oversized headers or section extents to alter page protections past[base, base + size). Step 2 also used uncheckedsrc + raw/s.va + raw.This uses wrapping
u64arithmetic fordelta, clamps header and sectionVirtualProtectranges to[0, size)viasection_protect_range(), and uses checked addition in section copy.What is in it
crates/xcl/src/loader.rs: switchdeltato wrappingu64arithmetic; addsection_protect_range()and clampVirtualProtectextents tosize; usechecked_addfor section copy bounds; add unit testsrelocates_high_image_base_without_signed_overflow(verified panicking before the fix) andsection_protect_range_clamps_to_image_size.Tested
stable-x86_64-pc-windows-msvc), DXC 1.9.2609.5, debug (scripts/test.ps1) and release (scripts/smoke.ps1).\scripts\test.ps1(cargo build --workspace+cargo test --workspace -- --test-threads=4): 753 passed, 0 failed, 41 ignored (SKIPPED GPU tests: 2no wave64—gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask,gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware)cargo test -p xcl --lib loader::tests: 4 passed, 0 failed (relocates_high_image_base_without_signed_overflowpanicked with signed subtraction overflow before the fix)Regression run
main:
PR:
Not tested
AI use
loader.rs, wrote the fixes and unit tests, ran the test suite andscripts/smoke.ps1regression runs, and drafted this PR description.