Skip to content

fix(relinker): validate relative relocation table bounds - #2222

Merged
oneandonlydean merged 2 commits into
boykopovar:mainfrom
EshaanJaiswal:fix-relative-relocation-bounds
Oct 10, 2026
Merged

oneandonlydean merged 2 commits into
boykopovar:mainfrom
EshaanJaiswal:fix-relative-relocation-bounds

Conversation

@EshaanJaiswal

@EshaanJaiswal EshaanJaiswal commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

What

Validate complete DT_RELA and DT_JMPREL relocation table ranges before parsing them.

Malformed ELF metadata could declare a relocation table extending beyond its file-backed PT_LOAD segment. The parser could then interpret bytes outside the segment as relocation entries.

This change:

  • Validates the full relocation table against its containing PT_LOAD.
  • Validates the resulting file range against the ELF byte buffer.
  • Rejects relocation sizes that are not multiples of 24 bytes.
  • Uses overflow-safe checks for virtual and file offsets.
  • Applies the checks to both DT_RELA and DT_JMPREL.
  • Adds regression coverage for overextended, unaligned, and near-UINT64_MAX metadata.

Fixes #2221

Tested

Linux x86-64 (Ubuntu 26 LTS)

Tests use synthetic ELF byte arrays only. No PS5 hardware, controller, firmware, title, or game files are required.

Commands run:

cmake --build build --target strict_nid_filter_tests --parallel
ctest --test-dir build -R strict_nid_filter --output-on-failure

Result:

strict_nid_filter passed

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
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes

Copilot AI balanced review requested due to automatic review settings October 9, 2026 12:07

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review note: collectRelativeEntries now skips only when both the address and size are zero. Previously it returned when either was zero. An ELF can have a relocation address tag with a zero relocation size; there are no entries to read, so requiring that address to map inside a PT_LOAD can reject an empty table. Please keep zero-sized tables as no-ops (while retaining the malformed nonzero-size checks) and add coverage for a nonzero table address with a zero size. I have not approved the PR; the current checks show Conventions only, so a Build result on this exact head is still needed as well.

@EshaanJaiswal

Copy link
Copy Markdown
Contributor Author

@MarcZX100, are you spying on me or something ? xD
How can someone review stuff so fast ?

@EshaanJaiswal

Copy link
Copy Markdown
Contributor Author

Review note: collectRelativeEntries now skips only when both the address and size are zero. Previously it returned when either was zero. An ELF can have a relocation address tag with a zero relocation size; there are no entries to read, so requiring that address to map inside a PT_LOAD can reject an empty table. Please keep zero-sized tables as no-ops (while retaining the malformed nonzero-size checks) and add coverage for a nonzero table address with a zero size. I have not approved the PR; the current checks show Conventions only, so a Build result on this exact head is still needed as well.

Implemented the requested empty-table handling.

Zero-sized DT_RELA and DT_JMPREL tables now return early before address translation, so an unmapped address with size zero is treated as an empty table. Added regression coverage for this case.

Focused tests pass:

  • strict_nid_filter_tests
  • ctest -R strict_nid_filter

@MarcZX10

MarcZX10 commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

Thanks, the follow-up addresses my empty-table concern: zero-sized tables now return before address translation, and the regression covers a nonzero unmapped address with zero size. The added bounds checks and malformed-size cases look consistent on the updated diff. The focused test results and Conventions are reported green; the upstream Build workflow is still not present on this head, so I am not submitting approval until the required Build jobs run.

@EshaanJaiswal

Copy link
Copy Markdown
Contributor Author

@MarcZX100, Build Jobs won't be able to run unless I am a contributor or a maintainer approves this/my other PRs.

@rmz-24

rmz-24 commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

Windows run: Windows 11 Pro 25H2 (10.0.26200.9457), RTX 5060 Ti (NVIDIA 617.42), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release, -DANYPS5_ENABLE_SPIRV_TOOLS=ON, full build plus libs. 98b449f cherry-picked onto current main d70b899 (applies cleanly).

  • strict_nid_filter passes.
  • Full ctest: 510/510.

AI-assisted: yes

@MarcZX10

MarcZX10 commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

I see the independent Windows report for this exact head cherry-picked onto d70b8998: full build plus CTest 510/510, including the focused regression. That closes the Windows evidence gap. The remaining contribution-check gap is the full Linux Build and the relinker matrix on the current head; the PR currently reports only the focused Linux test. Since the author cannot dispatch the upstream workflow, an authorized collaborator would need to run it before this review can be finalized.

@MarcZX10

MarcZX10 commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

The PR has now received independent Windows validation for the current head (full build plus 510/510 CTest on a clean cherry-pick). I also verified the repository-required Linux/Windows full build and Linux/Windows/macOS relinker matrix workflow, but this checkout cannot dispatch it: GitHub returned 403 “Must have admin rights to Repository.” The only current check remains Conventions. I cannot submit an approval without the required project checks; a maintainer/collaborator with write access needs to run Actions > Build > Run workflow for PR #2222 on main.

oneandonlydean added a commit to oneandonlydean/AnyPS5 that referenced this pull request Oct 10, 2026
oneandonlydean added a commit to oneandonlydean/AnyPS5 that referenced this pull request Oct 10, 2026
@oneandonlydean
oneandonlydean merged commit 5545196 into boykopovar:main Oct 10, 2026
6 of 7 checks passed
SleglJan pushed a commit to SleglJan/AnyPS5 that referenced this pull request Oct 10, 2026
…location-bounds

fix(relinker): validate relative relocation table bounds
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Strict NID filtering reads relative relocations beyond PT_LOAD bounds

5 participants