fix(relinker): contain explicit module dirs #18000

Merged
DonRyuzaki merged 1 commit from upstream-pr/18000 into main 2026-11-16 02:14:32 +00:00
DonRyuzaki commented 2026-11-10 03:25:45 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by DonRyuzaki on 2026-11-10T03:25:45Z.


What

--module-dir checked that a requested path was lexically beneath the guest module parent, then followed directory symlinks while scanning. A link inside the parent could point to an outside directory: the relinker accepted it, read an external PRX, and staged the converted module under app0.

Resolve the existing parent and requested directory to canonical paths before scanning. Reject a requested directory whose resolved path is outside the parent, while preserving links that resolve to a directory inside it. This check applies to explicit --module-dir paths; the automatic sce_module, sce_modules, and prx directories are unchanged.

The regression checks direct and nested links to an external directory for Linux and --windows output. It also converts through a link to an inside directory as a positive control.

Tested

Ubuntu 24.04 on WSL2, x86-64, GCC 13.3.0, CMake 3.28.3, relinker-only Ninja build. Branch head a7cef341daa30bf24710e4c290c33d35d5a04193, based on upstream main 017bd95f5f53192c82eba8917d91f1c5fd1376de. The isolated WSL core/relinker source matched this head byte for byte before the build.

  • Negative control: the new test_guest_module_dir.py fails against the preceding relinker binary at --module-dir linked: it exits 0, converts the outside plugin.prx, and prints an app0/linked/plugin.prx.guest.prx layout. That binary's NativeModules.cpp Git blob is 85fd4731e54e9e1b1b53114d685b06bc1001c40b, identical to this PR's base.
  • nice -n 10 cmake --build <isolated-build> --target relinker --parallel 2: passed, compiling the changed NativeModules.cpp and linking the relinker.
  • ctest --test-dir <isolated-build> -R '^guest_module_dir$' --output-on-failure: 1/1 passed.
  • ctest --test-dir <isolated-build> -R '^(guest_module_dir|guest_module_directories|guest_needed_modules)$' --output-on-failure: 3/3 passed.
  • python tools/check_conventions.py --base origin/main: passed after rebasing. git diff --check origin/main...HEAD: clean.

tools/pr_overlap.py could not run because gh is unavailable in this environment. I checked the current open PRs that mention NativeModules.cpp through GitHub: #17536 changes missing-module hints after line 142, and #17538 changes exclusion filtering after line 100. Their patches do not touch this PR's explicit-directory validation at lines 80–92. No native Windows build, title, or game runtime was tested.

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; silent stubs are documented
  • No notes, investigation files, or images added to the repository
  • 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
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5235250077 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/18000). Originally posted by [DonRyuzaki](https://github.com/DonRyuzaki) on 2026-11-10T03:25:45Z. --- ### What `--module-dir` checked that a requested path was lexically beneath the guest module parent, then followed directory symlinks while scanning. A link inside the parent could point to an outside directory: the relinker accepted it, read an external PRX, and staged the converted module under `app0`. Resolve the existing parent and requested directory to canonical paths before scanning. Reject a requested directory whose resolved path is outside the parent, while preserving links that resolve to a directory inside it. This check applies to explicit `--module-dir` paths; the automatic `sce_module`, `sce_modules`, and `prx` directories are unchanged. The regression checks direct and nested links to an external directory for Linux and `--windows` output. It also converts through a link to an inside directory as a positive control. ### Tested Ubuntu 24.04 on WSL2, x86-64, GCC 13.3.0, CMake 3.28.3, relinker-only Ninja build. Branch head `a7cef341daa30bf24710e4c290c33d35d5a04193`, based on upstream `main` `017bd95f5f53192c82eba8917d91f1c5fd1376de`. The isolated WSL `core/relinker` source matched this head byte for byte before the build. - Negative control: the new `test_guest_module_dir.py` fails against the preceding relinker binary at `--module-dir linked`: it exits 0, converts the outside `plugin.prx`, and prints an `app0/linked/plugin.prx.guest.prx` layout. That binary's `NativeModules.cpp` Git blob is `85fd4731e54e9e1b1b53114d685b06bc1001c40b`, identical to this PR's base. - `nice -n 10 cmake --build <isolated-build> --target relinker --parallel 2`: passed, compiling the changed `NativeModules.cpp` and linking the relinker. - `ctest --test-dir <isolated-build> -R '^guest_module_dir$' --output-on-failure`: 1/1 passed. - `ctest --test-dir <isolated-build> -R '^(guest_module_dir|guest_module_directories|guest_needed_modules)$' --output-on-failure`: 3/3 passed. - `python tools/check_conventions.py --base origin/main`: passed after rebasing. `git diff --check origin/main...HEAD`: clean. `tools/pr_overlap.py` could not run because `gh` is unavailable in this environment. I checked the current open PRs that mention `NativeModules.cpp` through GitHub: #17536 changes missing-module hints after line 142, and #17538 changes exclusion filtering after line 100. Their patches do not touch this PR's explicit-directory validation at lines 80–92. No native Windows build, title, or game runtime was tested. ### Checklist - [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 - [x] Unimplemented paths throw; silent stubs are documented - [x] No notes, investigation files, or images added to the repository - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
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!18000
No description provided.