fix(libkernel_sys): link a symbolic link itself in linkat without AT_SYMLINK_FOLLOW #11595
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/11595"
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 alvaroelpob on 2026-10-26T22:09:12Z.
What
linkatthrew (NotImplemented_nid_no_patch) when its source is a symbolic link andAT_SYMLINK_FOLLOWis not set. FreeBSD 11.4'skern_linkatlooks the source up withNOFOLLOWin 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 checkslinkalready makes (EEXISTfor a taken name, thenENOTDIRorENOENTfor the parent).EXDEVmaps to the guest'sEXDEV, as inLinkNative. Any other host error throws, as it does there. The source checks that follow the link (ENOENTfor a dangling link,EPERMfor a directory) apply only withAT_SYMLINK_FOLLOW. The destination checks move intoLinkDestinationError, whichLinkNativeand the new path share;LinkNativekeeps 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=ONonmaina2175b54fd.guest_kernel_sys, new checks (not on Windows):linkatwith 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 ownlstatcount is 2 and the target's count does not change. WithAT_SYMLINK_FOLLOW, the dangling link fails withENOENTand the directory link withEPERM. A taken destination fails withEEXIST, a missing parent withENOENTand a file as parent withENOTDIR. The test aborts onmainat the first of these calls and passes with the change.ctest -jat the head commit: 2393/2394 pass.agc_driver_multisample_retirementfails the same way onmainon this machine.check_conventions.py --base upstream/mainpasses.pr_overlap.py --branchfinds no compared overlap. For the PRs it could not compare (conflicting withmain), I checked their hunks by hand: none change the link code, the debt line or the lines the test changes.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 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.
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_FOLLOWkeeps the existing target-link path and preservesELOOP/directory behavior throughLinkSourceError. 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 onmain); 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.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 onmaincb45ae2ddwith 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_syspasses, 3 of 3 runs, including the new flag-0 checks (symbolic link, dangling link, link naming a directory) and theAT_SYMLINK_FOLLOWand destination error checks.guest_kernel_sys_*,guest_kernel_fcntl*,guest_kernel_rename,guest_filesystem, among others).mainwithout the PR: 1361/1361.core/libs/prx/libkernel_sys/Export.cppreverted tomain(new test kept),guest_kernel_sysaborts withlinkat: 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.