fix(libkernel_sys): follow a symbolic link in link on Windows #9336
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/9336"
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 ycbuzi on 2026-10-21T18:45:32Z.
What
linkfollows a symbolic link source, as FreeBSD's does (7cba4ce60a). It decided that withstd::filesystem::is_symlink, and MinGW-w64's libstdc++ never reports a Windows symbolic link as one:symlink_statusof aCreateSymbolicLinkWlink withFILE_ATTRIBUTE_REPARSE_POINTset returns a regular file. So on Windowslinkmade a hard link to the symbolic link itself. The test for following is under#ifndef _WIN32, so nothing showed it.On Windows
linknow checks the source forFILE_ATTRIBUTE_REPARSE_POINT, asfchmodatin the same file does. It opens a reparse point source withCreateFileWwithoutFILE_FLAG_OPEN_REPARSE_POINTand links toGetFinalPathNameByHandleWof that handle. A dangling link returnsENOENTand a loop (ERROR_CANT_RESOLVE_FILENAME)ELOOP, instead of linking the reparse point. A source that resolves to a directory returnsEPERM, as before. Linux and macOS are unchanged.The link-through-a-link case of
guest_kernel_sysnow runs on Windows too, when symbolic links can be created. It usesdot-linkfor its link to., because the Windows part of the test already makes adirectory-linkearlier. On Windows it checks that the new name is not a reparse point, sinceis_symlinkcannot tell there.Tested
Windows 11 Home 10.0.26200, MinGW-w64 GCC 15.2.0 (ucrt-posix-seh r7), Release,
BUILD_TESTING=ON, onmain950388bfd2:guest_kernel_sys, elevated so symbolic links can be created: passes 3 of 3.Export.cppfrommain: fails atGuestKernelSys.cpp:692(guest errno 2), the new name is a reparse point.symlinkfails there, so the new block is skipped, which the test shows withsymbolic links unavailable: the symlink success cases not tested. (Thethe link cases not testedline comes from an earlier block that usesstd::filesystem::create_symlink, which MinGW's libstdc++ does not implement.)mainwas merged into this branch (339d5c11d7). The only conflict was its ENOTDIR return on the destination line next to this change; both are kept.guest_kernel_syspasses 3 of 3 on the merge.37ba44ce4d): after a guestsymlink("loop-b", "loop-a")andsymlink("loop-a", "loop-b"),linkfromloop-areturnsELOOP(62)._wstat64succeeds on the loop, so the existence check lets it through, andCreateFileWthen fails withERROR_CANT_RESOLVE_FILENAME(1921).guest_kernel_syspasses 2 of 2 with it. A chain of 40 links is linked, where FreeBSD stops at 32; the debt file records it (e9e345fbf3).symlink("owned.txt", "owned.link"), thenlink("owned.link", "other.txt"). Onmain,other.txtis a reparse point,owned.linkhas 2 links andowned.txt1. With this changeother.txtis a plain file andowned.txthas 2 links.python tools/check_conventions.py --base origin/mainpasses.tools/pr_overlap.py): #8522, now merged, is handled above. #6044 movesGuestKernelSys.cpp. #5528 changes onlyreadlink, and #5021 and #7201 do not touchlink.Found while running #9103's new
linkattest on Windows; itsAT_SYMLINK_FOLLOWcase goes through thislink.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)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by cadenasynyster on 2026-10-21T19:08:08Z.
Independent Windows run of this PR (head
a29386856).Environment: Windows 11 10.0.26300, Ryzen 7 9800X3D, WinLibs GCC 15.2.0 r7 (MinGW), Release, BUILD_TESTING=ON. PowerShell not elevated, Developer Mode on.
Results:
guest_kernel_syspasses 3/3 (--repeat until-fail:3).core/libs/prx/libkernel_sys/Export.cppwith the merge-base version.guest_kernel_sysfails with "Kernel sys check failed at line 692 (guest errno 2)", the same as the description's negative control. I restored the PR's file afterwards.On the unelevated note in the description: my run also printed "symbolic links unavailable: the link cases not tested", but the new link-through-a-link cases still ran. The base failure at line 692 is inside that block, and that block's own skip message ("the symlink success cases not tested") was not printed. The "link cases not tested" message comes from the earlier readlink block, which creates its link with
std::filesystem::create_symlink, and that call failed here. The new block depends on the guestsymlinkinstead, which passesSYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE, and on this machine it succeeded without elevation. So whether the new cases ran is shown by the absence of "the symlink success cases not tested", not by the "link cases not tested" line. I did not check whycreate_symlinkfails here.Not run: a symbolic link loop or a chain of links, Linux/macOS, the full repository CTest, and any title.
AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by ycbuzi on 2026-10-21T19:14:02Z.
@cadenasynyster thanks for the run and for the correction. You're right:
the link cases not testedcomes from the earlier block, whosestd::filesystem::create_symlinkcannot succeed on Windows with MinGW's libstdc++ (it fails with "Function not implemented" here even elevated). The skip line for the new block isthe symlink success cases not tested. My unelevated run had Developer Mode off, so the guestsymlinkfailed and that line was printed too. I've corrected the description.Since #8522 landed in the meantime, I merged
maininto the branch (339d5c11d7). The conflict was its ENOTDIR return on the destination line just above this change; both are kept, andguest_kernel_syspasses 3 of 3 on the merge.Imported from boykopovar/AnyPS5. Originally posted by harisibrar1 on 2026-10-22T13:41:43Z.
Review: COMMENTED
Checked against main
8b3e39832aand the Windows SDK 10.0.26100 UCRT source (ucrt/filesystem/stat.cpp):is_symlinkhere, so the fix is still needed.link_nid_postfixrunsstd::filesystem::status(source)and returns ENOENT/ENOTDIR when it doesn't exist (Export.cpp:374-375), beforeFollowLinkPath(:381). On MinGW thatstatusis UCRT_wstat64, and when CreateFileW fails on a path that isn't a drive root, UCRT stat reports ERROR_FILE_NOT_FOUND (stat.cpp:378-388). So a loop comes back as ENOENT beforeFollowLinkPathruns. Example: guestsymlink("b","a"),symlink("a","b"),link("a","x")should give 62 (ELOOP) as on FreeBSD, but would give 2. CouldFollowLinkPathrun before the existence check on Windows, with a loop case added toguest_kernel_sys? I couldn't run this locally (Smart App Control blocked my probe), so a run on your side would confirm it.Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.
Imported from boykopovar/AnyPS5. Originally posted by harisibrar1 on 2026-10-22T18:09:04Z.
Review: APPROVED
Rechecked at
e9e345fbf3:_wstat64error path but didn't run it, and on a real loop it succeeds, so the existence check lets it through andFollowLinkPathreturnsELOOPas intended. Sorry for the noise.guest_kernel_sys(37ba44ce4d) pins that, and the debt line (e9e345fbf3) records that longer chains link here, where FreeBSD stops atMAXSYMLINKS(32). Nothing left from my side.Reviewed with AI assistance (Claude Code).