fix(relinker): reject an executable dynamic string table that does not begin with NUL #11382
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/11382"
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 roboterspinne on 2026-10-26T10:04:41Z.
What
RelinkerPipelinereads executable names at string offset 0 without checking the first byte ofDT_STRTAB:readCStrchecks only that the offset is insideDT_STRSZand that the string ends with NUL within it. On untouched4017310678, an executable whose string table isParty.prx\0withDT_NEEDED0 converts with exit 0 and an output file for Linux, Linux--lazy-binding,--windowsand--macos(a16ff208dc3build, with the same relinker code as4017310678, also listsParty.prxinneeded.jsonunder--registry); the same offset-0 read names an import whosest_nameis 0, including the all-zero symbol entries that the null-symbol handling (#4452, #7902) resolves to 0 plus addend. In the gABI, index 0 of a string table holds a NUL byte and a string at index 0 means no name;GuestImageReaderalready rejects a module whose string table does not begin with NUL (Invalid string or symbol table).readCStrthrowsDynamic string table does not begin with a NUL byteat theDT_STRTABoffset when it reads offset 0 and the first byte of the table is not NUL, right after theDT_STRSZbounds check; the CLI exits 2 and writes no output. This covers every name the pipeline reads at offset 0:DT_NEEDED, import module names, import symbol names and export symbol names. The check sits at the offset-0 read because that is where a first byte other than NUL changes a result; a check run once for every executable would also reject the many synthetic fixtures that pointDT_STRTABat the dynamic tags withDT_STRSZ1 and read no name. Symbol entry 0 is not part of this PR; #11367 rejects relocations against a non-null symbol entry 0.test_needed_libraries.py:executable_needingtakes the bytes before the name, and a new case buildsParty.prx\0withDT_NEEDED0 and expects exit 2,FAIL: Dynamic string table does not begin with a NUL byte (offset 0x4a00)and no output for Linux, Linux--lazy-binding,--windowsand--macos. The fixtures oftest_optional_plt.py(convert_strict),test_unused_filter_indirect.py(build) andtest_executable_segments.py(with_import) relied on a table beginning withfoo; they now use\0foo\0lib.so\0,DT_NEEDED5 andst_name1 for symbol 1, which keeps the import namedfooandDT_STRSZ12. With the change and the old fixtures, all three tests fail with the new message.pr_overlap.pyreports no shared lines with open pull requests that merge withmain. It cannot compare this branch with #10792 and #10861, which also changeRelinkerPipeline.cpp, because they do not merge withmain. Checked by hand againstmain7b415520b6: #10792 addsFindPathconfImportafter line 25 and changes the syscall patch loop (lines 431 to 437); #10861 changes the unwind block that #8076 rewrote onmain(thehasEhFrameblock, lines 403 to 416), adds a tail scan after line 439 andSyscallContinuationsafter line 632. None of this is nearreadCStr(line 273), where this PR adds lines 276 and 277. Trial merges of this branch with each of them conflict in the same files and regions asmaindoes (GuestModuleBuilder.cppfor #10792;GuestModuleBuilder.cpp, thehasEhFrameblock ofRelinkerPipeline.cppanddocs/dev/debt/relinker.mdfor #10861), and apart from the conflict marker labels the merged trees differ from those ofmainonly by the lines of this PR. Neither reads a name at string offset 0: #10792 matches import names thatreadCStrhas already returned, and the fixtures that both add or reuse begin their string tables with NUL.Tested
Windows 11, GCC 15.2.0 (WinLibs UCRT), relinker-only Release build (
-DANYPS5_RELINKER_ONLY=ON -DBUILD_TESTING=ON); synthetic fixtures only, no title or homebrew, relinked outputs not run.needed_librarieswith the new case on untouched4017310678fails withAssertionError: ([], 0, b''); all four targets exited 0 with an output file and empty stderr.optional_plt,unused_filter_indirectandexecutable_segmentswith the edited fixtures pass on untouched code. Rebased onto3a2c51afd2, which has no relinker changes since4017310678; with the changeneeded_librariespassed there in 9.8 s under-j4.main(7b415520b6, which includes #11058) into the branch without conflicts (a6c2e21b3c; the earlier merges are5b5d24cb22inf15b926d04and204c6747d0inb818895614, wheremain's changes totest_executable_segments.pyandtest_unused_filter_indirect.pymerged automatically);tools/check_main_sync.py --base upstream/mainreported 0 behind and a clean merge at7b415520b6, and the later merges onmainup to035ac96eddtouch no relinker file. Ona6c2e21b3c,ctest -R 'dynamic_string|needed|null_symbol|import|linux_dynamic_strings|optional_plt|unused_filter_indirect|executable_segments|executable_tls_relocations' -j 6: 22 tests passed:needed_libraries(1.6 s),optional_plt,unused_filter_indirect,executable_segments,linux_dynamic_strings,executable_tls_relocations(extended by #11058),macos_trace_imports,guest_needed_modules,guest_needed_nested_modules,null_symbol_relocations,import_audit,import_symbol_types,guest_unused_import_dependencies,linux_trace_imports,windows_trace_imports,windows_named_imports,linux_named_imports,linux_guest_named_imports,windows_import_modules,weak_imports,windows_guest_weak_imports,macos_guest_weak_imports.a6c2e21b3c:ctest --test-dir build-relinker -j 6: 309 tests, 306 passed,long_pathsskipped; failures known on this machine onmainas well:select_tests(Windows symlink fixture) andpatch_advisor_unit(path with spaces, which open #10667 fixes); both failed again alone.python tools/check_conventions.py --base upstream/mainwith this title and description passed ona6c2e21b3c.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)Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-26T10:17:09Z.
Review: APPROVED
Reviewed the rebased head
b81889561420084ee21d33b7877e9c7d050e9599. The offset-zero guard is applied inside the boundedreadCStrpath, so it rejects a malformed string table only when the pipeline actually reads its empty-name entry. The synthetic regression and fixture updates preserve intended names while restoring the required leading NUL. Hosted Linux, Windows, macOS and macOS x86_64 relinker jobs plus ASan all pass; the reported Windows focused and full-suite results are detailed and accurately identify the two unrelated known failures.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-26T10:38:48Z.
Review: DISMISSED
The earlier approval covers the dynamic-string-table guard and its fixture behavior on head
f15b926d04. Before merge, please sync the currentmain: this branch's latest main merge is5b5d24cb22, while currentmainiscbf76e7a6eand includes #9408's macOS import-tracing changes toRelinkerPipeline.cpp. The preview merge is clean, but those integration changes are not in the tested head. Please rerun the focused dynamic-string/needed-module tests and hosted relinker matrix after syncing. This followsCONTRIBUTING.md's requirement to keep branches up to date; I’m requesting changes only for this integration check.