feat(libkernel_sys): create symlink targets with parent-directory components #10625

Merged
Dom3005 merged 5 commits from upstream-pr/10625 into main 2026-11-02 10:23:35 +00:00
Dom3005 commented 2026-10-24 13:31:09 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Dom3005 on 2026-10-24T13:31:09Z.


What

symlink threw parent-directory targets for any target with a .. component, such as ../file.txt or ... FreeBSD 11.4 stores the target unchanged and its namei resolves the .. later, from the directory that holds the link.

Here the link is a host symbolic link, so the host follows it, not the guest path resolver. A .. target is therefore created only when both reach the same place:

  • every directory a .. leaves must exist and not be a symbolic link, so the host's physical .. gives the same directory as the resolver's lexical one;
  • the target joined to the link's host directory, normalised, must equal the guest path it names (the link's guest directory joined with the target), resolved through the guest mounts.

Anything else still throws, with a message that names the reason: a .. that climbs out of a mount such as /savedata0, or a .. past a directory reached through a symbolic link. Absolute targets still throw as well; they would need a host path stored in the link and a translation back in readlink. The checks run after the existing EEXIST, ENOENT and ENOTDIR checks on the new name, so those errors come first, as in FreeBSD's kern_symlinkat.

A new symlink entry in docs/dev/debt/libkernel_sys.md describes the rule and what still throws.

Tested

Windows 11 26200, WinLibs MinGW-w64 GCC 15.2.0 r7, CMake + Ninja, Release, -DBUILD_TESTING=ON, Developer Mode on (so the link success cases run), on main 6cd36e6517.

  • guest_kernel_sys gets cases that:
    • create ../file.txt, deeper/../../file.txt and .., check readlink returns each target unchanged, and read the file through the link;
    • create a dangling ../missing/x;
    • create deeper/../up inside an aliased mount and read through it.
      a/../b with a missing a, a/../../x and /abs still throw.
      The symlink-prefix and mount-escape paths are still unimplemented and not pinned by tests, per review.
  • After merging main (f02a94df4e) and dropping those two throw cases, guest_kernel_sys passes again. With the original change, guest_kernel_sys passed 3 of 3, and the 82 tests matching kernel_sys|filesystem|symlink|readlink|lstat|stat|rename|link|chmod|access|open|path pass. The full build has 0 failed steps.
  • Control, main's Export.cpp with the new test: guest_kernel_sys aborts with symlink: parent-directory targets not implemented.
  • Not run on Linux locally; the Linux CI job covers it.
  • python tools/check_conventions.py --base upstream/main passes. tools/pr_overlap.py reports only #9442, which adds a declaration on the same line of GuestKernelSys.cpp. None of the other open PRs that touch libkernel_sys/Export.cpp change symlink.

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: #9442 (merged; main merged in at 61316594bc)
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4995808203 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10625). Originally posted by [Dom3005](https://github.com/Dom3005) on 2026-10-24T13:31:09Z. --- ### What `symlink` threw `parent-directory targets` for any target with a `..` component, such as `../file.txt` or `..`. FreeBSD 11.4 stores the target unchanged and its `namei` resolves the `..` later, from the directory that holds the link. Here the link is a host symbolic link, so the host follows it, not the guest path resolver. A `..` target is therefore created only when both reach the same place: - every directory a `..` leaves must exist and not be a symbolic link, so the host's physical `..` gives the same directory as the resolver's lexical one; - the target joined to the link's host directory, normalised, must equal the guest path it names (the link's guest directory joined with the target), resolved through the guest mounts. Anything else still throws, with a message that names the reason: a `..` that climbs out of a mount such as `/savedata0`, or a `..` past a directory reached through a symbolic link. Absolute targets still throw as well; they would need a host path stored in the link and a translation back in `readlink`. The checks run after the existing `EEXIST`, `ENOENT` and `ENOTDIR` checks on the new name, so those errors come first, as in FreeBSD's `kern_symlinkat`. A new `symlink` entry in `docs/dev/debt/libkernel_sys.md` describes the rule and what still throws. ### Tested Windows 11 26200, WinLibs MinGW-w64 GCC 15.2.0 r7, CMake + Ninja, Release, `-DBUILD_TESTING=ON`, Developer Mode on (so the link success cases run), on `main` `6cd36e6517`. - `guest_kernel_sys` gets cases that: - create `../file.txt`, `deeper/../../file.txt` and `..`, check `readlink` returns each target unchanged, and read the file through the link; - create a dangling `../missing/x`; - create `deeper/../up` inside an aliased mount and read through it. `a/../b` with a missing `a`, `a/../../x` and `/abs` still throw. The symlink-prefix and mount-escape paths are still unimplemented and not pinned by tests, per review. - After merging `main` (`f02a94df4e`) and dropping those two throw cases, `guest_kernel_sys` passes again. With the original change, `guest_kernel_sys` passed 3 of 3, and the 82 tests matching `kernel_sys|filesystem|symlink|readlink|lstat|stat|rename|link|chmod|access|open|path` pass. The full build has 0 failed steps. - Control, `main`'s `Export.cpp` with the new test: `guest_kernel_sys` aborts with `symlink: parent-directory targets not implemented`. - Not run on Linux locally; the Linux CI job covers it. - `python tools/check_conventions.py --base upstream/main` passes. `tools/pr_overlap.py` reports only #9442, which adds a declaration on the same line of `GuestKernelSys.cpp`. None of the other open PRs that touch `libkernel_sys/Export.cpp` change `symlink`. ### 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: #9442 (merged; `main` merged in at 61316594bc) - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
MarcZX10 commented 2026-10-24 13:41:02 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-24T13:41:02Z.

Review: APPROVED


Reviewed exact head 69a7bd2c19dd68c1b269705ef33bfbf35609452c. The change permits relative .. targets only when the host’s physical traversal agrees with the guest path resolution: every directory being left exists and is not a symlink, and the resulting host path matches the resolved guest target. It keeps absolute targets and paths that escape mount aliases or traverse symlink directories unsupported. The added tests cover preserved readlink text, file reads through valid parent targets, dangling targets, a symlinked path component, mount escape, and an in-mount parent traversal. I checked the reported #9442 overlap: it only adds a separate declaration in the shared test file.

git diff --check upstream/main...HEAD and python3 tools/check_conventions.py --base upstream/main --head HEAD pass. Hosted eligibility, conventions, intake, labels, and report pass; hosted product jobs were skipped. The Windows 11 filesystem/CTest results in the PR description are author-reported; I did not independently run Windows. I found no blocking issue in this implementation.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5638446756 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10625#pullrequestreview-5638446756). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-24T13:41:02Z. **Review:** APPROVED --- Reviewed exact head `69a7bd2c19dd68c1b269705ef33bfbf35609452c`. The change permits relative `..` targets only when the host’s physical traversal agrees with the guest path resolution: every directory being left exists and is not a symlink, and the resulting host path matches the resolved guest target. It keeps absolute targets and paths that escape mount aliases or traverse symlink directories unsupported. The added tests cover preserved readlink text, file reads through valid parent targets, dangling targets, a symlinked path component, mount escape, and an in-mount parent traversal. I checked the reported #9442 overlap: it only adds a separate declaration in the shared test file. `git diff --check upstream/main...HEAD` and `python3 tools/check_conventions.py --base upstream/main --head HEAD` pass. Hosted eligibility, conventions, intake, labels, and report pass; hosted product jobs were skipped. The Windows 11 filesystem/CTest results in the PR description are author-reported; I did not independently run Windows. I found no blocking issue in this implementation.
MarcZX10 commented 2026-10-24 13:49:16 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-24T13:49:16Z.

Review: CHANGES_REQUESTED


Follow-up on the new overlap warning at exact head 69a7bd2c19dd68c1b269705ef33bfbf35609452c: I manually compared #9442 and #10625. git merge-tree --write-tree upstream/pr/9442 upstream/pr/10625 reports a content conflict in core/libs/tests/GuestKernelSys.cpp at the adjacent prototype block: #9442 adds the lchflags_nid_postfix declaration, while this PR adds AddPathAlias_nid_no_patch and RemovePathAlias_nid_no_patch there. The declarations are independent and can be retained together, but the authors still need an agreed merge order and the dependent PR should record Depends on: #N per CONTRIBUTING. The current checklist says Depends on: none.

Please coordinate with #9442's author and update the dependency/order note. My earlier approval covered the symlink implementation; this follow-up requests changes only for the unresolved shared-file merge coordination.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5638474253 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10625#pullrequestreview-5638474253). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-24T13:49:16Z. **Review:** CHANGES_REQUESTED --- Follow-up on the new overlap warning at exact head `69a7bd2c19dd68c1b269705ef33bfbf35609452c`: I manually compared #9442 and #10625. `git merge-tree --write-tree upstream/pr/9442 upstream/pr/10625` reports a content conflict in `core/libs/tests/GuestKernelSys.cpp` at the adjacent prototype block: #9442 adds the `lchflags_nid_postfix` declaration, while this PR adds `AddPathAlias_nid_no_patch` and `RemovePathAlias_nid_no_patch` there. The declarations are independent and can be retained together, but the authors still need an agreed merge order and the dependent PR should record `Depends on: #N` per CONTRIBUTING. The current checklist says `Depends on: none`. Please coordinate with #9442's author and update the dependency/order note. My earlier approval covered the symlink implementation; this follow-up requests changes only for the unresolved shared-file merge coordination.
MarcZX10 commented 2026-10-24 15:28:29 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-24T15:28:29Z.

Review: APPROVED


Re-reviewed exact head 69a7bd2c19dd68c1b269705ef33bfbf35609452c. The overlap issue is now handled: the author proposed #9442 first, updated the checklist to Depends on: #9442, and will retain both declaration blocks on rebase. The symlink path checks and test coverage remain as previously reviewed. Current git diff --check, repository conventions and merge-tree checks pass; hosted eligibility, intake, conventions, labels and report pass, while product jobs are skipped. The Windows test results are author-reported and were not independently reproduced here.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5638784011 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10625#pullrequestreview-5638784011). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-24T15:28:29Z. **Review:** APPROVED --- Re-reviewed exact head `69a7bd2c19dd68c1b269705ef33bfbf35609452c`. The overlap issue is now handled: the author proposed #9442 first, updated the checklist to `Depends on: #9442`, and will retain both declaration blocks on rebase. The symlink path checks and test coverage remain as previously reviewed. Current `git diff --check`, repository conventions and merge-tree checks pass; hosted eligibility, intake, conventions, labels and report pass, while product jobs are skipped. The Windows test results are author-reported and were not independently reproduced here.
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!10625
No description provided.