fix(relinker): bound ELF symbol name reads #1682

Closed
MarcZX10 wants to merge 1 commit from upstream-pr/1682 into main
MarcZX10 commented 2026-10-08 16:20:46 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-08T16:20:46Z.


What

Validate the ELF symbol table base and the selected symbol's four-byte name-offset field with subtraction-based bounds checks before deriving the field address. This prevents a malformed DT_OS_SYMTAB file offset from wrapping into the input image. The relinker only reads this four-byte field from each symbol entry, so the check covers the bytes it accesses.

Add parser integration cases for an out-of-file base, an offset near UINT64_MAX that previously wrapped, and a truncated name-offset field. Existing System V/OS-tag valid fixtures remain controls.

Tested

Linux: built relinker; ctest --test-dir build -R '^(string_table_bounds|optional_plt)$' --output-on-failure passed (2/2). Conventions and git diff --check passed.

Checklist

  • Based on current main; no other open PR implements this symbol-table bounds fix
  • One topic per PR; follow-ups go in a new pull request
  • 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
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4789733349 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1682). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-08T16:20:46Z. --- ### What Validate the ELF symbol table base and the selected symbol's four-byte name-offset field with subtraction-based bounds checks before deriving the field address. This prevents a malformed `DT_OS_SYMTAB` file offset from wrapping into the input image. The relinker only reads this four-byte field from each symbol entry, so the check covers the bytes it accesses. Add parser integration cases for an out-of-file base, an offset near `UINT64_MAX` that previously wrapped, and a truncated name-offset field. Existing System V/OS-tag valid fixtures remain controls. ### Tested Linux: built `relinker`; `ctest --test-dir build -R '^(string_table_bounds|optional_plt)$' --output-on-failure` passed (2/2). Conventions and `git diff --check` passed. ### Checklist - [x] Based on current `main`; no other open PR implements this symbol-table bounds fix - [x] One topic per PR; follow-ups go in a new pull request - [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 - [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
github-actions[bot] commented 2026-10-08 17:08:45 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-08T17:08:45Z.


Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
#1690 core/relinker/relinker/src/pipeline/RelinkerPipeline.cpp L219-220
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6065086840 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1682#issuecomment-6065086840). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-08T17:08:45Z. --- <!-- pr-overlap --> Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in **Depends on**. | Pull request | Conflicting files (lines on `main`) | Same exports | Same new files | |---|---|---|---| | #1690 | `core/relinker/relinker/src/pipeline/RelinkerPipeline.cpp` [L219-220](https://github.com/boykopovar/AnyPS5/blob/17350cf5fd54ad5c79ee495ed8e8615f4663bbd6/core/relinker/relinker/src/pipeline/RelinkerPipeline.cpp#L219-L220) | | |
MarcZX10 commented 2026-10-08 17:27:19 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-08T17:27:19Z.


Closing this as a duplicate of #1272: its current head already contains the same subtraction-based symbol-entry bounds check and has all four upstream checks passing. #1690 supplies the broader symbol-range regression coverage on top of #1272. Keeping both implementations open would leave competing guards in RelinkerPipeline.cpp.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6065408530 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1682#issuecomment-6065408530). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-08T17:27:19Z. --- Closing this as a duplicate of #1272: its current head already contains the same subtraction-based symbol-entry bounds check and has all four upstream checks passing. #1690 supplies the broader symbol-range regression coverage on top of #1272. Keeping both implementations open would leave competing guards in RelinkerPipeline.cpp.
Dextroid17 commented 2026-10-08 18:05:45 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-08T18:05:45Z.


Thanks for closing this in favour of #1272 — worth recording what I checked on the pair so a reviewer has it in one place:

  • #1272 is MERGEABLE/CLEAN on current main with all four checks green; I re-ran its negative control (implementation reverted, test kept -> fails; restored -> passes).
  • #1690 is stacked on it and supplies the integration coverage: both merge in order without conflict on today's main (2b297842), the full relinker suite is 38/38 on Linux, and with the bound reverted to main's symOff + 4 > raw.size() its two new tests fail — so they gate the fix.
  • Its UNSTABLE status is only the two Build jobs waiting for approval, not a failure.

No action needed from you; the evidence is in both threads for whoever takes the merge.

Written with AI assistance.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6066055681 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1682#issuecomment-6066055681). Originally posted by [Dextroid17](https://github.com/Dextroid17) on 2026-10-08T18:05:45Z. --- Thanks for closing this in favour of #1272 — worth recording what I checked on the pair so a reviewer has it in one place: - `#1272` is `MERGEABLE/CLEAN` on current `main` with all four checks green; I re-ran its negative control (implementation reverted, test kept -> fails; restored -> passes). - `#1690` is stacked on it and supplies the integration coverage: both merge in order without conflict on today's `main` (`2b297842`), the full relinker suite is 38/38 on Linux, and with the bound reverted to `main`'s `symOff + 4 > raw.size()` its two new tests fail — so they gate the fix. - Its `UNSTABLE` status is only the two Build jobs waiting for approval, not a failure. No action needed from you; the evidence is in both threads for whoever takes the merge. Written with AI assistance.

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