Add bounds checking for relocation entries in RelinkerPipeline and up… #298

Closed
Praetorian0420 wants to merge 5 commits from upstream-pr/298 into main
Praetorian0420 commented 2026-10-01 23:23:23 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Praetorian0420 on 2026-10-01T23:23:23Z.


…date tests

What

Tested

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:
  • AI-assisted:
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4710787803 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/298). Originally posted by [Praetorian0420](https://github.com/Praetorian0420) on 2026-10-01T23:23:23Z. --- …date tests ### What ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. --> ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [ ] 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](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [ ] 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) - [ ] 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: <!-- #PR, or none --> - [ ] AI-assisted: <!-- yes / no -->
oneandonlydean commented 2026-10-04 05:40:17 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-04T05:40:17Z.


Thanks for looking at relocation bounds. A few things before this can go in. The template is empty, so please fill in What, Tested and the checklist, including its last line. The workflow edits (pr-overlap.yml and progress.yml) are a separate topic and should be their own PR. The new optional_plt case fails on both CI jobs: main already rejects DT_RELA 0x2000 with "Virtual address not mapped by any PT_LOAD segment" before your check runs, so the fixture needs a table that is mapped but runs past the end of the file (for example a valid DT_RELA with an oversized DT_RELASZ). Please also drop the merge commit and rebase onto current main.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5977005323 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/298#issuecomment-5977005323). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-04T05:40:17Z. --- Thanks for looking at relocation bounds. A few things before this can go in. The template is empty, so please fill in What, Tested and the checklist, including its last line. The workflow edits (pr-overlap.yml and progress.yml) are a separate topic and should be their own PR. The new optional_plt case fails on both CI jobs: main already rejects DT_RELA 0x2000 with "Virtual address not mapped by any PT_LOAD segment" before your check runs, so the fixture needs a table that is mapped but runs past the end of the file (for example a valid DT_RELA with an oversized DT_RELASZ). Please also drop the merge commit and rebase onto current main.
oneandonlydean commented 2026-10-05 23:37:48 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-05T23:37:48Z.


Thanks for bringing this up to date with main. The points from my earlier comment are still open (template, the separate workflow edits, the bad-rela-range fixture and the merge commits), and CI now also shows a second failure (run 37382987112, both jobs):

string_table_bounds: AssertionError: ('huge-size', 2, ... 'FAIL: Empty import symbol name (offset 0x300)')

The change in RelinkerPipeline.cpp replaces main's check

if (dynStrTabOffset > raw.size() || dynStrTabSize > raw.size() - dynStrTabOffset)
    throw RelinkerException("Dynamic string table is out of bounds", dynStrTabOffset);

with the two validateRelaRange calls, so an oversized DT_STRSZ is no longer rejected. Please keep that check and add the relocation checks next to it.

optional_plt still fails in bad-rela-range for the reason I gave before: DT_RELA = 0x2000 isn't mapped by any PT_LOAD, so the address translation rejects it before your check runs. A mapped DT_RELA with a DT_RELASZ that runs past the end of the file would reach the new check.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6005567092 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/298#issuecomment-6005567092). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-05T23:37:48Z. --- Thanks for bringing this up to date with main. The points from my earlier comment are still open (template, the separate workflow edits, the `bad-rela-range` fixture and the merge commits), and CI now also shows a second failure ([run 37382987112](https://github.com/boykopovar/AnyPS5/actions/runs/37382987112), both jobs): ``` string_table_bounds: AssertionError: ('huge-size', 2, ... 'FAIL: Empty import symbol name (offset 0x300)') ``` The change in `RelinkerPipeline.cpp` replaces main's check ```cpp if (dynStrTabOffset > raw.size() || dynStrTabSize > raw.size() - dynStrTabOffset) throw RelinkerException("Dynamic string table is out of bounds", dynStrTabOffset); ``` with the two `validateRelaRange` calls, so an oversized `DT_STRSZ` is no longer rejected. Please keep that check and add the relocation checks next to it. `optional_plt` still fails in `bad-rela-range` for the reason I gave before: `DT_RELA = 0x2000` isn't mapped by any `PT_LOAD`, so the address translation rejects it before your check runs. A mapped `DT_RELA` with a `DT_RELASZ` that runs past the end of the file would reach the new check.
oneandonlydean commented 2026-10-06 21:20:20 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-06T21:20:20Z.


Thanks for looking at relocation bounds. I'm closing this for now, since the points from 10-04 and 10-05 are still open and the branch has drifted from main:

  • Merged as it is, it would delete main's DT_STRSZ check (Dynamic string table is out of bounds) from RelinkerPipeline.cpp.
  • It still carries the unrelated pr-overlap.yml and progress.yml edits, and the template is empty.
  • #917 makes the RELA entry check overflow-safe, and #930 validates the dynamic segment, so what's left here is the per-table check and the extractRelative loop.

If you decide to continue, please reopen with a branch rebased on current main that only changes the relocation bounds, with the template filled in and a fixture that fails on main.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6025666716 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/298#issuecomment-6025666716). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-06T21:20:20Z. --- Thanks for looking at relocation bounds. I'm closing this for now, since the points from 10-04 and 10-05 are still open and the branch has drifted from main: - Merged as it is, it would delete main's `DT_STRSZ` check (`Dynamic string table is out of bounds`) from `RelinkerPipeline.cpp`. - It still carries the unrelated `pr-overlap.yml` and `progress.yml` edits, and the template is empty. - #917 makes the RELA entry check overflow-safe, and #930 validates the dynamic segment, so what's left here is the per-table check and the `extractRelative` loop. If you decide to continue, please reopen with a branch rebased on current main that only changes the relocation bounds, with the template filled in and a fixture that fails on main.

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