fix(relinker): accept PT_DYNAMIC data after DT_NULL #10561
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/10561"
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 vingelvatten on 2026-10-24T10:08:21Z.
What
The five relinker parsers of an input
PT_DYNAMICrefused any segment whosep_fileszis not a multiple of 16 before reading it (Invalid dynamic segment size,Code analysis: invalid dynamic segment,Strict filter: truncated dynamic segment,Missing or invalid ELF load/dynamic segments). The current public elfldr, v0.27elfldr-ps5.elf(sha25682f6227610172c98bad6efe68219fc93a10027035991f47eb4b75532d023407d), declaresp_filesz = 0x1468: the segment header covers the tail of its secondPT_LOAD(.dynamic,.dynsym,.gnu.hash,.dynstr,.rela.dyn), while.dynamicis 0x150 bytes andDT_NULLis entry 21. v0.26 (sha256ed6d587a057c09d6a95b2176e336d9ffc605e547ac56462128b029e47b8ccea1) declares exactly 0x150 with the same tags; so do the 22 other public ps5-payload-dev payloads I checked. The gABI dynamic section ends the array atDT_NULL; FreeBSD rtld (digest_dynamic1inlibexec/rtld-elf/rtld.c) and glibc (elf_get_dynamic_infoinelf/get-dynamic-info.h) walk toDT_NULLand never readp_filesz. v0.27 is the current elfldr release.Each parser now reads whole 16-byte entries within the declared, bounds-checked size and stops at
DT_NULL. A segment whose whole entries end withoutDT_NULL, including one cut inside the terminator, still throwsUnterminated dynamic segment. The parsers:ElfReader::ReadDynamicTags,CodeInstructionCollector(Windows and macOS code analysis),RelativeRelocationIndex(unused-filter=1),StrictNidFilter(unused-filter=2) andGuestImageReader(guest modules). The% 16checks on the relinker's own rebuilt dependency tables are unchanged. The sectionless-ELF reader oftools/import_audit.pykeeps the same refusal for now: #10352 edits that loop (#10311 has landed), so it follows in its own pull request once #10352 lands.test_dynamic_segment.pyreplacespartial-entrywithtrailing-bytes-after-null(declared size 0x18 pastDT_NULLover non-zero bytes, converts) andpartial-terminator(declared size cut 8 bytes intoDT_NULL, refused), runs every executable case for Linux, Windows, macOS andunused-filter=1, adds the same two shapes on a strict-filter fixture (one immutable code segment and a SysV hash table) underunused-filter=2for all three targets, and adds a guest module inprx/with the same two shapes for all three targets.test_conversion_diagnostics.pyexpects the module with a 17-byte dynamic segment to be refused as unterminated, with its path as before.Tested
macOS 26 (Apple silicon), Apple clang 21, relinker-only Release build with
BUILD_TESTING=ON, base60465afd3.ctest: 232/232 pass.dynamic_segmentfails on the base sources with the new test, passes with the change.python3 tools/check_conventions.py --base origin/main: passed.python3 tools/pr_overlap.py: overlaps #10403 intest_dynamic_segment.py(see Overlap below).--skip-sce-modulefor Linux,--windowsand--macos, with and without--trap-sdk-syscall-stubs:FAIL: Invalid dynamic segment size (offset 0x5c000)on all six runs. After: converts on all three targets with--trap-sdk-syscall-stubs, and without it is refused at its SDK syscall stub (Forbidden syscall instruction at code offset 0xad67), the same outcome as v0.26 (0x2187).Windows 11 Pro, WinLibs GCC 15.2.0 r7 (the
build.ymlrelinker toolchain), relinker-only Release build withBUILD_TESTING=ON, head0103719e1(this PR merged withmain14c99b52a).ctest: 306/306 pass,dynamic_segmentincluded.python3 tools/check_conventions.py --base origin/main: passed.test_dynamic_segment.py(theconvertsignature and the end of the case list). The merge ofmainkeeps this PR'sconvert, which still accepts themodesargument of #10403'sduplicatecase, and keeps both case blocks.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)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-24T11:03:33Z.
Review: APPROVED
I reran the exact head
68f5474263b6b69b95ee94eb09d582742efc8a4elocally on Linux with GCC 12.2: the relinker-only Release build completed,ctest -R dynamic_segmentpassed (1/1), andgit diff --check upstream/main...HEADis clean. The PR report also records a full 232/232 macOS suite and a broad public-payload differential sweep; hosted conventions, intake, and labels pass. The parser change is platform-neutral and its focused fixture exercises the Linux, Windows, and macOS output modes. I could not run a Windows-host build here; the repository workflow did not schedule platform builds for this PR.Imported from boykopovar/AnyPS5. Originally posted by roboterspinne on 2026-10-25T12:56:54Z.
Review: COMMENTED
Reviewed head
68f547426merged ontoupstream/mainc2e087b2a6(2026-10-25); the merge is clean. It is also clean onto the currentmaina5a780eaa, whose 2 newer commits touch neithercore/relinkernortools.Environment: Windows 11 Home 10.0.26200, Intel i9-12900H, WinLibs GCC 15.2.0 UCRT, CMake 4.3.1, Ninja 1.13.2, Python 3.13.9,
-DANYPS5_RELINKER_ONLY=ON -DBUILD_TESTING=ON, Release.Results
long_pathsskipped. The one failure ispatch_advisor_unit. It fails the same way on plainmainon this machine, because the temp path contains a space (#10667), and it is unrelated.dynamic_segmentandconversion_diagnosticspass.main, both tests fail: 20 case/mode failures indynamic_segment, plus both module cases inconversion_diagnostics. Reverting one parser at a time shows each one is pinned on its own:ElfReader:partial-terminator,trailing-bytes-after-nulland both strict cases.CodeInstructionCollector: the three trailing-bytes cases, for--windowsand--macosonly.RelativeRelocationIndex:trailing-bytes-after-null [unused-filter=1].StrictNidFilter:strict-trailing-bytes-after-null, all three modes.GuestImageReader: both module cases andconversion_diagnostics.DT_NULLinside thePT_LOADand declaredp_fileszas 0x318, 0x320 and 0xbf8 instead of the exact 0x80 (0x90 for the strict fixture). I converted each for Linux,--windows,--macos,unused-filter=1and, on the strict fixture,unused-filter=2.p_filesz/p_memszbytes of the input header. On macOS it also differs in the metadata copy of that header and in the content-hashLC_UUID(MacOsImage.cpp:890onmain).PT_DYNAMIC(SegmentFilter.cpp:19) and rebuild their own.% 16checks that remain apply only to the relinker's rebuilt tables, as you describe: onmainthey areLinuxElfPatcher.cpp:195,GuestModuleBuilder.cpp:32,MacOsMachOPatcher.cpp:34andWindowsImportBuilder.cpp:36, and all of them readSysVDynamicSection::DynamicSegmentData.EntryPointCollector.cppalready looped over whole entries.check_conventions.py --base upstream/mainpasses with this title and body. Since you are a first-time contributor, the hosted relinker jobs were skipped, so the local runs (BunnyFl's and this one) are the Windows evidence.Nit
python3 tools/pr_overlap.py: no overlap", but the Overlap bullet and the bot's comment both name #10403 (a conflict intest_dynamic_segment.py). That line could say so.Notes, nothing to change here
strict-partial-terminatoris refused byElfReader(FAIL: Unterminated dynamic segment) before the strict filter runs. So the strict filter's ownStrict filter: unterminated dynamic segmentbranch is not reached by the test; reverting onlyStrictNidFilterleaves that case green. Its loop change is still pinned bystrict-trailing-bytes-after-null.import_audit.pyloop you defer.Not checked: the elfldr v0.27 image and the 24-image sweep (third-party binaries I did not download, so the real-world case rests on your sweep and the synthetic fixtures); running the Linux and macOS outputs.
Apart from the nit in the description, I found nothing to change. For disclosure: #10403 is my PR and conflicts with this one in
test_dynamic_segment.py(theconvertsignature and the end of the case list). Resolving it means taking this PR'sconvertand keeping both case blocks. My #10731 also editsGuestImageReader.cpp, in a different hunk, and merges cleanly with this PR. My other open relinker PRs don't touch these files.Written with AI assistance (Claude Code). I ran the build, the tests, the per-parser counter-check and the conversions above on my Windows 11 machine.
Imported from boykopovar/AnyPS5. Originally posted by roboterspinne on 2026-10-26T08:37:52Z.
Review: APPROVED
@vingelvatten Thanks, checked
0103719e1merged ontomain204c6747d(2026-10-26); the merge is clean. Windows 11, GCC 15.2, relinker-only Release.mainleaves this PR's source changes as I reviewed them. Intest_dynamic_segment.pyit keeps yourconvertwith its four default modes, and #10403'sduplicatecase still runs with its own three modes.ctest: 306 of 307 pass, includingdynamic_segmentandconversion_diagnostics;patch_advisor_unitfails the same way on plainmain, andlong_pathsis skipped.main's five source files under these tests,dynamic_segmentfails attrailing-bytes-after-null, andconversion_diagnosticsfails at the module case that now expectsUnterminated dynamic segment.Disclosure: #10403 was my PR; it has landed, and this merge keeps its test as it was. None of my open PRs touches these files.
I found nothing else to change.
Written with AI assistance (Claude Code). I ran the checks above on my Windows 11 machine.