Skip to content

fix(relinker): validate dynamic section entry size - #25435

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
malekaifa:prime-d/sht-dynamic-entry-size-20261122
Nov 27, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
malekaifa:prime-d/sht-dynamic-entry-size-20261122

Conversation

@malekaifa

@malekaifa malekaifa commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

What

Reject malformed ELF SHT_DYNAMIC section headers whose sh_entsize is not the ELF64 dynamic-entry size (16 bytes).

ElfReader::ReadSectionHeaders() already validates sh_entsize for symbol and relocation sections but previously accepted any value for SHT_DYNAMIC. The parser now uses the existing kDynEntrySize constant, the bounds fixture keeps its synthetic dynamic section otherwise valid, and the relinker debt entry records the additional validation.

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 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 (OpenAI ChatGPT)

Summary by CodeRabbit

  • Bug Fixes
    • Invalid dynamic sections with incorrect entry sizes are now rejected with a clear error.
  • Documentation
    • Updated the ELF validation notes to include dynamic section entry sizes.

Copilot AI balanced review requested due to automatic review settings November 22, 2026 03:13

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 insufficient remaining quota. Try requesting a review at a lower effort level.

@PrivacyOnion PrivacyOnion 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.

Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against 3a0287fc8f:

  • Conventions: tools/check_conventions.py passed.
  • Build: elf_reader_bounds_tests failed to build.
    core/relinker/relinker/tests/ElfReaderBoundsTests.cpp:1096:145: error: unable to deduce ‘std::initializer_list<auto>&&’ from ‘{0, 1, 8, 15, 17, 24, 32, 64, std::numeric_limits<long unsigned int>::max()}’
    core/relinker/relinker/tests/ElfReaderBoundsTests.cpp:1096:145: note:   deduced conflicting types for parameter ‘auto’ (‘long long unsigned int’ and ‘long unsigned int’)
    

Requesting changes for the points above.

@oneandonlydean

Copy link
Copy Markdown
Collaborator

@malekaifa the new test does not compile on Linux at 3a0287fc8f. In the first loop the braced list mixes 0ULL style literals (unsigned long long) with std::numeric_limits<std::uint64_t>::max() (unsigned long where uint64_t is unsigned long), so initializer_list deduction for the range-for fails. Please write the loop over std::initializer_list<std::uint64_t>{...} or cast each element to std::uint64_t. The check itself in the relinker looks right to me.

@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.

Reviewed — looks good

Nothing blocks this change; the parser check and regression test support the stated validation, and the reviewed files support merging.

What I ran

Reviewed head 3a0287fc8f98cf6ebf1d1b5eef16255c4b74bd5c using the prepared diff and pinned reader. No build or test commands were run.

Results

Check Result Note
Diff and changed files passed Three changed files read
Build and tests not run Author reports passing gates
Console behavior not run Hardware diagnostics remain unverified

Findings

Blocking

None.

Non-blocking

None.

Not verified

No commands or tests were run independently. PS5 hardware behavior was not verified. The complete file contents were read for all files listed as reviewed; no files were excluded in manifest.json.

To get this to a good state

Nothing is required.

@malekaifa

Copy link
Copy Markdown
Contributor Author

Fixed the Linux compile issue from @oneandonlydean on current head 70f127160c8b17e8db622fa0ce59e5667464dc9c: the mixed braced list is now an explicit std::initializer_list<std::uint64_t>, with no production-code change.

Machine main validation on the exact pushed head:

  • configured ANYPS5_RELINKER_ONLY=ON, Release, GCC 16.2.0;
  • built elf_reader_bounds_tests successfully;
  • ctest -R '^elf_reader_bounds$' --output-on-failure: 1/1 passed;
  • python tools/check_conventions.py --base 87b7ef3891afc17113b86b14815f96895ae477cf: passed;
  • git diff --check: passed.

Fresh hosted checks are now queued on the new head.

@PrivacyOnion PrivacyOnion 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.

Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against 70f127160c:

  • Conventions: tools/check_conventions.py passed.
  • Build: elf_reader_bounds_tests built cleanly.
  • CTest (elf_reader_bounds):
    1/1 Test #6364: elf_reader_bounds ................   Passed    0.00 sec
    100% tests passed, 0 tests failed out of 1
    
  • Negative control: with core/relinker/relinker/src/parsing/ElfReader.cpp reverted to main and the new tests kept, the suite fails:
    1/1 Test #6364: elf_reader_bounds ................***Failed    0.00 sec
    0% tests passed, 1 tests failed out of 1
    
    Restoring the change makes it pass again.
  • Code reading:
    • Validated core/relinker/relinker/src/parsing/ElfReader.cpp:267-269 ElfReader::ReadSectionHeaders() correctly validates sh.Type == SHT_DYNAMIC with sh.EntrySize != kDynEntrySize (16 bytes) and throws RelinkerException with the exact offset offset + kShdrEntSizeOffset, mirroring SHT_SYMTAB/DYNSYM and SHT_RELA/REL checks.
    • Verified docs/dev/debt/relinker.md correctly updates the debt entry to document that dynamic section entry size is now validated alongside symbol and relocation sections.
    • Verified core/relinker/relinker/tests/ElfReaderBoundsTests.cpp lines 1066 and 1096-1103: regression test comprehensively covers various invalid entry sizes (0, 1, 8, 15, 17, 24, 32, 64, UINT64_MAX) using explicit std::initializer_liststd::uint64_t and validates valid size 16.
    • Checked AGENTS.md rules: no prohibited comments added, no stubs or single-game workarounds introduced, conventional commit and PR structure respected, no extra files added.

