Repository navigation
fix(relinker): reject Linux RELATIVE addends outside the ELF image - #27980
JustDownTV wants to merge 1 commit into
Conversation
A RELATIVE relocation of the executable whose addend lies outside its PT_LOAD span was converted for Linux outputs and pointed into the metadata segment the relinker appends, while Windows and macOS outputs and guest modules on every target reject it with "Relative relocation addend is outside the ELF image". The Linux patcher now applies the guest module bound: from the lowest PT_LOAD address to the end of the highest one, the end included. RELR entries reach the same table.
|
No actionable comments were generated in the recent review. Walkthrough
Change: Bug fix Merge Risk:
|
arcwiser
left a comment
There was a problem hiding this comment.
Reviewed exact head 6ff7a5e1f7b014b194c5af9937e45146ffa9f872.
The check applies the same inclusive image-span rule already used by GuestImageReader and WindowsLoadImage, handles virtual-range overflow conservatively, and runs before fixed-base rebasing can move an invalid addend into the relinker's appended segment. RELR entries are folded into RelaData, so they reach the check. I also verified that a RELATIVE entry cannot bypass it through RelaPltData: RelinkerPipeline rejects every PLT relocation type other than R_X86_64_JUMP_SLOT before patching.
The regression matrix covers the lower bound, an interior address, the inclusive image end, positive out-of-range values, negative addends, all Linux modes, and parity with Windows/macOS.
Local source-level validation:
python tools/check_conventions.py --base upstream/main— passedgit diff --check upstream/main...upstream/pr-27980— passed- merge-tree against current
upstream/main— clean
This workspace has no C/C++ compiler, so I could not independently execute the relinker cases; the PR reports the focused tests, RELR variant, and broader relinker suite from Windows. No blocking issue found.
|
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
|
Plyxen
left a comment
There was a problem hiding this comment.
Checked head 6ff7a5e1f7 on Windows 11 with WinLibs GCC 15.2 (Release), applied to main c6331cc61b together with 14 other open PRs.
tools/check_conventions.py --headandtools/debt_fold.py --checkpass, and the full build succeeds.jmprel_table_boundsandlinux_fixed_basepass in the full suite, with the relinker producing every output target on this Windows host.- Full CPU suite (5,146 tests): the only failures are
windows_read_trap_unknown, which fails onmaintoo (fixed in #28028), and theframe_capture_minimizeload timeout.
From reading the code: addend > end keeps an addend equal to the end of the last PT_LOAD, a one-past-the-end address, which the test pins with 0x1000.
AI-assisted: yes (Claude Code)
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed — looks good
Nothing blocks this change; the review found no verified defect in the changed code.
What I ran
Reviewed head 6ff7a5e1f7b014b194c5af9937e45146ffa9f872. I read the prepared description, commits, manifest and diff, plus all three changed files at the relevant hunks. I used repo_read.py to inspect targeted repository context. No build or test commands were run.
Results
| Check | Result | Note |
|---|---|---|
| Diff and target code review | passed | Changed behavior and callers inspected |
| Tests | not run | Author-reported results were not independently reproduced |
Findings
Blocking
None.
Non-blocking
None.
Not verified
No tests or build were run. I did not read portions of LinuxElfPatcher.cpp and the two test files outside the cited ranges. review/files.json was unavailable; the manifest lists all three changed files as included and reviewed.
To get this to a good state
Nothing is required.
ligmaSec
left a comment
There was a problem hiding this comment.
Ran jmprel_table_bounds, linux_fixed_base, and linux_load_pages on Linux with the PR applied. All passed, covering the relocation addend bounds checks and the valid fixed-base layout cases.
AI-assisted: yes.
What
A
R_X86_64_RELATIVErelocation of the executable whose addend lies outside itsPT_LOADspan was converted for Linux outputs (default, fixed base and--lazy-binding): with onePT_LOADat 0x0-0x1000 and an addend of 0x1008, the output slot points at 0x401008, inside thePT_LOADthe relinker appends for its dynamic strings, symbols and stubs. Windows and macOS outputs (WindowsLoadImage::GetRelocatedAddress) and guest modules on every target (GuestImageReader) already reject it withRelative relocation addend is outside the ELF image.LinuxElfPatcher::Patchnow checks each RELATIVE entry of the data relocation table against the boundGuestImageReaderuses: from the lowestPT_LOADaddress to the end of the highest one, the end included. RELR entries reach the same table and are covered too.test_jmprel_table_bounds.pyadds RELATIVE cases for the Linux, fixed-base, lazy, Windows and macOS outputs: addends 0, 0x200 and the image end 0x1000 convert, 0x1008, 0x5000 and -8 are rejected. Onmainthe Linux caseslinux-relative-addend-outside-1008,-5000and the lazy-8convert successfully. Intest_linux_fixed_base.py,negative-target(RELATIVE, addend -16) now stops at this check withRelative relocation addend is outside the ELF imageinstead ofRelocation target -16 lies below the image at a fixed Linux base, which still guards IRELATIVE.Tested
Windows 11, WinLibs GCC 15.2.0 (
15.2.0posix-14.0.0-ucrt-r7), relinker-only Release build.jmprel_table_boundsandlinux_fixed_basefail onmainand pass with the change;linux_load_bounds,relr_relocations,reloc_table_bounds,none_relocationsandgnu_hash_analysispass. A RELR variant of the same image gives the same results on the Linux outputs.ctest -j 16: 1167 of 1171 pass.pr_overlap_tools,windows_fixed_baseandwindows_address_spacefail the same way onmainon this machine;check_main_sync_CheckMainSyncGitTestsfails in itsgit submodule addsetup on this machine, and this change touches no tool.python3 tools/check_conventions.pypasses.python3 tools/pr_overlap.py --branch fix/relinker-linux-relative-addend-boundscould not compare fix(relinker): convert RELR tables and targets that span load segments #23861 and feat(relinker): record the host CPU features --to-avx output needs #24915, which conflict withmain; compared by hand, fix(relinker): convert RELR tables and targets that span load segments #23861 rewrites the range check afterRequireFileRangeand feat(relinker): record the host CPU features --to-avx output needs #24915 changes thePatchsignature and later blocks, so neither touches the lines or the check this change adds.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)Summary by CodeRabbit