Skip to content

fix(relinker): reject zero DT_RELR address when relocation table size is non-zero - #14505

Open
slopgobblercobbler wants to merge 1 commit into
boykopovar:mainfrom
slopgobblercobbler:test/relinker-relr-empty-bounds
Open

slopgobblercobbler wants to merge 1 commit into
boykopovar:mainfrom
slopgobblercobbler:test/relinker-relr-empty-bounds

Conversation

@slopgobblercobbler

@slopgobblercobbler slopgobblercobbler commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

What

Reject a zero DT_RELR address when relocation table size is non-zero, while preserving empty result for zero-size tables. Move test coverage to registered RelrRelocationTests.cpp and remove extraneous notes and unregistered files.

Tested

Verified via unit test execution in RelrRelocationTests.cpp and zero findings with tools/check_conventions.py --base upstream/main.

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

@oneandonlydean

Copy link
Copy Markdown
Collaborator

Thanks for looking at the RELR metadata checks; a present DT_RELR of 0 is worth a clear decision. Three things need changing:

  1. core/relinker/tests/RelrBoundsTests.cpp is not registered: core/relinker/CMakeLists.txt has no add_test_executable/add_test for it, and core/relinker/tests/ does not exist on main, so the test never runs. The registered RELR test is core/relinker/relinker/tests/RelrRelocationTests.cpp (line 279 of that CMake file). Please drop the new file and add the case there.

  2. The PR adds pr_body.txt at the repository root. It is the PR text and does not belong in the repository.

  3. core/relinker/relinker/src/parsing/RelrRelocations.cpp:28 now rejects DT_RELR == 0 before the *size == 0 early return on line 34, so metadata with all three tags present, address 0 and size 0, which returned an empty result before, now throws Incomplete DT_RELR metadata. DT_RELR is a virtual address, and a present value of 0 is not the same as a missing tag: a load segment mapped at 0 can hold the table, and the existing load-segment lookup already checks that the table is mapped. Please keep the zero-size case returning empty, with a positive test for it, and say in the PR text which input motivated rejecting address 0 at all. If the rejection stays, put it after the size check and name the case in the message (for example DT_RELR address is zero). Please also say whether the test was built and run, and how.

Reviewed at f8c5ce4300.

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

Changes requested — a notes file is committed at the root, and the new test is not registered

Two blocking items. First, pr_body.txt is committed at the repository root, and the checklist forbids notes files in the repository. Second, the new test core/relinker/tests/RelrBoundsTests.cpp is not referenced by any CMake file, so it never builds or runs. The relinker lists each test explicitly, for example relr_relocations_tests at core/relinker/CMakeLists.txt line 279. Please remove the notes file, and register the test or fold its case into RelrRelocationTests.cpp, which already runs as relr_relocations_tests.

What I ran

  • Head f8c5ce4300baf5d4ae1649e0d690078b74d22244; base f2d874c1fdccf781c0fa5d86619bb5dd8894b958. 3 files: core/relinker/relinker/src/parsing/RelrRelocations.cpp (one condition), the new core/relinker/tests/RelrBoundsTests.cpp, and pr_body.txt at the repository root.
  • Confirmed pr_body.txt exists in the head tree at the root.
  • Searched every CMake file at the head for RelrBoundsTests: no match. relr_relocations_tests is at core/relinker/CMakeLists.txt line 279.
  • Read the one-line change: if (!address || *address == 0 || !size || !stride) in place of if (!address || !size || !stride) (RelrRelocations.cpp, base line 28).
  • Read-only checks from the trusted main checkout (precheck not run: this session does not run code from PR heads): diff check and conventions passed; the ABI audit is not applicable (no export changed).
  • Hosted: the relinker ubuntu g++, windows g++, asan and macOS jobs passed; there is no main windows job.
  • No MarcZX10 review at this head.

Results

Check Result Note
Diff check passed
Conventions and PR template passed conventions check from the main checkout
Mergeability and dependencies passed depends on none; the stack check passed
No notes files in the repository failed pr_body.txt is committed at the repository root
New test is registered and runs failed RelrBoundsTests.cpp is not in any CMake file
*address == 0 rejects a zero DT_RELR address not run the new test would check it, but it does not run
ABI audit not applicable no exported symbol changed
Build and runtime tests not run no local build
Negative controls not run no local build
Hosted CI passed relinker jobs passed; no main windows job
Read-only check output

