fix(relinker): validate SysV hash chain bounds and 32-bit geometry overflow in symbol resolution #15903

Merged
slopgobblercobbler merged 1 commit from upstream-pr/15903 into main 2026-11-21 09:17:23 +00:00
slopgobblercobbler commented 2026-11-04 22:49:18 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by slopgobblercobbler on 2026-11-04T22:49:18Z.


What

  • Audit and harden dynamic symbol table resolution and hash lookup bounds in relinker code analysis (CodeInstructionCollector.cpp) and strict NID reachability filtering (StrictNidFilter.cpp).
  • Enforce strict 32-bit geometry arithmetic overflow validation for SysV dynamic symbol hash headers (nbucket, nchain) and GNU dynamic hash headers (bloomCount, bucketCount) to prevent 32-bit wrap-around before table range translation.
  • Validate SysV hash chain table indices ensuring each chain index is strictly bounded (chain < nchain), throwing explicit invalid SysV hash chain index on corrupted or maliciously crafted hash records.
  • Bound GNU hash chain traversal against maximum allowable symbol table entries derived from image bounds (symbolCount <= imageSize / 24) to eliminate potential runaway loops on malformed chains.
  • Expand unit test suite in StrictNidFilterTests.cpp covering SysV hash chain bounds, SysV geometry overflow, and GNU hash geometry overflow.

