fix(relinker): validate every entry of the Linux run path #10607

Merged
roboterspinne merged 1 commit from upstream-pr/10607 into main 2026-10-26 01:26:40 +00:00
roboterspinne commented 2026-10-24 12:25:39 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by roboterspinne on 2026-10-24T12:25:39Z.


What

Linux was the only target that wrote --rpath into the output without checking its entries.

  • Executables. LinuxElfPatcher::Patch copied the value into DT_RUNPATH unchanged, so --rpath "", :$ORIGIN/libs, $ORIGIN/libs: or /opt/a::/opt/b relinked with exit 0. glibc treats an empty entry of a non-empty DT_RUNPATH as the working directory, so such a program loads its libraries from wherever it is started, and it ignores an entirely empty DT_RUNPATH, so --rpath "" produced a program that cannot find libs/ at all. The macOS patcher rejects Empty macOS run path component is not supported (MacOsMachOPatcher.cpp) and Windows Windows run path must be a nonempty ASCII path (WindowsEntryStubBuilder.cpp). The Linux patcher now throws Empty Linux run path component is not supported with the other precondition checks at the start of Patch, for the default (fixed-base) and --lazy-binding outputs, 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 $ORIGIN entries.
  • Guest modules. GuestModuleBuilder::Build enforced the documented rule, absolute or beginning with $ORIGIN, only on the start of the whole value, so $ORIGIN/libs:, $ORIGIN::/opt/libs, $ORIGIN:relative/libs and /opt/libs: passed and the relative or empty entry reached every guest module's DT_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 of test_guest_runpath.py are unchanged. As before, the rule applies to Linux and macOS guest modules.
  • Docs. Only the --rpath row of USAGE.md changes: on Linux every colon-separated entry must be nonempty, and with guest modules each must be absolute or begin with $ORIGIN.
  • Tests. test_linux_dynamic_strings.py gains a two-entry run path that must be written as given and eight rejected runs (four values on the default and --lazy-binding outputs); test_guest_runpath.py gains the four invalid lists above. Against the main binary both tests fail at the first new rejected case with exit 0 and an output file; with this change they pass.
  • Overlap. pr_overlap.py cannot 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 with main. Checked by hand: none of them edits the --rpath row, 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_strings and guest_runpath fail against the main binary (('', [], 0, ...) and ('$ORIGIN/libs:', 0, ...), both with exit 0) and pass with this change.
  • With guest modules, --rpath '$ORIGIN:relative/libs' and --rpath '$ORIGIN/libs:' relink with exit 0 on main and now exit 2 with Guest Linux run path must be absolute or begin with $ORIGIN; --rpath '$ORIGIN:$ORIGIN/libs' still exits 0.
  • glibc behaviour behind the check, with a gcc-built program and library: RUNPATH [nonexist:] and [nonexist::x] find libdata.so only when the program is started inside the directory that holds it (exit 8 there, cannot open shared object file elsewhere); RUNPATH [] finds it in neither place.
  • python3 tools/check_conventions.py --base upstream/main with this title and description passed.
  • Not tested on Windows or macOS; the changed code is host-independent and CI runs both tests on all three hosts.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes (Claude Code)
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4995364712 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10607). Originally posted by [roboterspinne](https://github.com/roboterspinne) on 2026-10-24T12:25:39Z. --- ### What Linux was the only target that wrote `--rpath` into the output without checking its entries. - **Executables.** `LinuxElfPatcher::Patch` copied the value into `DT_RUNPATH` unchanged, so `--rpath ""`, `:$ORIGIN/libs`, `$ORIGIN/libs:` or `/opt/a::/opt/b` relinked with exit 0. glibc treats an empty entry of a non-empty `DT_RUNPATH` as the working directory, so such a program loads its libraries from wherever it is started, and it ignores an entirely empty `DT_RUNPATH`, so `--rpath ""` produced a program that cannot find `libs/` at all. The macOS patcher rejects `Empty macOS run path component is not supported` (`MacOsMachOPatcher.cpp`) and Windows `Windows run path must be a nonempty ASCII path` (`WindowsEntryStubBuilder.cpp`). The Linux patcher now throws `Empty Linux run path component is not supported` with the other precondition checks at the start of `Patch`, for the default (fixed-base) and `--lazy-binding` outputs, 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 `$ORIGIN` entries. - **Guest modules.** `GuestModuleBuilder::Build` enforced the documented rule, absolute or beginning with `$ORIGIN`, only on the start of the whole value, so `$ORIGIN/libs:`, `$ORIGIN::/opt/libs`, `$ORIGIN:relative/libs` and `/opt/libs:` passed and the relative or empty entry reached every guest module's `DT_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 of `test_guest_runpath.py` are unchanged. As before, the rule applies to Linux and macOS guest modules. - **Docs.** Only the `--rpath` row of `USAGE.md` changes: on Linux every colon-separated entry must be nonempty, and with guest modules each must be absolute or begin with `$ORIGIN`. - **Tests.** `test_linux_dynamic_strings.py` gains a two-entry run path that must be written as given and eight rejected runs (four values on the default and `--lazy-binding` outputs); `test_guest_runpath.py` gains the four invalid lists above. Against the `main` binary both tests fail at the first new rejected case with exit 0 and an output file; with this change they pass. - **Overlap.** `pr_overlap.py` cannot 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 with `main`. Checked by hand: none of them edits the `--rpath` row, and #8076 leaves the run path check untouched. ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> 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_strings` and `guest_runpath` fail against the `main` binary (`('', [], 0, ...)` and `('$ORIGIN/libs:', 0, ...)`, both with exit 0) and pass with this change. - With guest modules, `--rpath '$ORIGIN:relative/libs'` and `--rpath '$ORIGIN/libs:'` relink with exit 0 on `main` and now exit 2 with `Guest Linux run path must be absolute or begin with $ORIGIN`; `--rpath '$ORIGIN:$ORIGIN/libs'` still exits 0. - glibc behaviour behind the check, with a gcc-built program and library: `RUNPATH [nonexist:]` and `[nonexist::x]` find `libdata.so` only when the program is started inside the directory that holds it (exit 8 there, `cannot open shared object file` elsewhere); `RUNPATH []` finds it in neither place. - `python3 tools/check_conventions.py --base upstream/main` with this title and description passed. - Not tested on Windows or macOS; the changed code is host-independent and CI runs both tests on all three hosts. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: <!-- #PR, or none --> none - [x] Fixes: <!-- issue it closes as Fixes #N, or none --> none - [x] Unblocks: <!-- title ID and Game bring-up discussion, e.g. PPSA01325 #3232, or none --> none - [x] GPUs tested: <!-- for AGC, shader recompiler or VideoOut changes: vendor, model, driver and OS of each GPU the GPU tests ran on; otherwise n/a --> n/a - [x] AI-assisted: <!-- yes / no --> yes (Claude Code)
MarcZX10 commented 2026-10-24 12:32:21 +00:00 (Migrated from github.com)

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.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5638245801 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10607#pullrequestreview-5638245801). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-24T12:32:21Z. **Review:** APPROVED --- Reviewed head 5362dcaaf08eb33cf237a5ac6720235352cae08b. 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.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!10607
No description provided.