fix(relinker): validate every entry of the Linux run path #10607
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/10607"
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-24T12:25:39Z.
What
Linux was the only target that wrote
--rpathinto the output without checking its entries.LinuxElfPatcher::Patchcopied the value intoDT_RUNPATHunchanged, so--rpath "",:$ORIGIN/libs,$ORIGIN/libs:or/opt/a::/opt/brelinked with exit 0. glibc treats an empty entry of a non-emptyDT_RUNPATHas the working directory, so such a program loads its libraries from wherever it is started, and it ignores an entirely emptyDT_RUNPATH, so--rpath ""produced a program that cannot findlibs/at all. The macOS patcher rejectsEmpty macOS run path component is not supported(MacOsMachOPatcher.cpp) and WindowsWindows run path must be a nonempty ASCII path(WindowsEntryStubBuilder.cpp). The Linux patcher now throwsEmpty Linux run path component is not supportedwith the other precondition checks at the start ofPatch, for the default (fixed-base) and--lazy-bindingoutputs, and leaves no output. Relative entries stay accepted for executables relinked with--skip-sce-module, as on macOS, where the patcher also rejects only empty components; the guest rule below is what requires absolute or$ORIGINentries.GuestModuleBuilder::Buildenforced the documented rule, absolute or beginning with$ORIGIN, only on the start of the whole value, so$ORIGIN/libs:,$ORIGIN::/opt/libs,$ORIGIN:relative/libsand/opt/libs:passed and the relative or empty entry reached every guest module'sDT_RUNPATH. The check now walks the colon-separated entries with the same message.$ORIGIN,$ORIGIN/...and absolute entries, alone or in lists, are accepted as before; the existing list cases oftest_guest_runpath.pyare unchanged. As before, the rule applies to Linux and macOS guest modules.--rpathrow ofUSAGE.mdchanges: on Linux every colon-separated entry must be nonempty, and with guest modules each must be absolute or begin with$ORIGIN.test_linux_dynamic_strings.pygains a two-entry run path that must be written as given and eight rejected runs (four values on the default and--lazy-bindingoutputs);test_guest_runpath.pygains the four invalid lists above. Against themainbinary both tests fail at the first new rejected case with exit 0 and an output file; with this change they pass.pr_overlap.pycannot compare this branch with #5021, #5925, #6171, #6924, #7642, #7942, #9401, #9408, #9508 and #10193 (USAGE.md) or #8076 (GuestModuleBuilder.cpp), because those do not merge withmain. Checked by hand: none of them edits the--rpathrow, and #8076 leaves the run path check untouched.Tested
Ubuntu 24.04 x86_64, glibc 2.39, relinker-only Release build (
-DANYPS5_RELINKER_ONLY=ON -DBUILD_TESTING=ON); synthetic fixtures only, no title or homebrew.ctest --test-dir build-relinker -j4: 243/243 passed.linux_dynamic_stringsandguest_runpathfail against themainbinary (('', [], 0, ...)and('$ORIGIN/libs:', 0, ...), both with exit 0) and pass with this change.--rpath '$ORIGIN:relative/libs'and--rpath '$ORIGIN/libs:'relink with exit 0 onmainand now exit 2 withGuest Linux run path must be absolute or begin with $ORIGIN;--rpath '$ORIGIN:$ORIGIN/libs'still exits 0.RUNPATH [nonexist:]and[nonexist::x]findlibdata.soonly when the program is started inside the directory that holds it (exit 8 there,cannot open shared object fileelsewhere);RUNPATH []finds it in neither place.python3 tools/check_conventions.py --base upstream/mainwith this title and description passed.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-24T12:32:21Z.
Review: APPROVED
Reviewed head
5362dcaaf0. The Linux patcher rejects empty run-path components before writing output, and guest modules now validate every colon-separated component while preserving the accepted absolute and $ORIGIN forms. The added cases cover empty, leading, trailing, and interior components on default and lazy-binding Linux outputs, plus invalid guest lists. Eligibility, conventions, intake, labels, Linux/Windows/macOS relinker jobs, and relinker ASan pass; full product Linux/Windows jobs are skipped for this relinker-focused change. The described Ubuntu/glibc behavior and relinker-only CTest results are author-reported; I did not reproduce them locally.