Repository navigation
fix(relinker): reject relocations against a non-null executable symbol entry 0 - #11367
oneandonlydean merged 4 commits into
Conversation
…l entry 0 A symbolic relocation with symbol index 0 read the name, binding and type of dynamic symbol entry 0, so a named entry 0 turned STN_UNDEF relocations into named imports on Linux, Windows and macOS. The ELF gABI reserves index 0 as STN_UNDEF and requires its entry to be all zero, and the guest reader already rejects such a table as "Invalid null symbol". The relinker now fails with "Dynamic symbol table entry 0 is not a null symbol entry" when a symbolic relocation names index 0 and that entry has a nonzero byte; relocations against an all-zero entry 0 are unchanged.
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed exact head b1e3b814fbc75af569bb3fb4f7f90e22b547ee9d against current main. The current branch includes its merge base; neither touched path has changed on main since 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 RELATIVE path 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_host fixture target. Current-main conventions and git diff --check passed. Hosted relinker/ASan jobs are still running; Linux and Windows product jobs are skipped by path policy.
|
CI follow-up to my exact-head review of |
MarcZX10
left a comment
There was a problem hiding this comment.
The reviewed relinker change remains unchanged at b1e3b814fbc75af569bb3fb4f7f90e22b547ee9d, but its base is now 118 commits behind current main 5b5d24cb22. 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 current main. 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.
|
@MarcZX10 Synced with current |
MarcZX10
left a comment
There was a problem hiding this comment.
Re-reviewed exact head 028e58a. The branch includes main at 5b5d24c; 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.
|
@MarcZX10 Since your approval, |
|
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
|
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 4017310, an input whose
R_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. fix(relinker): reject an executable dynamic string table that does not begin with NUL #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 feat(relinker): route ps5-payload-dev pathconf stub to libkernel export #10792 and fix(relinker): analyze referenced code beyond SCE scan boundaries #10861, which also changeRelinkerPipeline.cpp, because they do not merge withmain. Checked by hand againstmain7b41552: feat(relinker): route ps5-payload-dev pathconf stub to libkernel export #10792 addsFindPathconfImportafter line 25 and changes the syscall patch loop (lines 431 to 437); fix(relinker): analyze referenced code beyond SCE scan boundaries #10861 changes the unwind block that fix(relinker): mask embedded data tables in inter-FDE gaps #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 feat(relinker): route ps5-payload-dev pathconf stub to libkernel export #10792;GuestModuleBuilder.cpp, thehasEhFrameblock ofRelinkerPipeline.cppanddocs/dev/debt/relinker.mdfor fix(relinker): analyze referenced code beyond SCE scan boundaries #10861), and apart from the conflict marker labels the merged trees differ from those ofmainonly by the lines of this PR. fix(relinker): analyze referenced code beyond SCE scan boundaries #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 untouched 4017310 fails 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 onto e05ba6f, which has no relinker changes since 4017310; 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 untouched 4017310 and withDynamic symbol table entry 0 is not a null symbol entry (offset 0x620)with the change.main(7b41552, which includes fix(relinker): reject out-of-range executable TLS symbols #11058) into the branch without conflicts (7c0b736; the earlier merges are 5b5d24c in 028e58a and 204c674 in b1e3b81);tools/check_main_sync.py --base upstream/mainreported 0 behind and a clean merge at 7b41552, and the later merges onmainup to 035ac96 touch no relinker file. On 7c0b736,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 fix(relinker): reject out-of-range executable TLS symbols #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.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 test(tools): compare quoted and resolved paths in the patch advisor test #10667 fixes); both failed again alone.python tools/check_conventions.py --base upstream/mainwith this title and description passed on 7c0b736.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)