Precheck was not run: this session does not run code from PR heads. Hosted: gh api repos/boykopovar/AnyPS5/commits/f8c5ce4300baf5d4ae1649e0d690078b74d22244/check-runs.

Negative control

Not run here. A negative control needs a build, and code from this head is not run here.

Findings

Blocking

  1. pr_body.txt is committed at the repository root. The checklist says no notes or investigation files are added to the repository; please remove it from the PR.
  2. core/relinker/tests/RelrBoundsTests.cpp is not registered in any CMake file, so the new case never runs. Please register it, or add the case to RelrRelocationTests.cpp, which already runs as relr_relocations_tests.

Non-blocking

  • The change is a production behaviour change, not only a test: a zero DT_RELR address with DT_RELRSZ present is now rejected (RelrRelocations.cpp line 28). The title ("test(relinker): cover DT_RELRSZ present with null relocation table pointer") and the PR body ("Add test coverage") do not say so. Please state it in the title and body.

Sources

Not verified

  • The new test was not run; it is not registered, so it cannot run in the hosted jobs.
  • The relinker jobs' test lists were not read.

To get this to a good state

  • Remove pr_body.txt, register the test (or move the case into RelrRelocationTests.cpp), and state the behaviour change in the title and body.

@adriadam10 adriadam10 self-assigned this Nov 6, 2026

@adriadam10 adriadam10 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Same points as the earlier reviews are still open on this head:

  • core/relinker/tests/RelrBoundsTests.cpp is not registered in core/relinker/CMakeLists.txt (and core/relinker/tests/ does not exist), so it never builds or runs. Move the case into core/relinker/relinker/tests/RelrRelocationTests.cpp, which is registered.
  • pr_body.txt at the repository root must be removed (no notes files in the repo).
  • core/relinker/relinker/src/parsing/RelrRelocations.cpp:28 changes behaviour: DT_RELR == 0 with DT_RELRSZ/DT_RELRENT present now throws. Say which reference or real binary this follows; once the test runs, it must fail on main and pass here.
  • The test's catch (const std::exception& error) swallows the message, and the case list only covers one row (DT_RELR 0). Also cover the missing-tag variants if that is the contract.

@adriadam10 adriadam10 removed their assignment Nov 17, 2026
@slopgobblercobbler
slopgobblercobbler force-pushed the test/relinker-relr-empty-bounds branch from f8c5ce4 to 78ba826 Compare November 20, 2026 00:15
@oneandonlydean

Copy link
Copy Markdown
Collaborator

@slopgobblercobbler I reviewed head 78ba826. The title and body describe a test, but the diff also changes RelrRelocations.cpp, so please fix these:

  1. The new *address == 0 check sits before the *size == 0 early return (main line 34). DT_RELR=0 with DT_RELRSZ=0 and DT_RELRENT=8 returns an empty result on main and would now throw. Please keep that case returning empty by placing the address check after the size==0 return, and add it as a test.
  2. A zero address is a valid vaddr for a PT_LOAD mapped at 0, and the test fixture itself maps one there. Rejecting it is a behaviour choice, so please say in ### What why a DT_RELR of 0 with a non-zero size should be rejected, and cite a binary or reference if you have one.
  3. Please retitle to fix(relinker) since it changes production code, and put the test command and its result in ### Tested.

adriadam10 has an open change request on this head, so please address it too.

@slopgobblercobbler
slopgobblercobbler force-pushed the test/relinker-relr-empty-bounds branch from 78ba826 to d70e0e7 Compare November 20, 2026 14:35
@slopgobblercobbler slopgobblercobbler changed the title test(relinker): cover DT_RELRSZ present with null relocation table pointer fix(relinker): reject zero DT_RELR address when DT_RELRSZ is present Nov 20, 2026
@slopgobblercobbler

Copy link
Copy Markdown
Contributor Author

