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

Merged
treuenten merged 1 commit from upstream-pr/2091 into main 2026-10-10 04:43:53 +00:00
treuenten commented 2026-10-09 08:06:50 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by treuenten on 2026-10-09T08:06:50Z.


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 d70b8998:

  • 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 d5d6e577 (510/510).

Rebased onto main c963432d on 2026-10-10 with no change to the diff (now d1c14102). The linux and windows checks on the old head failed because they built on main 6cc0503d, from before #2099 added SPIRV-Headers to the Vulkan test targets. On c963432d 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

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4797803075 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2091). Originally posted by [treuenten](https://github.com/treuenten) on 2026-10-09T08:06:50Z. --- ### 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](https://github.com/treuenten/AnyPS5/actions/runs/37943413968)), using this repository's `build.yml` unchanged on this PR merged into `main` d70b8998: - 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 d5d6e577 (510/510). Rebased onto `main` c963432d on 2026-10-10 with no change to the diff (now d1c14102). The `linux` and `windows` checks on the old head failed because they built on `main` 6cc0503d, from before #2099 added SPIRV-Headers to the Vulkan test targets. On c963432d 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 - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
rmz-24 commented 2026-10-09 11:58:39 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by rmz-24 on 2026-10-09T11:58:39Z.


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

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

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6080399010 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2091#issuecomment-6080399010). Originally posted by [rmz-24](https://github.com/rmz-24) on 2026-10-09T11:58:39Z. --- 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`. d5d6e577 cherry-picked onto current `main` d70b8998 (applies cleanly). - `jmprel_table_bounds` passes. - Full ctest: 510/510, including the Windows PE execution tests. AI-assisted: yes
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!2091
No description provided.