Looks Good To Me

@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.

Reviewed — looks good

The change validates SHT_DYNAMIC entry sizes and adds a focused regression test; the reviewed files support merging.

What I ran

Reviewed head 70f127160c8b17e8db622fa0ce59e5667464dc9c. I did not run commands or tests; repo_read.py was unavailable as a command in this environment. The author reports the focused test, full suite, and stated gates passed.

Results

Check Result Note
Code and diff review passed All changed files read
Tests and other gates not run Results supplied by author only

Findings

Blocking

None.

Non-blocking

None.

Sources

Reviewed core/relinker/relinker/src/parsing/ElfReader.cpp, core/relinker/relinker/tests/ElfReaderBoundsTests.cpp, and docs/dev/debt/relinker.md; all are included in the review bundle and were read. No files were excluded.

Not verified

Tests, build, convention checks, and test registration were not run by me. PS5 hardware and console-loader diagnostics were not tested, as noted in the PR description.

To get this to a good state

Nothing is required.

@malekaifa

Copy link
Copy Markdown
Contributor Author

Maintainer handoff: current head 70f127160c8b17e8db622fa0ce59e5667464dc9c is mergeable/clean. The repaired exact head now has green relinker jobs on Windows, Ubuntu, macOS and ASan, plus green eligibility, PR, conventions and labels checks. PrivacyOnion and MarcZX10 both approved this exact head, and PrivacyOnion independently rebuilt elf_reader_bounds_tests, passed elf_reader_bounds, and confirmed the negative control fails without the parser fix. No remaining blocker is known from this review/CI pass.

@malekaifa
malekaifa force-pushed the prime-d/sht-dynamic-entry-size-20261122 branch from 70f1271 to d519ded Compare November 23, 2026 00:22
@malekaifa

Copy link
Copy Markdown
Contributor Author

Rebased onto current main 7a3206e9cd8c as head d519ded26f6905837eb231864f5f871196df0dfe. Machine main: rebuilt elf_reader_bounds_tests; ctest -R ^elf_reader_bounds$ passes 1/1 on this exact head, and git diff --check passes. Fresh hosted checks are running.

@malekaifa
malekaifa force-pushed the prime-d/sht-dynamic-entry-size-20261122 branch from d519ded to b45fa67 Compare November 23, 2026 01:01
@malekaifa

malekaifa commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor Author

Current stable head is b45fa671169cf6cc4bd0c2bf3168d42577e691d1, based on db397a73fe4754858e19483fd6cb29159ed57d74. The Linux initializer fix remains in place; elf_reader_bounds_tests rebuilt and elf_reader_bounds passed 1/1 on machine main, conventions/test registration/diff checks passed, and GitHub reports the PR mergeable/clean. I will not rebase it again merely to chase a moving main; this head stays stable unless a real conflict, integration dependency, or reviewer request appears. AI-assisted: yes

@malekaifa

Copy link
Copy Markdown
Contributor Author

@MarcZX10 @PrivacyOnion The current stable PR head is b45fa671169cf6cc4bd0c2bf3168d42577e691d1, newer than the last reviewed head. Could you please re-review this exact head when convenient?

@malekaifa
malekaifa force-pushed the prime-d/sht-dynamic-entry-size-20261122 branch from b45fa67 to b02f778 Compare November 23, 2026 13:08
@malekaifa

Copy link
Copy Markdown
Contributor Author

Final exact-head handoff: current head b02f7781262a69c6fcaf21dcf41129ca1f18382d has all 14 hosted checks complete/pass-or-intentionally-skipped, including Windows/Ubuntu/macOS relinker and ASan, conventions, eligibility, PR and labels. GitHub review records attach both PrivacyOnion and MarcZX10 approvals to this exact head, and the PR is mergeable. No remaining blocker is known. AI-assisted: yes

@github-actions

github-actions Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 10861 docs/dev/debt/relinker.md
PR 11525 docs/dev/debt/relinker.md
PR 11661 core/relinker/relinker/src/parsing/ElfReader.cpp
core/relinker/relinker/tests/ElfReaderBoundsTests.cpp
docs/dev/debt/relinker.md
PR 11689 core/relinker/relinker/src/parsing/ElfReader.cpp
core/relinker/relinker/tests/ElfReaderBoundsTests.cpp
docs/dev/debt/relinker.md
PR 11698 core/relinker/relinker/src/parsing/ElfReader.cpp
core/relinker/relinker/tests/ElfReaderBoundsTests.cpp
docs/dev/debt/relinker.md
PR 12678 docs/dev/debt/relinker.md
PR 13716 docs/dev/debt/relinker.md
PR 14241 docs/dev/debt/relinker.md
PR 15245 docs/dev/debt/relinker.md
PR 17557 docs/dev/debt/relinker.md
PR 18523 docs/dev/debt/relinker.md
PR 20389 docs/dev/debt/relinker.md

