fix(relinker): reject overlapping PT_LOAD segments before sizing the Windows image #1238
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1238"
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 boykopovar/AnyPS5. Originally posted by hashaam1217 on 2026-10-07T19:06:15Z.
What
relinker --windowscrashed with SIGSEGV on an ELF whose first PT_LOAD segment reaches past the end of the last one.WindowsLoadImagesorts the segments, sizesdataandpageFlagsfrom the end of the last segment, and checked for overlap inside the loop that copies each segment and marks its pages. The first segment's page loop ran pastpageFlagsbefore the next segment's overlap check could throw (AddressSanitizer: heap-buffer-overflow inWindowsLoadImage::WindowsLoadImage).Overlap is now checked in a pass of its own before anything is sized, so such an input fails with "Overlapping PT_LOAD memory ranges". Valid inputs are unchanged: when no segments overlap, the last segment's end is the largest end.
Found by fuzzing the relinker: an AddressSanitizer + UBSan build, inputs mutated from the fixtures of the relinker Python tests, in Linux,
--windows,--to-inteland guest-module modes. The fuzzer is not part of this PR.Tested
Ubuntu 24.04.5, GCC 13.3.0. Full build and
ctest: 399/399 passed.executable_segments: two new cases. The first segment's memory size is set to 2^52, overlapping the other segments and reaching past the last, and to 0x1300, overlapping only the next one. Both must fail with "Overlapping PT_LOAD memory ranges" and write no output. With the relinker frommainthe first case dies with SIGSEGV (returncode=-11).tools/check_conventions.py --base origin/main: passed.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-08T09:14:55Z.
Checked the overlap pre-pass against the diff, ran the build and full ctest on top of main (430/430) and reverted
WindowsLoadImage.cppto confirmexecutable_segmentsfails without it; theMappedAddress + MemorySizewrap is already rejected earlier in the constructor. Merging.