fix(relinker): reject unsigned address overflow for relative uleb128 unwind encodings #11991

Closed
slopgobblercobbler wants to merge 1 commit from upstream-pr/11991 into main
slopgobblercobbler commented 2026-10-27 15:41:54 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by slopgobblercobbler on 2026-10-27T15:41:54Z.


What

Extends the exception frame reader unsigned unwind pointer bounds checking to cover DW_EH_PE_uleb128 (encoding & 0x0F == 1). Unsigned relative unwind encodings cannot express negative displacements; when added to a base address where value > std::numeric_limits<VirtualAddress>::max() - base, the reader now rejects the overflow with RelinkerException("Strict filter: unwind pointer address overflowed", field) rather than wrapping modulo 2^64.

Also adds an unwind record test exercising relative DW_EH_PE_uleb128 overflow on high mapped addresses and updates docs/dev/debt/relinker.md.

Tested

  • Unit test unwind_record_bounds (18 cases passed including DW_EH_PE_uleb128 relative overflow).
  • Relinker test suite (strict_nid_filter).
  • Windows 11 host verification courtesy of @JJenkx: Windows 11 Enterprise 10.0.22621, WinLibs GCC 15.2.0 UCRT r7, Ninja, Release; all 376 relinker CTests pass in each of 3 runs (-DANYPS5_RELINKER_ONLY=ON -DBUILD_TESTING=ON).
  • macOS arm64 verification courtesy of @rooklz: unwind_record_bounds_tests passed 18/18; negative control with EhFrameReader.cpp reverted to main verified failing.
  • python tools/check_conventions.py --base upstream/main --head HEAD passed with 0 findings.

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 under Silent stubs in their library's technical debt file
  • 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
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5036778823 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11991). Originally posted by [slopgobblercobbler](https://github.com/slopgobblercobbler) on 2026-10-27T15:41:54Z. --- ### What Extends the exception frame reader unsigned unwind pointer bounds checking to cover `DW_EH_PE_uleb128` (`encoding & 0x0F == 1`). Unsigned relative unwind encodings cannot express negative displacements; when added to a base address where `value > std::numeric_limits<VirtualAddress>::max() - base`, the reader now rejects the overflow with `RelinkerException("Strict filter: unwind pointer address overflowed", field)` rather than wrapping modulo 2^64. Also adds an unwind record test exercising relative `DW_EH_PE_uleb128` overflow on high mapped addresses and updates `docs/dev/debt/relinker.md`. ### Tested - Unit test `unwind_record_bounds` (18 cases passed including DW_EH_PE_uleb128 relative overflow). - Relinker test suite (`strict_nid_filter`). - Windows 11 host verification courtesy of @JJenkx: Windows 11 Enterprise 10.0.22621, WinLibs GCC 15.2.0 UCRT r7, Ninja, Release; all 376 relinker CTests pass in each of 3 runs (`-DANYPS5_RELINKER_ONLY=ON -DBUILD_TESTING=ON`). - macOS arm64 verification courtesy of @rooklz: `unwind_record_bounds_tests` passed 18/18; negative control with `EhFrameReader.cpp` reverted to `main` verified failing. - `python tools/check_conventions.py --base upstream/main --head HEAD` passed with 0 findings. ### 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 under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [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] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
rooklz commented 2026-10-28 01:58:21 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by rooklz on 2026-10-28T01:58:21Z.

Review: COMMENTED


I reproduced this on macOS arm64 (relinker-only Release, head ea7b82e58f, base e0cd1259a9).

The new case discriminates. unwind_record_bounds_tests passes 18/18 on head. With only EhFrameReader.cpp reverted to main, the same test binary fails (Unwind record validation failed). Full build OK; ctest 360/361. The one failure is patch_advisor_unit, an environment issue on my side: I built under /tmp, which macOS resolves to /private/tmp. Your diff doesn't touch it.

A consistency problem with the new rule. ULEB128 is not narrower than a pointer. It encodes the full 64-bit range (10 bytes). So it can carry the same modulo-2^64 backward displacement that DW_EH_PE_absptr / DW_EH_PE_udata8 carry, and the debt entry keeps those on purpose ("wraps modulo 2^64 to accommodate backward offsets, as standard DWARF unwinders add them"). The udata2/udata4 rejection works because a 16- or 32-bit value cannot reach the wrap. That argument doesn't carry over to uleb128.

Probe: the existing belowPcrelUdata8 fixture (pc-relative FDE begin pointing back to 0x800), with the begin field re-encoded as DW_EH_PE_pcrel|DW_EH_PE_uleb128 (0x11) holding the same value 0x800 - 0x1010:

base main head
backward pc-rel, udata8 accepted, begin 0x800 accepted, begin 0x800
same displacement, uleb128 accepted, begin 0x800 rejected: unwind pointer address overflowed

So the PR now treats two encodings of the same pointer value differently. The new debt sentence also groups uleb128 with the narrow encodings for a reason (no negative displacements) that applies to udata8 just as much. I see two consistent options:

  1. Keep uleb128 in the pointer-width wrapping group: no source change, and add DW_EH_PE_uleb128 to the absptr/udata8 sentence in the debt entry. Or:
  2. Reject wrapping for all unsigned relative encodings, including udata8/absptr. That reverses the documented choice and breaks the existing belowPcrelUdata8 / belowDatarelUdata8 fixtures, so it would need its own justification.

Neither option is measured on the console. The debt entry says unwind validation for out-of-range displacements is unmeasured, so the current documented behaviour (wrap at pointer-width-capable encodings) looks like the safer default.

Minor: pr_overlap reports docs/dev/debt/relinker.md as not compared against #5021/#7173/#7531/#10861/#11192. #7173 and #7531 append lines right after this entry (@@ -47,3 +47,4 @@), so whichever lands second will probably need a rebase. #5021/#10861/#11192 touch other entries.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5676852692 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11991#pullrequestreview-5676852692). Originally posted by [rooklz](https://github.com/rooklz) on 2026-10-28T01:58:21Z. **Review:** COMMENTED --- I reproduced this on macOS arm64 (relinker-only Release, head `ea7b82e58f`, base `e0cd1259a9`). **The new case discriminates.** `unwind_record_bounds_tests` passes 18/18 on head. With only `EhFrameReader.cpp` reverted to `main`, the same test binary fails (`Unwind record validation failed`). Full build OK; ctest 360/361. The one failure is `patch_advisor_unit`, an environment issue on my side: I built under `/tmp`, which macOS resolves to `/private/tmp`. Your diff doesn't touch it. **A consistency problem with the new rule.** ULEB128 is not narrower than a pointer. It encodes the full 64-bit range (10 bytes). So it can carry the same modulo-2^64 backward displacement that `DW_EH_PE_absptr` / `DW_EH_PE_udata8` carry, and the debt entry keeps those on purpose ("wraps modulo 2^64 to accommodate backward offsets, as standard DWARF unwinders add them"). The `udata2`/`udata4` rejection works because a 16- or 32-bit value cannot reach the wrap. That argument doesn't carry over to `uleb128`. Probe: the existing `belowPcrelUdata8` fixture (pc-relative FDE begin pointing back to 0x800), with the begin field re-encoded as `DW_EH_PE_pcrel|DW_EH_PE_uleb128` (`0x11`) holding the same value `0x800 - 0x1010`: | | base `main` | head | |---|---|---| | backward pc-rel, `udata8` | accepted, begin `0x800` | accepted, begin `0x800` | | same displacement, `uleb128` | accepted, begin `0x800` | **rejected**: `unwind pointer address overflowed` | So the PR now treats two encodings of the same pointer value differently. The new debt sentence also groups `uleb128` with the narrow encodings for a reason (no negative displacements) that applies to `udata8` just as much. I see two consistent options: 1. Keep `uleb128` in the pointer-width wrapping group: no source change, and add `DW_EH_PE_uleb128` to the absptr/udata8 sentence in the debt entry. Or: 2. Reject wrapping for all unsigned relative encodings, including `udata8`/`absptr`. That reverses the documented choice and breaks the existing `belowPcrelUdata8` / `belowDatarelUdata8` fixtures, so it would need its own justification. Neither option is measured on the console. The debt entry says unwind validation for out-of-range displacements is unmeasured, so the current documented behaviour (wrap at pointer-width-capable encodings) looks like the safer default. Minor: `pr_overlap` reports `docs/dev/debt/relinker.md` as not compared against #5021/#7173/#7531/#10861/#11192. #7173 and #7531 append lines right after this entry (`@@ -47,3 +47,4 @@`), so whichever lands second will probably need a rebase. #5021/#10861/#11192 touch other entries. AI-assisted: yes

Pull request closed

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!11991
No description provided.