Skip to content

fix(relinker): reject a relocation target whose range wraps the address space - #2091

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
treuenten:fix/relinker-callsite-range-wrap
Oct 10, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
treuenten:fix/relinker-callsite-range-wrap

Conversation

@treuenten

@treuenten treuenten commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

What

CallSiteResolver::ResolveCallSites takes lower_bound(address) and lower_bound(address + size). For a jump slot whose r_offset is 0xFFFFFFFFFFFFFFF8 or higher, address + 8 wraps, the upper iterator lands before the lower one, and the loop walks past the end of the map. On main the relinker dies with SIGSEGV (exit 139) in both Linux and --windows mode instead of failing with an error. Under ASan:

ERROR: AddressSanitizer: heap-buffer-overflow
    #0 in Relinker::CallSiteResolver::ResolveCallSites(...) CallSiteResolver.cpp:104
    #1 in Relinker::RelinkerPipeline::Relink(...) RelinkerPipeline.cpp:336

The resolver now throws RelinkerException("Relocation target range exceeds the address space") when the range does not fit, with the same size > max - begin check as EhFrameReader.cpp:173 and StrictNidFilter.cpp:26. 0xFFFFFFFFFFFFFFF7 still reaches the existing PT_LOAD containment check.

test_jmprel_table_bounds.py: the fixture's jump slot r_offset becomes a parameter; targets 0xFFFFFFFFFFFFFFF8, 0xFFFFFFFFFFFFFFFC and 0xFFFFFFFFFFFFFFFF must exit 2 with the new message and write no output.

No open pull request touches CallSiteResolver.cpp or this test.

Tested

macOS arm64 (Apple M3), AppleClang 21, relinker-only build:

  • ctest 34/34 in Release, and 34/34 with -fsanitize=address,undefined.
  • The new cases fail on main (exit -11) and pass with the fix.
  • python3 tools/check_conventions.py --base origin/main passes.

Full CI on my fork (run 37943413968), using this repository's build.yml unchanged on this PR merged into main d70b899:

  • Linux full build: ctest 516/516, including the lavapipe Vulkan tests.
  • Windows full build (MinGW GCC 15.2.0): ctest 507/507.
  • Relinker-only build on Linux (43/43), Windows (40/40) and macOS (38/38).
  • jmprel_table_bounds passes on Linux and Windows.

rmz-24 also ran the full Windows build with d5d6e57 (510/510).

Rebased onto main c963432 on 2026-10-10 with no change to the diff (now d1c1410). The linux and windows checks on the old head failed because they built on main 6cc0503, from before #2099 added SPIRV-Headers to the Vulkan test targets. On c963432 both full builds stop at the ctest registration check (agc_driver_recorder_tests is still in KNOWN_UNRUN). The same failure happens on main's own push build, so it is not caused by this change. After the rebase, the relinker-only ctest passes 49/49 on macOS.

Not run: any title.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes

🤖 Generated with Claude Code

@rmz-24

rmz-24 commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

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. d5d6e57 cherry-picked onto current main d70b899 (applies cleanly).

  • jmprel_table_bounds passes.
  • Full ctest: 510/510, including the Windows PE execution tests.

AI-assisted: yes

…ss space

A jump slot whose r_offset is 0xFFFFFFFFFFFFFFF8 or higher makes
targetGotOrPltAddress + 8 wrap, so the upper lower_bound lands before
the lower one and the call-site loop walks past the end of the map
(SIGSEGV; ASan heap-buffer-overflow in ResolveCallSites).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@treuenten
treuenten force-pushed the fix/relinker-callsite-range-wrap branch from d5d6e57 to d1c1410 Compare October 10, 2026 03:08
oneandonlydean added a commit to oneandonlydean/AnyPS5 that referenced this pull request Oct 10, 2026
oneandonlydean added a commit to oneandonlydean/AnyPS5 that referenced this pull request Oct 10, 2026
@oneandonlydean
oneandonlydean merged commit 1b5ebc6 into boykopovar:main Oct 10, 2026
12 checks passed
SleglJan pushed a commit to SleglJan/AnyPS5 that referenced this pull request Oct 10, 2026
…te-range-wrap

fix(relinker): reject a relocation target whose range wraps the address space
@treuenten
treuenten deleted the fix/relinker-callsite-range-wrap branch October 10, 2026 13:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants