fix(libkernel_sys): link a symbolic link itself in linkat without AT_SYMLINK_FOLLOW #11595

Merged
alvaroelpob merged 4 commits from upstream-pr/11595 into main 2026-10-28 12:32:30 +00:00
alvaroelpob commented 2026-10-26 22:09:12 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by alvaroelpob on 2026-10-26T22:09:12Z.


What

linkat threw (NotImplemented_nid_no_patch) when its source is a symbolic link and AT_SYMLINK_FOLLOW is not set. FreeBSD 11.4's kern_linkat looks the source up with NOFOLLOW in that case and refuses only a directory vnode (EPERM), so it links the symbolic link itself, also when the link dangles or names a directory.

On Linux and macOS the host's linkat(AT_FDCWD, source, AT_FDCWD, destination, 0) does the same, so that case now goes there, after the destination checks link already makes (EEXIST for a taken name, then ENOTDIR or ENOENT for the parent). EXDEV maps to the guest's EXDEV, as in LinkNative. Any other host error throws, as it does there. The source checks that follow the link (ENOENT for a dangling link, EPERM for a directory) apply only with AT_SYMLINK_FOLLOW. The destination checks move into LinkDestinationError, which LinkNative and the new path share; LinkNative keeps its behaviour. Windows still throws. Its hard link to a reparse point was not tested, and I have no Windows machine.

The debt entry is cut to the Windows case.

Tested

Ubuntu (WSL2, kernel 6.18.54, ext4), GCC 15.2.0, Release, full build with BUILD_TESTING=ON on main a2175b54fd.

  • guest_kernel_sys, new checks (not on Windows): linkat with flag 0 gives a symbolic link, a dangling one and one naming a directory a second name. The new name reads the same target, the link's own lstat count is 2 and the target's count does not change. With AT_SYMLINK_FOLLOW, the dangling link fails with ENOENT and the directory link with EPERM. A taken destination fails with EEXIST, a missing parent with ENOENT and a file as parent with ENOTDIR. The test aborts on main at the first of these calls and passes with the change.
  • Full ctest -j at the head commit: 2393/2394 pass. agc_driver_multisample_retirement fails the same way on main on this machine.
  • check_conventions.py --base upstream/main passes. pr_overlap.py --branch finds no compared overlap. For the PRs it could not compare (conflicting with main), I checked their hunks by hand: none change the link code, the debt line or the lines the test changes.
  • Not tested: Windows, macOS, a title, a PS5.

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
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5025393643 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11595). Originally posted by [alvaroelpob](https://github.com/alvaroelpob) on 2026-10-26T22:09:12Z. --- ### What `linkat` threw (`NotImplemented_nid_no_patch`) when its source is a symbolic link and `AT_SYMLINK_FOLLOW` is not set. FreeBSD 11.4's [`kern_linkat`](https://github.com/freebsd/freebsd-src/blob/releng/11.4/sys/kern/vfs_syscalls.c) looks the source up with `NOFOLLOW` in that case and refuses only a directory vnode (`EPERM`), so it links the symbolic link itself, also when the link dangles or names a directory. On Linux and macOS the host's `linkat(AT_FDCWD, source, AT_FDCWD, destination, 0)` does the same, so that case now goes there, after the destination checks `link` already makes (`EEXIST` for a taken name, then `ENOTDIR` or `ENOENT` for the parent). `EXDEV` maps to the guest's `EXDEV`, as in `LinkNative`. Any other host error throws, as it does there. The source checks that follow the link (`ENOENT` for a dangling link, `EPERM` for a directory) apply only with `AT_SYMLINK_FOLLOW`. The destination checks move into `LinkDestinationError`, which `LinkNative` and the new path share; `LinkNative` keeps its behaviour. Windows still throws. Its hard link to a reparse point was not tested, and I have no Windows machine. The debt entry is cut to the Windows case. ### 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 (WSL2, kernel 6.18.54, ext4), GCC 15.2.0, Release, full build with `BUILD_TESTING=ON` on `main` a2175b54fd. - `guest_kernel_sys`, new checks (not on Windows): `linkat` with flag 0 gives a symbolic link, a dangling one and one naming a directory a second name. The new name reads the same target, the link's own `lstat` count is 2 and the target's count does not change. With `AT_SYMLINK_FOLLOW`, the dangling link fails with `ENOENT` and the directory link with `EPERM`. A taken destination fails with `EEXIST`, a missing parent with `ENOENT` and a file as parent with `ENOTDIR`. The test aborts on `main` at the first of these calls and passes with the change. - Full `ctest -j` at the head commit: 2393/2394 pass. `agc_driver_multisample_retirement` fails the same way on `main` on this machine. - `check_conventions.py --base upstream/main` passes. `pr_overlap.py --branch` finds no compared overlap. For the PRs it could not compare (conflicting with `main`), I checked their hunks by hand: none change the link code, the debt line or the lines the test changes. - Not tested: Windows, macOS, a title, a PS5. ### 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: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
copilot-pull-request-reviewer[bot] commented 2026-10-26 22:11:14 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by copilot-pull-request-reviewer[bot] on 2026-10-26T22:11:14Z.

Review: COMMENTED


Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5659796908 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11595#pullrequestreview-5659796908). Originally posted by [copilot-pull-request-reviewer[bot]](https://github.com/apps/copilot-pull-request-reviewer) on 2026-10-26T22:11:14Z. **Review:** COMMENTED --- Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.
MarcZX10 commented 2026-10-26 22:17:16 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-26T22:17:16Z.

Review: APPROVED


The flag check still rejects unsupported bits before resolving paths. For flag 0, the code now distinguishes a symlink source and uses POSIX linkat(..., 0) so the new name refers to that same symlink inode; AT_SYMLINK_FOLLOW keeps the existing target-link path and preserves ELOOP/directory behavior through LinkSourceError. The tests cover regular, dangling and directory symlinks, both flag modes, destination collisions and missing/non-directory parents. The author reports the focused test and full Linux suite (with the same unrelated multisample failure on main); conventions pass. Windows and macOS are untested, and the hosted product jobs are skipped by path policy. I did not rerun the native test locally.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5659855957 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11595#pullrequestreview-5659855957). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-26T22:17:16Z. **Review:** APPROVED --- The flag check still rejects unsupported bits before resolving paths. For flag 0, the code now distinguishes a symlink source and uses POSIX `linkat(..., 0)` so the new name refers to that same symlink inode; `AT_SYMLINK_FOLLOW` keeps the existing target-link path and preserves `ELOOP`/directory behavior through `LinkSourceError`. The tests cover regular, dangling and directory symlinks, both flag modes, destination collisions and missing/non-directory parents. The author reports the focused test and full Linux suite (with the same unrelated multisample failure on `main`); conventions pass. Windows and macOS are untested, and the hosted product jobs are skipped by path policy. I did not rerun the native test locally.
jotitadev commented 2026-10-27 01:24:47 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-27T01:24:47Z.

Review: COMMENTED


An independent Linux run of the new POSIX path, which the Windows run above does not reach.

Exact head 0f2a263a20, merged on main cb45ae2dd with no conflicts. Linux x86_64 (bare metal, not WSL), i7-8700, Ubuntu 26.04, kernel 7.0, ext4, GCC 15.2, CMake 4.2.3, Ninja, Release, BUILD_TESTING=ON, full build.

  • guest_kernel_sys passes, 3 of 3 runs, including the new flag-0 checks (symbolic link, dangling link, link naming a directory) and the AT_SYMLINK_FOLLOW and destination error checks.
  • The neighbouring kernel_sys, filesystem and kernel tests pass, 31 of 31 (guest_kernel_sys_*, guest_kernel_fcntl*, guest_kernel_rename, guest_filesystem, among others).
  • Full non-GPU suite on the same main without the PR: 1361/1361.
  • With only core/libs/prx/libkernel_sys/Export.cpp reverted to main (new test kept), guest_kernel_sys aborts with linkat: a hard link to a symbolic link itself not implemented. So the test covers the new behaviour on Linux and fails without the change.

Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5661189430 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11595#pullrequestreview-5661189430). Originally posted by [jotitadev](https://github.com/jotitadev) on 2026-10-27T01:24:47Z. **Review:** COMMENTED --- An independent Linux run of the new POSIX path, which the Windows run above does not reach. Exact head `0f2a263a20`, merged on `main` `cb45ae2dd` with no conflicts. Linux x86_64 (bare metal, not WSL), i7-8700, Ubuntu 26.04, kernel 7.0, ext4, GCC 15.2, CMake 4.2.3, Ninja, Release, `BUILD_TESTING=ON`, full build. - `guest_kernel_sys` passes, 3 of 3 runs, including the new flag-0 checks (symbolic link, dangling link, link naming a directory) and the `AT_SYMLINK_FOLLOW` and destination error checks. - The neighbouring kernel_sys, filesystem and kernel tests pass, 31 of 31 (`guest_kernel_sys_*`, `guest_kernel_fcntl*`, `guest_kernel_rename`, `guest_filesystem`, among others). - Full non-GPU suite on the same `main` without the PR: 1361/1361. - With only `core/libs/prx/libkernel_sys/Export.cpp` reverted to `main` (new test kept), `guest_kernel_sys` aborts with `linkat: a hard link to a symbolic link itself not implemented`. So the test covers the new behaviour on Linux and fails without the change. Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
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!11595
No description provided.