fix(relinker): validate translated load segment file ranges #2068
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2068"
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 deadpoods on 2026-10-09T06:34:15Z.
What
ElfReader::TranslateVirtualAddresscould wrap aPT_LOADfile offset and return a location in unrelated input bytes. A synthetic ELF withp_offset=0xfffffffffffff000,p_vaddr=0x2000,p_filesz=0x2000andDT_STRTAB=0x3600translates to file offset0x600after wrapping. On unmodified main, Linux conversion succeeds and emitsDT_NEEDED=libwrongx.prxfrom those unrelated bytes. The valid control emitslibkernel.prx.Check the selected load segment's complete file range with the existing subtraction-based
_rangeFitshelper before adding the address displacement. The malformed input now exits 2 withSegment offset out of bounds (offset 0xfffffffffffff000)and creates neither an executable nor a registry. Windows also rejects it in the shared parser, before its existing PE-specific validation.The ELF gABI, sections 7.1 and 7.2 defines
p_offsetas the start of a segment's file image andp_fileszas its extent. The check follows the existingElfReader::ReadSegmentcontract, which rejects a segment whose complete file range exceeds the input. This deliberately rejects truncated segments even when the requested byte itself is inside the file.Extend the already registered
elf_offsetstest with 20 conversions: valid mappings, the first file-backed byte, a segment ending exactly at EOF, wrapping/past-EOF offsets, truncated and oversized extents, an address at the segment's exclusive end, and an empty segment. Invalid cases require exit 2, the expected diagnostic, and no output or registry. Valid Linux controls inspect the emitted dynamic table and dependency name; Windows controls verify successful PE generation. Existing assertions are retained.This is the deferred file-offset translation gap recorded in #1690. It does not duplicate that PR's symbol-boundary tests or #1272's symbol guard. Open #1087 and #1956 change other
ElfReadermethods; #1446 bounds RELA tables and #1943 handles Linux layout-address overflow. The audit reviewed all 558 open PRs and current relinker/ELF issues on 9 October 2026; no equivalent implementation was found. No prerequisite is needed.Tested
macOS 26.6.2 (25G83), x86-64; AppleClang 21.0.0; CMake 4.4.4; Ninja 1.13.2; Python 3.13. Relinker-only Release build, without third-party submodules or system libraries. Base:
f145139676a48306681d3a4d5fabf83938759daf, refreshed from upstream main before final review.elf_offsetsagainst a saved, unmodified baseline binary: failed attranslation-offset-wrap, because Linux returned 0 and wrote an executable instead of rejecting the input. All three new valid controls passed in both output modes before that failure.elf_offsets: passed (1.84 s).elf_offsetstook 1.67 s.python3 tools/check_conventions.py --base origin/main --title 'fix(relinker): validate translated load segment file ranges' --body <PR-description-file>: passed.python3 tools/check_test_registration.py ../build-relinker: all five test executables registered.git diff --checkand final diff review: passed; two source/test files, three production lines, no added comments, dependencies or investigation files.Build and test commands from the repository root:
CMake and Ninja were installed only in the task's work folder. Configuration used an explicit
CMAKE_MAKE_PROGRAMpath to that Ninja executable; the registration check used its directory onPATH.Limitations: the fixtures inspect Linux ELF and Windows PE output on macOS; compatible-host execution branches in the existing tests do not run here. No native Linux/Windows build, generated-game execution, real title, full system-library build, GPU test, or sanitizer run was performed. This check covers selected segments used by address translation; general load-segment validation and virtual-address-end overflow remain outside this patch.
Checklist
main; no other open PR implements the same fixImported from boykopovar/AnyPS5. Originally posted by rmz-24 on 2026-10-09T11:58:41Z.
Windows run, since the description notes it wasn't tested there: Windows 11 Pro 25H2 (10.0.26200.9457), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release, full build with
BUILD_TESTING=ON.b01704e7cherry-picked onto currentmaind70b8998(applies cleanly).elf_offsetspasses.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-09T20:08:35Z.
Closing: a
PT_LOADwhosep_offsetwraps doesn't occur in a title the console loads, and no real input is shown reaching it. The new rule also refuses truncated segments, which could stop a title that converts today. Please reopen with the title if one hits this.Pull request closed