fix(relinker): validate covered SCE RELRO file ranges #15345

Merged
AasishDairelSahayaGrinspan merged 2 commits from upstream-pr/15345 into main 2026-11-12 20:29:53 +00:00
AasishDairelSahayaGrinspan commented 2026-11-03 02:05:43 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by AasishDairelSahayaGrinspan on 2026-11-03T02:05:43Z.


What

Validate the ELF p_filesz <= p_memsz invariant and file-backed range for PT_SCE_RELRO headers even when the RELRO range is covered by a PT_LOAD. Previously these checks only ran when an uncovered RELRO header was converted into a load segment, so malformed covered RELRO metadata was accepted. Add deterministic bounds regressions for both invalid cases.

Tested

macOS 15, AppleClang 17, relinker-only Release build:

  • cmake -S . -B build-relinker -G Ninja -DCMAKE_BUILD_TYPE=Release -DANYPS5_RELINKER_ONLY=ON -DBUILD_TESTING=ON
  • cmake --build build-relinker --target elf_reader_bounds_tests -j 4
  • ctest --test-dir build-relinker -R "^elf_reader_bounds$" --output-on-failure — 1/1 passed
  • python3 tools/check_conventions.py --base origin/main — passed
  • pr-overlap bot report: the only confirmed overlapping PR is #10518 (PT_LOAD/RELRO alignment power-of-two checks, line-adjacent in the same function but an independent check); #11628/#11661/#11689/#11698, #12009, #14121 and #15651 are file neighbors that do not implement covered SCE RELRO validation. No build dependency on any of them; Depends on stays none (see the re-check comment).
  • git diff --check — passed