@malekaifa

Copy link
Copy Markdown
Contributor Author

Manual overlap follow-up for the latest bot warning: I inspected the shared-file diffs of #11661, #11689 and #11698. Their ElfReader.cpp changes are in other validation paths (including PT_LOAD alignment / RELRO handling); none of the three contains an SHT_DYNAMIC, sh_entsize, kDynEntrySize, or dynamic-section-entry-size change. Their ElfReaderBoundsTests.cpp / debt edits likewise do not implement #25435's validation. So these are shared-file/integration overlaps, not a competing implementation of this PR. No source change is needed from this overlap review. AI-assisted: yes (OpenAI ChatGPT).

@malekaifa
malekaifa force-pushed the prime-d/sht-dynamic-entry-size-20261122 branch from b02f778 to 3cf4af1 Compare November 23, 2026 23:48
@malekaifa

Copy link
Copy Markdown
Contributor Author

Rebased onto current main as head 3cf4af1. Machine main: rebuilt elf_reader_bounds_tests; elf_reader_bounds passes 1/1, conventions pass, all 338 test scripts are registered, and git diff --check passes. Fresh hosted checks are starting.

@malekaifa

Copy link
Copy Markdown
Contributor Author

Independent current-main integration validation (machine main).

  • Applied PR head 3cf4af18f039ccbfc0e1285a114099ab2be72278 to current main fd653794a1538fdde37ae77971e3f345ced33e85; merge was clean.
  • Configured a relinker-only Release build with MSYS2 UCRT64 GCC 16.2 and built elf_reader_bounds_tests.
  • CTest elf_reader_bounds: 1/1 passed.
  • Negative control: restored current main's unpatched ElfReader.cpp while keeping the PR regression test; the test failed specifically at SHT_DYNAMIC section entry size mismatch because invalid metadata was accepted. Restoring the PR implementation made it pass again.
  • check_test_registration.py --scripts: 341 scripts registered; git diff --check clean.

This independently verifies the dynamic-section entry-size regression on the current-main merge. Hosted Ubuntu/Windows/macOS relinker, ASan, conventions, eligibility, and labels checks are green. AI-assisted: yes (OpenAI ChatGPT).

@malekaifa
malekaifa force-pushed the prime-d/sht-dynamic-entry-size-20261122 branch from 3cf4af1 to 0681eb7 Compare November 26, 2026 15:57
@coderabbitai

coderabbitai Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Explain Change →

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: d2de18b5-9ef8-48fe-86c1-8c74310f3fcb
Commits

Reviewing files that changed from the base of the PR and between 0681eb7 and c1c0d20.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review

No actionable comments were generated in the recent review.

Walkthrough

Changes: Dynamic section validation

Layer / File(s) Summary
Validate dynamic section entry sizes
core/relinker/relinker/src/parsing/ElfReader.cpp, core/relinker/relinker/tests/ElfReaderBoundsTests.cpp, docs/dev/debt/relinker.md
ReadSectionHeaders rejects SHT_DYNAMIC entry sizes other than kDynEntrySize. Tests cover zero, other invalid sizes, the maximum uint64_t, and failure offset 248. The section-link test sets entry size 16 for section types 6 and 9. The debt entry documents dynamic-section entry-size validation and unmeasured console diagnostics.

Suggested reviewers: slopgobblercobbler

Change: Bug fix

Merge Risk: Minimal · previous review 0681e

The relinker's ELF reader now rejects dynamic sections whose entry size is not 16 bytes, matching what the writer already produces. Only malformed inputs are affected, and tests cover the rejection. No merge-blocking risk remains.

Security architecture risk: Minimal · up to 0681e

The reader now rejects malformed dynamic section headers that it previously accepted, without changing the files the relinker writes. The change adds a rejection check rather than a new way for input to reach downstream processing.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The direct exposure change is limited to callers parsing section headers from ELF inputs with nonconforming SHT_DYNAMIC metadata. The new branch can stop those inputs earlier; it adds no route to downstream processing.

Trust Boundaries and Controls

  • observed — The reader compares the file-supplied entry size with a fixed format constant and uses the existing parser exception mechanism to reject a mismatch.
Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 65f65186-f589-4829-a7d1-71dacc32f3c3
Commits

Reviewing files that changed from the base of the PR and between 10fef81 and 0681eb7.

Files selected for processing: 3

  • core/relinker/relinker/src/parsing/ElfReader.cpp
  • core/relinker/relinker/tests/ElfReaderBoundsTests.cpp
  • docs/dev/debt/relinker.md

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

@malekaifa
malekaifa force-pushed the prime-d/sht-dynamic-entry-size-20261122 branch from 0681eb7 to c1c0d20 Compare November 26, 2026 17:01
@oneandonlydean
oneandonlydean merged commit 6b481be into boykopovar:main Nov 27, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants