fix(relinker): reject relocations against a non-null executable symbol entry 0 #11367
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/11367"
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-26T08:58:07Z.
What
A symbolic relocation in the executable with symbol index 0 read the name, binding and type of dynamic symbol entry 0 like any import. On untouched
4017310678, an input whoseR_X86_64_GLOB_DATandR_X86_64_64relocations name index 0 while entry 0 is(st_name "foo", st_info 0x12)converted with exit 0 for Linux,--windowsand--macos: the Linux output importsfooas a global function for both slots, and the Windows program exits 0xC0000139 withFAIL: unresolved ELF import foo. The ELF gABI reserves index 0 asSTN_UNDEFand requires its entry to be all zero; the guest reader already rejects an entry 0 with a name or any nonzero field in modules (Invalid null symbol,GuestImageReader.cpp:184).symbolEntryPosinRelinkerPipeline.cppthrowsDynamic symbol table entry 0 is not a null symbol entryat the entry's file offset, after its bounds check, whensymIdxis 0 and any of the entry's 24 bytes is nonzero; the CLI exits 2 and writes no output. OnlyextractRelaasks for index 0: theRELATIVE, defined-TLS and TLS-pass paths skip index 0, and the export loop starts at entry 1, so the check fires only for a symbolic relocation against index 0, and a dynamic symbol table that aliases other data without such a relocation is unaffected. Relocations against an all-zero entry 0 keep theSTN_UNDEFmeaning fromdocs/dev/debt/relinker.md(value 0 plus addend); linkers emit an all-zero entry 0, and the relocations of OliSe Player (PPSA01153) point at all-zero entries. An unnamed nonzero entry 0 now reports this message instead ofUnnamed import symbol is not a null symbol entry; that message still covers other indices. #11382 rejects a dynamic string table that does not begin with NUL.test_null_symbol_relocations.pygets a case built fromimage_with(index=0)with string table\0foo\0libfoo.prx\0,DT_NEEDEDlibfoo.prxand entry 0(1, 0x12, 0, 0, 0, 0); Linux,--windowsand--macosmust exit 2 with the message and no output. The existing all-zero index-0 and index-1 cases (exit 42 on Windows) and the unnamed index-1 case are unchanged.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 nearsymbolEntryPos(line 305), where this PR adds lines 311 to 313. 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. #10861 treats every relocation against index 0 as a null symbol relocation inCodeInstructionCollector.cpp; for the executable that code runs only afterextractRela, so with this PR it never sees a non-null entry 0. The fixtures of both pull requests keep entry 0 all zero.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.null_symbol_relocationswith the new case on untouched4017310678fails withAssertionError: ('linux', 0, ''); run per target, the assertions are('linux', 0, ''),('windows', 0, '')and('macos', 0, ''), after the existing cases passed. The untouched Windows output ran and exited 0xC0000139 withFAIL: unresolved ELF import foo. Rebased ontoe05ba6feeb, which has no relinker changes since4017310678; with the change it passed there in 1.6 s.st_info0x12 and relocations against index 0 failed on all three targets withUnnamed import symbol is not a null symbol entry (offset 0x620)on untouched4017310678and withDynamic symbol table entry 0 is not a null symbol entry (offset 0x620)with the change.main(7b415520b6, which includes #11058) into the branch without conflicts (7c0b736c68; the earlier merges are5b5d24cb22in028e58a18fand204c6747d0inb1e3b814fb);tools/check_main_sync.py --base upstream/mainreported 0 behind and a clean merge at7b415520b6, and the later merges onmainup to035ac96eddtouch no relinker file. On7c0b736c68,ctest -R 'null_symbol|symbol|import|weak_imports|executable_export|executable_tls_relocations' -j 6: 22 tests passed:null_symbol_relocations(1.1 s),executable_tls_relocations(extended by #11058),macos_trace_imports,import_audit,import_symbol_types,windows_import_modules,executable_export_bounds,guest_relative_section_symbols,guest_unused_import_dependencies,guest_absolute_symbols,guest_symbol_names,windows_trace_imports,linux_trace_imports,windows_named_imports,linux_named_imports,linux_guest_named_imports,symbolize_samples,macos_executable_exports,linux_executable_exports,weak_imports,windows_guest_weak_imports,macos_guest_weak_imports.7c0b736c68: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 on7c0b736c68.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-26T09:01:07Z.
Review: APPROVED
Reviewed exact head
b1e3b814fbc75af569bb3fb4f7f90e22b547ee9dagainst currentmain. The current branch includes its merge base; neither touched path has changed onmainsince that base.The guard is placed after the existing symbol-entry bounds validation and rejects symbol index 0 only when a symbolic relocation reads a nonzero entry. The
RELATIVEpath and the existing TLS index-zero handling remain unaffected. The regression fixture exercises a named, nonzero entry 0 across Linux, Windows, and macOS output modes, while retaining the existing all-zero null-entry coverage. I found no blocking issue in the code or test.Independent Linux relinker-only Release build with GCC 12.2 succeeded. The focused null-symbol test passed, and the 20-test symbol/import/export selection passed 20/20 after building its required
guest_module_args_hostfixture target. Current-main conventions andgit diff --checkpassed. Hosted relinker/ASan jobs are still running; Linux and Windows product jobs are skipped by path policy.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-26T10:03:28Z.
Review: CHANGES_REQUESTED
The reviewed relinker change remains unchanged at
b1e3b814fbc75af569bb3fb4f7f90e22b547ee9d, but its base is now 118 commits behind currentmain5b5d24cb22. The merge preview is clean and main has not changed the two PR paths since the merge base; current conventions and diff checks pass. The contribution checklist requires branches based on currentmain. Please rebase and rerun the focused symbol-table tests on the resulting head before approval; the existing hosted relinker matrix passed on the older head, and the latest base should be represented in that validation.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-26T10:50:32Z.
Review: APPROVED
Re-reviewed exact head
028e58a18f. The branch includes main at5b5d24cb; current main has advanced since then, but the intervening changes do not touch this PR's two changed paths, and the current-main merge preview is clean. The author reports 20/20 focused symbol/import/export tests passing on this exact head, with all hosted relinker, ASan, eligibility, conventions, intake, and labels checks green. The symbol-index guard remains after bounds validation and leaves RELATIVE and TLS index-zero handling intact. No blocking issue found.