fix(relinker): reject overlapping PT_LOAD segments in Linux output #10564
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/10564"
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 roboterspinne on 2026-10-24T10:15:24Z.
What
SeparateSharedLoadPagesinLinuxElfPatcher.cppsorts thePT_LOADsegments by address but never checks that their memory ranges are disjoint, andElfReaderdoes not either. The Windows and macOS images reject overlapping loads (WindowsLoadImage.cpp:29-35,Overlapping PT_LOAD memory ranges) and so do guest modules (GuestImageReader.cpp:48). The Linux output kept both headers; the kernel maps the later segment over the earlier one, so a writable load over the code replaced it with zeros and the program crashed with SIGSEGV at start. After the sort, adjacent loads whose ranges overlap now fail with the Windows message, at the address of the second load. The subtraction cannot underflow because the loads are sorted, and loads withp_memsz0 are already left out.--lazy-bindingand--linux-fixed-base.executable_segmentsnow runs itsoverlap-nextcase on all five targets.overlap-past-endstays on Windows and macOS, because every Linux target rejects it before the overlap check: the default and--linux-fixed-baseoutputs because the address lies outside the user address space,--lazy-bindingwithEntry stub call exceeds rel32 range.Tested
Ubuntu 24.04 x86_64, glibc 2.39, relinker-only Release build (
-DANYPS5_RELINKER_ONLY=ON -DBUILD_TESTING=ON); synthetic fixtures only, no title or homebrew.ctest --test-dir build-relinker -j4: 241/241 passed. The changedexecutable_segmentsfails against themainbinary atoverlap-nexton the Linux target, where the relink exits 0.main, thetest_executable_tls_relocations.pyfixture with its writablePT_LOADmoved to address 0, over the code segment, relinks with exit 0 in the default mode and with--lazy-binding, and both outputs exit with SIGSEGV. With this change both relinks exit 2 withOverlapping PT_LOAD memory rangesand leave no output.python3 tools/check_conventions.py --base upstream/mainwith this title and description passed.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-24T10:23:24Z.
Review: APPROVED
Reviewed the Linux load-range check and its regression coverage against the existing Windows and guest-image checks. Sorting by mapped address makes the subtraction safe from underflow; comparing the distance with the previous segment size accepts exactly adjacent ranges and rejects actual overlap. Zero-size loads are excluded before the check. The new test exercises default Linux output, lazy binding, fixed-base Linux, Windows and macOS, and the reported synthetic case reproduces the prior invalid output. Approved.