No title, GPU or full-runtime testing; this is an ELF parser-only change.

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 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:5130637912 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15345). Originally posted by [AasishDairelSahayaGrinspan](https://github.com/AasishDairelSahayaGrinspan) on 2026-11-03T02:05:43Z. --- ### What Validate the ELF `p_filesz <= p_memsz` invariant and file-backed range for `PT_SCE_RELRO` headers even when the RELRO range is covered by a `PT_LOAD`. Previously these checks only ran when an uncovered RELRO header was converted into a load segment, so malformed covered RELRO metadata was accepted. Add deterministic bounds regressions for both invalid cases. ### Tested macOS 15, AppleClang 17, relinker-only Release build: - `cmake -S . -B build-relinker -G Ninja -DCMAKE_BUILD_TYPE=Release -DANYPS5_RELINKER_ONLY=ON -DBUILD_TESTING=ON` - `cmake --build build-relinker --target elf_reader_bounds_tests -j 4` - `ctest --test-dir build-relinker -R "^elf_reader_bounds$" --output-on-failure` — 1/1 passed - `python3 tools/check_conventions.py --base origin/main` — passed - `pr-overlap` bot report: the only confirmed overlapping PR is #10518 (PT_LOAD/RELRO alignment power-of-two checks, line-adjacent in the same function but an independent check); #11628/#11661/#11689/#11698, #12009, #14121 and #15651 are file neighbors that do not implement covered SCE RELRO validation. No build dependency on any of them; Depends on stays none (see the re-check comment). - `git diff --check` — passed No title, GPU or full-runtime testing; this is an ELF parser-only change. ### 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) - [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
MarcZX10 commented 2026-11-03 02:36:53 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-03T02:36:53Z.

Review: COMMENTED


Reviewed — looks good

The source change and two new bounds regressions look correct, but approval is deferred until both pending macOS relinker jobs finish.

What I ran

  • Read both changed files at head e55a04e3741a083e02aac28a3f4a1bd353251196 against base 7feb37ee3e30e10139b483fb4df689d5b5b69ab8.
  • Environment: Debian 12 x86_64, Linux 6.1.0-54-amd64, Python 3.11.2, GCC/G++ 12.2.0.
  • The PR reports a macOS relinker-only build and test; that is author-reported, not a local run by me.
  • Commands:
python3 tools/pr_precheck.py --repo boykopovar/AnyPS5 --pr 15345 --output-dir /tmp/anyps5-pr-precheck/15345-20261103
git diff --check refs/review/main-15345-20261103...refs/review/pr15345-20261103
python3 /marc/AnyPS5/tools/pr_stack_check.py 15345 --repo boykopovar/AnyPS5 --output-dir /tmp/anyps5-pr-precheck/15345-20261103/stack
gh pr checks 15345 --repo boykopovar/AnyPS5

Results

Check Result Note
Diff and conventions passed No whitespace or convention findings
Merge preview passed Clean against current main
Hosted CI not run Linux and Windows passed; two macOS relinker jobs remain pending
Local build and CTest not run PR author reports macOS test run
Test-quality helper failed Optional helper is missing from the exact-head snapshot
Precheck, CI and stack output
# PR precheck report — checks failed
Head: e55a04e3741a083e02aac28a3f4a1bd353251196
Base: 7feb37ee3e30e10139b483fb4df689d5b5b69ab8
diff_check | passed
conventions_and_pr_template | passed
changed_export_abi_audit | not_applicable
live_dependency_and_mergeability_check | passed
build_dependent_cpp_tests | not_applicable
test_quality_heuristics | failed
negative_controls | not_applicable

The test-quality helper could not launch:

/usr/bin/python3: can't open file '/tmp/anyps5-pr-precheck/15345-20261103/head-e55a04e3741a-ceeea8ac/tools/pr_test_quality.py': [Errno 2] No such file or directory

Convention check output:

All conventions checks passed.

Stack checker stdout:

/tmp/anyps5-pr-precheck/15345-20261103/stack/stack-report.md
/tmp/anyps5-pr-precheck/15345-20261103/stack/stack-report.json

Hosted-check output:

edge-watch	skipping	0	https://github.com/boykopovar/AnyPS5/actions/runs/41564970724/job/125684498651
linux	skipping	0	https://github.com/boykopovar/AnyPS5/actions/runs/41564970724/job/125684498772
register-context	skipping	0	https://github.com/boykopovar/AnyPS5/actions/runs/41564970724/job/125684499105
relinker (windows-latest, g++)	pass	8m44s	https://github.com/boykopovar/AnyPS5/actions/runs/41564970724/job/125684496911
relinker (macos-latest, clang++)	pending	0	https://github.com/boykopovar/AnyPS5/actions/runs/41564970724/job/125684496825
relinker (macos-latest, clang++, x86_64)	pending	0	https://github.com/boykopovar/AnyPS5/actions/runs/41564970724/job/125684496762
write-watch	skipping	0	https://github.com/boykopovar/AnyPS5/actions/runs/41564970724/job/125684498584
relinker (ubuntu-latest, g++)	pass	5m29s	https://github.com/boykopovar/AnyPS5/actions/runs/41564970724/job/125684496766
windows	skipping	0	https://github.com/boykopovar/AnyPS5/actions/runs/41564970724/job/125684497715
conventions	pass	19s	https://github.com/boykopovar/AnyPS5/actions/runs/41564969548/job/125684179708
eligibility	pass	4s	https://github.com/boykopovar/AnyPS5/actions/runs/41564970724/job/125684461048
labels	pass	7s	https://github.com/boykopovar/AnyPS5/actions/runs/41564969522/job/125684179922
relinker-asan	pass	2m20s	https://github.com/boykopovar/AnyPS5/actions/runs/41564970724/job/125684496738

Negative control

Not run. The two regressions need the exact-head C++ test binary; I did not build it.

Findings

Blocking

None identified in the reviewed diff. The validation now runs before the coverage decision for nonempty PT_SCE_RELRO entries, and the added fixtures exercise both invalid size and out-of-file cases when the RELRO range is covered by PT_LOAD.

Non-blocking

None identified.

Sources

Not verified

  • The two macOS relinker jobs were pending; I did not wait for or run them locally.
  • I did not run a local build, CTest, sanitizer, console, or title test.

To get this to a good state

No code change is requested. Let both macOS relinker jobs complete; if they pass on this exact head, I will approve it. If the head changes, I will rerun the applicable no-build checks and inspect the new diff.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5746561010 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15345#pullrequestreview-5746561010). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-03T02:36:53Z. **Review:** COMMENTED --- # Reviewed — looks good The source change and two new bounds regressions look correct, but approval is deferred until both pending macOS relinker jobs finish. ## What I ran - Read both changed files at head `e55a04e3741a083e02aac28a3f4a1bd353251196` against base `7feb37ee3e30e10139b483fb4df689d5b5b69ab8`. - Environment: Debian 12 x86_64, Linux 6.1.0-54-amd64, Python 3.11.2, GCC/G++ 12.2.0. - The PR reports a macOS relinker-only build and test; that is author-reported, not a local run by me. - Commands: ```sh python3 tools/pr_precheck.py --repo boykopovar/AnyPS5 --pr 15345 --output-dir /tmp/anyps5-pr-precheck/15345-20261103 git diff --check refs/review/main-15345-20261103...refs/review/pr15345-20261103 python3 /marc/AnyPS5/tools/pr_stack_check.py 15345 --repo boykopovar/AnyPS5 --output-dir /tmp/anyps5-pr-precheck/15345-20261103/stack gh pr checks 15345 --repo boykopovar/AnyPS5 ``` ## Results | Check | Result | Note | | - | - | - | | Diff and conventions | passed | No whitespace or convention findings | | Merge preview | passed | Clean against current main | | Hosted CI | not run | Linux and Windows passed; two macOS relinker jobs remain pending | | Local build and CTest | not run | PR author reports macOS test run | | Test-quality helper | failed | Optional helper is missing from the exact-head snapshot | <details> <summary>Precheck, CI and stack output</summary> ```text # PR precheck report — checks failed Head: e55a04e3741a083e02aac28a3f4a1bd353251196 Base: 7feb37ee3e30e10139b483fb4df689d5b5b69ab8 diff_check | passed conventions_and_pr_template | passed changed_export_abi_audit | not_applicable live_dependency_and_mergeability_check | passed build_dependent_cpp_tests | not_applicable test_quality_heuristics | failed negative_controls | not_applicable ``` The test-quality helper could not launch: ```text /usr/bin/python3: can't open file '/tmp/anyps5-pr-precheck/15345-20261103/head-e55a04e3741a-ceeea8ac/tools/pr_test_quality.py': [Errno 2] No such file or directory ``` Convention check output: ```text All conventions checks passed. ``` Stack checker stdout: ```text /tmp/anyps5-pr-precheck/15345-20261103/stack/stack-report.md /tmp/anyps5-pr-precheck/15345-20261103/stack/stack-report.json ``` Hosted-check output: ```text edge-watch skipping 0 https://github.com/boykopovar/AnyPS5/actions/runs/41564970724/job/125684498651 linux skipping 0 https://github.com/boykopovar/AnyPS5/actions/runs/41564970724/job/125684498772 register-context skipping 0 https://github.com/boykopovar/AnyPS5/actions/runs/41564970724/job/125684499105 relinker (windows-latest, g++) pass 8m44s https://github.com/boykopovar/AnyPS5/actions/runs/41564970724/job/125684496911 relinker (macos-latest, clang++) pending 0 https://github.com/boykopovar/AnyPS5/actions/runs/41564970724/job/125684496825 relinker (macos-latest, clang++, x86_64) pending 0 https://github.com/boykopovar/AnyPS5/actions/runs/41564970724/job/125684496762 write-watch skipping 0 https://github.com/boykopovar/AnyPS5/actions/runs/41564970724/job/125684498584 relinker (ubuntu-latest, g++) pass 5m29s https://github.com/boykopovar/AnyPS5/actions/runs/41564970724/job/125684496766 windows skipping 0 https://github.com/boykopovar/AnyPS5/actions/runs/41564970724/job/125684497715 conventions pass 19s https://github.com/boykopovar/AnyPS5/actions/runs/41564969548/job/125684179708 eligibility pass 4s https://github.com/boykopovar/AnyPS5/actions/runs/41564970724/job/125684461048 labels pass 7s https://github.com/boykopovar/AnyPS5/actions/runs/41564969522/job/125684179922 relinker-asan pass 2m20s https://github.com/boykopovar/AnyPS5/actions/runs/41564970724/job/125684496738 ``` </details> ## Negative control Not run. The two regressions need the exact-head C++ test binary; I did not build it. ## Findings ### Blocking None identified in the reviewed diff. The validation now runs before the coverage decision for nonempty `PT_SCE_RELRO` entries, and the added fixtures exercise both invalid size and out-of-file cases when the RELRO range is covered by `PT_LOAD`. ### Non-blocking None identified. ## Sources - [RELRO validation at the reviewed head](https://github.com/boykopovar/AnyPS5/blob/e55a04e3741a083e02aac28a3f4a1bd353251196/core/relinker/relinker/src/parsing/ElfReader.cpp#L156-L174) - [Covered RELRO regression cases at the reviewed head](https://github.com/boykopovar/AnyPS5/blob/e55a04e3741a083e02aac28a3f4a1bd353251196/core/relinker/relinker/tests/ElfReaderBoundsTests.cpp#L165-L170) - [Pending macOS relinker jobs](https://github.com/boykopovar/AnyPS5/actions/runs/41564970724) ## Not verified - The two macOS relinker jobs were pending; I did not wait for or run them locally. - I did not run a local build, CTest, sanitizer, console, or title test. ## To get this to a good state No code change is requested. Let both macOS relinker jobs complete; if they pass on this exact head, I will approve it. If the head changes, I will rerun the applicable no-build checks and inspect the new diff.
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!15345
No description provided.