fix(relinker): bound SCE relative relocation tables by PT_SCE_DYNLIBDATA #28881
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/28881"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by m4ce-w1ndu on 2026-12-04T12:42:20Z.
What
Bound SCE relative relocation tables (
DT_OS_RELAandDT_OS_JMPREL) inBuildRelativeRelocationIndexto thePT_SCE_DYNLIBDATAsegment extent (p_filesz) whenPT_SCE_DYNLIBDATAis present.Previously,
BuildRelativeRelocationIndexvalidatedPT_SCE_DYNLIBDATAagainst the file size and discarded itsp_filesz, allowingDT_OS_RELAandDT_OS_JMPRELtables (empty or non-empty) to extend past the end ofPT_SCE_DYNLIBDATAinto trailing file bytes instead of rejecting them. Tables withoutPT_SCE_DYNLIBDATAkeep their existing absolute file-offset behavior.Added regression tests in
core/relinker/relinker/tests/StrictNidFilterTests.cppcovering both exact-end acceptance and past-segment rejection for non-empty and emptyDT_OS_RELAandDT_OS_JMPRELtables.Tested
Linux x86-64 (GCC, C++20
-O2), relinker andstrict_nid_filter_testsbuilt fromcore/relinker/CMakeLists.txt:RelativeRelocationIndex.cpp(SCE RELA extending past PT_SCE_DYNLIBDATA into file bytes was accepted).strict_nid_filter_testspassed.relinker:test_jmprel_table_bounds.py,test_rela_size.py,test_relr_relocations.py,test_optional_rela.py,test_optional_plt.py,test_unused_filter_indirect.py,test_unused_filter_fallthrough_padding.py,test_init_array_roots.py,test_duplicate_relocations.py,test_overlapping_relocations.py,test_sce_code_extent.py,test_sce_code_gaps.py,test_null_symbol_relocations.py,test_none_relocations.py, andtest_call_registry.py(15/15 passed).python3 tools/check_conventions.pypassed.python3 tools/pr_overlap.py --branch fix/relinker-sce-reloc-index-boundsreported no overlap with open pull requests.Not tested with a real title or on Windows/macOS hosts.
Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Summary by CodeRabbit
Imported from boykopovar/AnyPS5. Originally posted by Plyxen on 2026-12-04T12:50:34Z.
Review: APPROVED
Verified on Windows 11 with WinLibs GCC 15.2.0 r7 (Release). I used a tree at
main63b98e5bf8(plus two unrelated commits of mine in libc and a LibreSSL test), with this PR applied together with #28881, #28810, #28806, #28776 and #28781, which touch separate files. I ran everystrict_nid_filter,guest_audiodec*,guest_np_manager*,guest_np_reachabilityand HarfBuzz test (31): all pass before the change, and all pass in 3 of 3 runs with it.Negative control, with
RelativeRelocationIndex.cppas onmainand the new tests kept:strict_nid_filterfails with "SCE RELA extending past PT_SCE_DYNLIBDATA into file bytes was accepted".The new bound is written without overflow:
tableAddress > sceTableSize || tableSize > sceTableSize - tableAddress. It applies only whenPT_SCE_DYNLIBDATAis present, so the absolute-offset path is unchanged.Not run: the relinker's Python tests and a real title.
AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-12-04T13:06:05Z.
Review: APPROVED
Reviewed — looks good
The reviewed change bounds SCE relocation tables to the validated
PT_SCE_DYNLIBDATAextent, and the added cases cover exact-end acceptance and past-segment rejection.What I ran
Reviewed head
bf869ac33b661c82fede9dafdb8345013ed6833b, the prepared diff and manifest, and both changed files. No tests or builds were run by me; the test results in the description are author-reported.Results
Negative control
Not run by me. The author reports that the new regression tests failed against the unpatched implementation.
Findings
Blocking
None.
Non-blocking
None.
Sources
RelativeRelocationIndex.cpp, lines 77–85 — overflow and segment-extent checks precede file access.StrictNidFilterTests.cpp, lines 1152–1204 — exact-end and past-segment cases for RELA and JMPREL, including empty tables.Not verified
No tests or builds were run by me, and behavior on a real title or Windows/macOS hosts was not verified. Both changed files were read;
files.jsonlists no excluded files.To get this to a good state
Nothing is required.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.