Tested

  • Built cleanly on Windows with MSVC C++20.
  • Verified test suite pass rate: strict_nid_filter_tests (all pass) and test_gnu_hash_analysis (all pass).
  • Passed conventions check with 0 findings: python tools/check_conventions.py --base upstream/main --head HEAD.

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 and the licence notice of code adapted from upstream (see AGENTS.md)
  • 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:5162882204 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15903). Originally posted by [slopgobblercobbler](https://github.com/slopgobblercobbler) on 2026-11-04T22:49:18Z. --- ### What - Audit and harden dynamic symbol table resolution and hash lookup bounds in relinker code analysis (CodeInstructionCollector.cpp) and strict NID reachability filtering (StrictNidFilter.cpp). - Enforce strict 32-bit geometry arithmetic overflow validation for SysV dynamic symbol hash headers (nbucket, nchain) and GNU dynamic hash headers (bloomCount, bucketCount) to prevent 32-bit wrap-around before table range translation. - Validate SysV hash chain table indices ensuring each chain index is strictly bounded (chain < nchain), throwing explicit invalid SysV hash chain index on corrupted or maliciously crafted hash records. - Bound GNU hash chain traversal against maximum allowable symbol table entries derived from image bounds (symbolCount <= imageSize / 24) to eliminate potential runaway loops on malformed chains. - Expand unit test suite in StrictNidFilterTests.cpp covering SysV hash chain bounds, SysV geometry overflow, and GNU hash geometry overflow. ### Tested - Built cleanly on Windows with MSVC C++20. - Verified test suite pass rate: strict_nid_filter_tests (all pass) and test_gnu_hash_analysis (all pass). - Passed conventions check with 0 findings: python tools/check_conventions.py --base upstream/main --head HEAD. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [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) and the licence notice of code adapted from upstream (see AGENTS.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
ahmadmuj commented 2026-11-06 06:29:43 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ahmadmuj on 2026-11-06T06:29:43Z.

Review: COMMENTED


Checked head 9837a66e9391187e8faf9ab518d6b742ed1f36b0, PR base 6a37dfbed9, against main fa134d9001. Relinker builds and control_flow_graph pass on both; head conventions pass.

FindRelativeJumpTables can now loop forever on rejected displacements. In RelativeJumpTables.cpp:340-341, continue skips pos += info.Length. Bytes {0x75,0x80}, segment address 0, function range [0,2) reproduce this: unchanged head source times out after 2 seconds; main returns no tables immediately. The LEA guards at 423-424 also skip pos = next. Bytes {0x48,0x8d,0x05,0x80,0xff,0xff,0xff,0xcc,0xc3}, address 0, ranges [0,7) and [8,9) reproduce that separately.

Could both rejection paths advance or terminate the scan, with regression tests? Positive-overflow cases also time out; valid branch/LEA and exact nonempty-table controls pass. The gap scan completes because decoded[pos] prevents repetition. These are bounded synthetic scanner probes, not a title reproduction.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5796584152 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15903#pullrequestreview-5796584152). Originally posted by [ahmadmuj](https://github.com/ahmadmuj) on 2026-11-06T06:29:43Z. **Review:** COMMENTED --- Checked head 9837a66e9391187e8faf9ab518d6b742ed1f36b0, PR base 6a37dfbed92929b84bfed73a7c6e28005ee51ac2, against main fa134d9001e54ffe6444b2417b3af702da0eac83. Relinker builds and control_flow_graph pass on both; head conventions pass. FindRelativeJumpTables can now loop forever on rejected displacements. In RelativeJumpTables.cpp:340-341, continue skips pos += info.Length. Bytes {0x75,0x80}, segment address 0, function range [0,2) reproduce this: unchanged head source times out after 2 seconds; main returns no tables immediately. The LEA guards at 423-424 also skip pos = next. Bytes {0x48,0x8d,0x05,0x80,0xff,0xff,0xff,0xcc,0xc3}, address 0, ranges [0,7) and [8,9) reproduce that separately. Could both rejection paths advance or terminate the scan, with regression tests? Positive-overflow cases also time out; valid branch/LEA and exact nonempty-table controls pass. The gap scan completes because decoded[pos] prevents repetition. These are bounded synthetic scanner probes, not a title reproduction.
descambiado commented 2026-11-19 12:54:49 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by descambiado on 2026-11-19T12:54:49Z.

Review: COMMENTED


Independent check of the RelativeJumpTables.cpp changes, plus a read of the hash changes, at head bdd07bb (merge-base d3074de). Ubuntu 24.04 (WSL2), GCC 13.3.

Overflow. I built relinker_core with ASan and UBSan and ran a randomized driver over the analysis and conversion entry points (FindRelativeJumpTables, FindTrailingRelativeJumpTable, FindReplacedPltStubs, FindSceCodeEnd, SceUnwindRanges, AnalyzeStrictReachability, ReadRelativeTableTargets, Amd64OnlyConverter for Intel and Rosetta, CodeInstructionCollector) with segment bases around 0, 2^63 and 2^64. 56,000 seeds on this head: no report and no timeout. The same driver on main hits signed overflow at lines 114, 335, 374 and 413 within 4,000 seeds. The two probes from ahmadmuj's review terminate here.

Hash changes. I read the SysV and GNU parts of StrictNidFilter.cpp. The geometry checks are bounded and the GNU symbol count follows the usual last bucket, then chain terminator walk. I found nothing wrong.

Tests (UBSan, Linux). With the PR's tests kept and its sources reverted to the merge-base, strict_nid_filter fails without the change, which is what you want. control_flow_graph, reloc_table_bounds and relr_relocations pass either way, so on Linux they do not catch the signed overflow in RelativeJumpTables.cpp. A segment mapped at or above 2^63 with a negative branch displacement does (that is what #23003 tests).

Not covered: Windows, and the PltCompactor and RelinkerPipeline changes beyond the driver.

Two things for the author and the maintainers. The PR mixes several topics (hash bounds, 32-bit geometry, address arithmetic), which CONTRIBUTING asks to split. And #23003 touches the same four sites, so someone needs to say which goes first (Depends on).

AI-assisted: yes (Claude Code wrote the driver and ran the checks).

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5975390473 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15903#pullrequestreview-5975390473). Originally posted by [descambiado](https://github.com/descambiado) on 2026-11-19T12:54:49Z. **Review:** COMMENTED --- Independent check of the `RelativeJumpTables.cpp` changes, plus a read of the hash changes, at head bdd07bb (merge-base d3074de). Ubuntu 24.04 (WSL2), GCC 13.3. **Overflow.** I built `relinker_core` with ASan and UBSan and ran a randomized driver over the analysis and conversion entry points (`FindRelativeJumpTables`, `FindTrailingRelativeJumpTable`, `FindReplacedPltStubs`, `FindSceCodeEnd`, `SceUnwindRanges`, `AnalyzeStrictReachability`, `ReadRelativeTableTargets`, `Amd64OnlyConverter` for Intel and Rosetta, `CodeInstructionCollector`) with segment bases around 0, 2^63 and 2^64. 56,000 seeds on this head: no report and no timeout. The same driver on main hits signed overflow at lines 114, 335, 374 and 413 within 4,000 seeds. The two probes from ahmadmuj's review terminate here. **Hash changes.** I read the SysV and GNU parts of `StrictNidFilter.cpp`. The geometry checks are bounded and the GNU symbol count follows the usual last bucket, then chain terminator walk. I found nothing wrong. **Tests (UBSan, Linux).** With the PR's tests kept and its sources reverted to the merge-base, `strict_nid_filter` fails without the change, which is what you want. `control_flow_graph`, `reloc_table_bounds` and `relr_relocations` pass either way, so on Linux they do not catch the signed overflow in `RelativeJumpTables.cpp`. A segment mapped at or above 2^63 with a negative branch displacement does (that is what #23003 tests). Not covered: Windows, and the `PltCompactor` and `RelinkerPipeline` changes beyond the driver. Two things for the author and the maintainers. The PR mixes several topics (hash bounds, 32-bit geometry, address arithmetic), which CONTRIBUTING asks to split. And #23003 touches the same four sites, so someone needs to say which goes first (`Depends on`). AI-assisted: yes (Claude Code wrote the driver and ran the checks).
MarcZX10 commented 2026-11-19 13:14:21 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-19T13:14:21Z.

Review: COMMENTED


Reviewed — no blocking findings

The inspected changes add bounds checks for malformed ELF hash data and signed address calculations; I found no verified blocking defect, but could not run the reported checks.

What I ran

Reviewed head bdd07bbaf45d2ceafbed5eef7c73fe619a146a35 using repo_read.py reader tools. No build, tests, or conventions check was run.

Results

Check Result Note
Diff review passed Prepared diff and manifest inspected
Build and tests not run No execution environment available
Conventions check not run Description reports it passed

Findings

Blocking

None verified in the inspected changes.

Non-blocking

None.

Sources

Reviewed changed lines and targeted source context at the pinned head: CodeInstructionCollector.cpp, StrictNidFilter.cpp, RelativeJumpTables.cpp, RelinkerPipeline.cpp, and other changed files listed in the review manifest.

Not verified

The prepared diff and manifest cover all 14 changed files, and all 14 were inspected in the diff. Targeted source ranges were read from 11 changed files; full file contents were not read, and a source read for ControlFlowGraphTests.cpp could not be completed. Build, test, conventions, and console behavior were not verified. The author reports Windows MSVC C++20 build and test success, plus a clean conventions check.

To get this to a good state

Nothing is required. Optional: run the reported build, tests, and conventions check on this head before merge.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5975676563 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15903#pullrequestreview-5975676563). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-19T13:14:21Z. **Review:** COMMENTED --- # Reviewed — no blocking findings The inspected changes add bounds checks for malformed ELF hash data and signed address calculations; I found no verified blocking defect, but could not run the reported checks. ## What I ran Reviewed head `bdd07bbaf45d2ceafbed5eef7c73fe619a146a35` using `repo_read.py` reader tools. No build, tests, or conventions check was run. ## Results | Check | Result | Note | |---|---|---| | Diff review | passed | Prepared diff and manifest inspected | | Build and tests | not run | No execution environment available | | Conventions check | not run | Description reports it passed | ## Findings ### Blocking None verified in the inspected changes. ### Non-blocking None. ## Sources Reviewed changed lines and targeted source context at the pinned head: [CodeInstructionCollector.cpp](https://github.com/boykopovar/AnyPS5/blob/bdd07bbaf45d2ceafbed5eef7c73fe619a146a35/core/relinker/relinker/src/analysis/CodeInstructionCollector.cpp), [StrictNidFilter.cpp](https://github.com/boykopovar/AnyPS5/blob/bdd07bbaf45d2ceafbed5eef7c73fe619a146a35/core/relinker/relinker/src/analysis/UnusedNidFilter/StrictNidFilter.cpp), [RelativeJumpTables.cpp](https://github.com/boykopovar/AnyPS5/blob/bdd07bbaf45d2ceafbed5eef7c73fe619a146a35/core/relinker/relinker/src/analysis/RelativeJumpTables.cpp), [RelinkerPipeline.cpp](https://github.com/boykopovar/AnyPS5/blob/bdd07bbaf45d2ceafbed5eef7c73fe619a146a35/core/relinker/relinker/src/pipeline/RelinkerPipeline.cpp), and other changed files listed in the review manifest. ## Not verified The prepared diff and manifest cover all 14 changed files, and all 14 were inspected in the diff. Targeted source ranges were read from 11 changed files; full file contents were not read, and a source read for `ControlFlowGraphTests.cpp` could not be completed. Build, test, conventions, and console behavior were not verified. The author reports Windows MSVC C++20 build and test success, plus a clean conventions check. ## To get this to a good state Nothing is required. Optional: run the reported build, tests, and conventions check on this head before merge.
MarcZX10 commented 2026-11-20 11:12:41 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-20T11:12:41Z.

Review: COMMENTED


Reviewed — comments

The change adds bounds checks for malformed hash tables and address arithmetic, but the review bundle does not include file contents, so the full review and approval criteria could not be completed.

What I ran

  • Inspected the prepared diff and manifest for head f4d791315fdd3cdbfb901b99d16838bcaa53ed52.
  • Used the pinned reader to inspect targeted ranges in CodeInstructionCollector.cpp and StrictNidFilter.cpp.
  • No build or test commands were run.

Results

Check Result Note
Diff and manifest review passed All changed paths were listed as included.
Targeted source review passed Hash table parsing and symbol bounds inspected.
Build and tests not run No commands were run.

Findings

Blocking

None identified in the inspected code.

Non-blocking

  • The new SysV chain validation scans every chain entry. This is bounded by the validated file range, but may add noticeable work for unusually large valid hash tables (core/relinker/relinker/src/analysis/CodeInstructionCollector.cpp:394).

Not verified

The prepared bundle did not contain review/files/ full-text files, and the prompt-provided reader interface was unavailable as a callable command. I inspected only the diff and targeted repository ranges, not every changed file listed in the manifest. Consequently, the complete behavior, tests, and author-reported Windows build and test results are not verified. Excluded by review: full contents of all changed files beyond the inspected source ranges; no paths were marked excluded in the manifest.

To get this to a good state

Nothing is required. Optional: run the stated Windows build and test suite against this exact head and include the results with the review.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5991774034 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15903#pullrequestreview-5991774034). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-20T11:12:41Z. **Review:** COMMENTED --- # Reviewed — comments The change adds bounds checks for malformed hash tables and address arithmetic, but the review bundle does not include file contents, so the full review and approval criteria could not be completed. ## What I ran - Inspected the prepared diff and manifest for head `f4d791315fdd3cdbfb901b99d16838bcaa53ed52`. - Used the pinned reader to inspect targeted ranges in `CodeInstructionCollector.cpp` and `StrictNidFilter.cpp`. - No build or test commands were run. ## Results | Check | Result | Note | |---|---|---| | Diff and manifest review | passed | All changed paths were listed as included. | | Targeted source review | passed | Hash table parsing and symbol bounds inspected. | | Build and tests | not run | No commands were run. | ## Findings ### Blocking None identified in the inspected code. ### Non-blocking - The new SysV chain validation scans every chain entry. This is bounded by the validated file range, but may add noticeable work for unusually large valid hash tables (`core/relinker/relinker/src/analysis/CodeInstructionCollector.cpp:394`). ## Not verified The prepared bundle did not contain `review/files/` full-text files, and the prompt-provided reader interface was unavailable as a callable command. I inspected only the diff and targeted repository ranges, not every changed file listed in the manifest. Consequently, the complete behavior, tests, and author-reported Windows build and test results are not verified. Excluded by review: full contents of all changed files beyond the inspected source ranges; no paths were marked excluded in the manifest. ## To get this to a good state Nothing is required. Optional: run the stated Windows build and test suite against this exact head and include the results with the review.
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!15903
No description provided.