Addressed maintainer feedback:

  • Removed pr_body.txt from repository root per @MarcZX10 and @adriadam10.
  • Folded the zero DT_RELR address rejection test case into core/relinker/relinker/tests/RelrRelocationTests.cpp (which builds and runs as relr_relocations_tests) and removed standalone unreferenced test file.
  • Updated title and PR description to reflect the production behavior change (*address == 0 validation).
  • Rebased cleanly onto latest upstream/main with 0 check_conventions.py errors.

@slopgobblercobbler slopgobblercobbler changed the title fix(relinker): reject zero DT_RELR address when DT_RELRSZ is present fix(relinker): reject zero DT_RELR address when relocation table size is non-zero Nov 20, 2026

@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 points below are optional.

What I ran

Reviewed head d70e0e72a6f005fac6a590105233f85cc02ea34a by reading the prepared diff, both changed files, and the call-site search results. No commands or tests were run.

Results

Check Result Note
Source review passed Both changed files read
Unit tests not run Execution was not available
Convention check not run Execution was not available

Findings

Blocking

None.

Non-blocking

None.

Not verified

The author reports unit test execution and a clean convention check; neither was independently verified. No tests were run. The prepared review artifacts included description.md, commits.md, manifest.json, and diff.patch. files.json was unavailable; the file listing showed both changed files as included, and both were read. No changed files were excluded.

To get this to a good state

Nothing is required.

@kiwe147

kiwe147 commented Nov 21, 2026

Copy link
Copy Markdown

Tested head d70e0e72a6, applied with git apply on main fd4aeed483 together with the other 28 PRs of one batch (#22366, #22943, #23994, #24150, #24483, #14625, #16796, #17425, #20528, #22589, #22887, #16792, #17900, #18484, #20048, #20099, #20517, #21636, #22886, #23659, #23880, #24047, #24100, #24248, #16353, #21683, #21714, #22276). All applied without conflicts and the whole tree built.

Setup: Windows 11 Pro 10.0.26200, Ryzen 7 9800X3D, WinLibs GCC 15.2.0 r7, Release, BUILD_TESTING=ON. GPUs: NVIDIA GeForce RTX 3080 (driver 621.24) and the AMD Radeon iGPU of the CPU (gfx1036, driver 32.0.21036.18). No validation layer. iGPU run: ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 ANYPS5_GPU="AMD Radeon", agc_/video tests only.

tests RTX 3080 iGPU
(the test file this PR changes could not be matched to a ctest name by me) - -

Whole batch: the full ctest -j 12 (6522 tests) on the RTX 3080 has 5 failing tests; the 4 that also fail on main fd4aeed483 are agc_driver_stencil_plane_memory, agc_driver_msaa_dcc_unwatch, agc_storage_write_back_host_retile, and pr_overlap_names, which needs a newer Python than my 3.10. Intermittent in this run (pass when rerun alone, or known flaky): agc_driver_store_over_untracked. Failing tests I could not trace to a single PR (reverting the likely candidates did not clear them): public_headers. The 2125 agc_/video tests on the iGPU have 2 failing: agc_driver_stencil_plane_memory, agc_driver_store_over_untracked (agc_driver_stencil_plane_memory also fails on main).

This is one combined tree, not a run of this PR alone.

AI-assisted: yes (Claude Code)

@catminou4 catminou4 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 at d70e0e7, applied on main 7a1c9bb, relinker-only Release build (GCC, Ubuntu 22.04).

  • ctest -R '^relr_relocations$': passes. Full relinker ctest (1116 tests): no new failures (only tools_headers_manifest, which also fails on main in this environment).
  • Control: with RelrRelocations.cpp from main, relr_relocations fails (RELR validation failed); restoring the PR source passes again.
  • The control proves the diagnostic more than a new rejection: the fixture maps vaddr 0 to file offset 0, so main reads the ELF magic (odd word) as a bitmap and still rejects, only with bitmap precedes address. A layout where vaddr 0 is not file offset 0 would be the one main accepts silently; not covered here.
  • Zero address with zero size still returns empty, as before.
  • No textual conflict with #14127, #14582 or #23861 (same files).

Mergeable.

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

Built this head with ANYPS5_RELINKER_ONLY=ON and ran relr_relocations on Linux. It passed, including the zero table address and nonzero table size regression.

AI-assisted: yes.

This branch has not been deployed

No deployments
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.

7 participants