fix(libkernel_sys): fail symlink with ENAMETOOLONG for a target of 1024 bytes or more #8723
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/8723"
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 xXPBSXx on 2026-10-20T22:25:00Z.
What
symlink_nid_postfix(libkernel_sys/Export.cpp) had no length check on the target. FreeBSD 11.4kern_symlinkatcopies the target withcopyinstr(path1, syspath, MAXPATHLEN, NULL)(vfs_syscalls.c:1490) before it looks up the link name, andMAXPATHLENis 1024 (sys/syslimits.h:63), so a target of 1024 bytes or more fails withENAMETOOLONG(63).symlinknow does the same before any other check of the target or the link name.Fixes #8722
git merge-treeagainstupstream/main, #8522, #8680, #8312 and #8603 is clean; #5528 (readlink path length, open) conflicts inExport.cpp(one conflict); whichever lands second rebases.pr_overlapwas not run.Tested
Windows 10 (19045), MinGW-w64 GCC 15.2.0, Release, on
upstream/main+ headb3a9fbe3ea:guest_kernel_sys: targets of 1024 and 1100 bytes return -1 with errno 63 and create no link. Without the change it fails atGuestKernelSys.cpp:301(errno 1); with it it passes.symlink_nid_postfixis called only fromGuestKernelSys.cpp, so there is no other caller test to run.python tools/check_conventions.py --base upstream/main: passes.Checklist
main; no other open PR implements the same functions.mdfiles or images added to the repositoryAI-assisted (Claude Code).
🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-20T22:29:09Z.
Review: APPROVED
Reviewed the current diff and
upstream/main:GuestPathMaxis 1024, and applying the same bound to the symlink target before resolving the link path matches the cited FreeBSDcopyinstrlimit. The existingResolvePathError_nid_no_patchalready uses this boundary for guest paths. The Windows test checks both 1024-byte and longer targets returnENAMETOOLONGand leave no link. The author reports the focused Windows test and conventions check passing. Hosted platform build jobs are skipped and Linux/macOS were not tested, so this approval is based on the focused result and the small, localized change.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-21T03:53:39Z.
Review: COMMENTED
One useful boundary case is still missing from the regression: the current test checks 1024 and 1100 bytes, but not 1023. Since
copyinstr(..., MAXPATHLEN, ...)permits at mostMAXPATHLEN - 1payload bytes plus the NUL, a 1023-byte target should still succeed while 1024 fails. Adding the accepted boundary case would protect against changing>= GuestPathMaxto> GuestPathMax(or accidentally tightening the guest limit).Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-21T04:29:00Z.
Thanks, added.
GuestKernelSys.cppnow also tries a 1023-byte target: it must not fail with ENAMETOOLONG (it either links, or fails for a host reason such as missing symlink privilege, and a created link is removed again). 1024 and 1100 bytes still fail with 63. To check that the new case guards the boundary I changed the comparison insymlink_nid_postfixto>= GuestPathMax - 1:guest_kernel_systhen fails at GuestKernelSys.cpp:308 (errno 63); with the real comparison it passes (Windows 10, MinGW-w64 GCC 15.2, Release; commit241c8d5973). Not tested again on Linux/macOS after this commit.AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by ycbuzi on 2026-10-21T04:46:12Z.
Windows run of
241c8d5973merged ontomainaa408677b0(d74d8acda9, clean), covering the boundary the description lists as not tested. Windows 11 Home 10.0.26200, MinGW-w64 GCC 15.2.0 (ucrt-posix-seh r7), Release,BUILD_TESTING=ON, run elevated, so symbolic links can be created here.guest_kernel_sys: passes (1.5 s).libkernel_sys.prx, callingsymlinkwith targets of 1022, 1023, 1024 and 1100 bytes into a scratch folder: 1022 and 1023 return 0,readlinkgives the target back at its full length, and the link is removed; 1024 and 1100 return -1 with errno 63 andreadlinkfinds no link. So the boundary sits where the PR puts it. One observation, data only: the probe zeroed errno before each call, and after the two successfulsymlinkcalls errno read 2.Not run: Linux or macOS.
Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-21T05:34:19Z.
Thanks for the run and the boundary data.
On the errno of 2 after a successful
symlink: it is left behind by a host call, not set by this change.symlink_nid_postfixlooks atstd::filesystem::is_directory(parent / target, error)to choose between a file and a directory link, and the target here does not exist. A standalone probe (Windows 10, MinGW-w64 GCC 15.2) shows that call setting the Cerrnoitself:is_directoryof a missing path returns false withec= 2 anderrno= 2, while the same call on an existing directory leaveserrnoat 0. The success path ofsymlink_nid_postfixdoes not touch errno, so it keeps that value. A caller must not readerrnoafter a call that returned 0 (POSIX leaves it unspecified there), so I would leave this as it is; this PR only adds the length check. The sameis_directory(native.parent_path() / contents, error)call is already onmain(libkernel_sys/Export.cpp,symlink_nid_postfix), so the stale value is not introduced by this change. Not tested: whether otherlibkernel_syscalls leave a stale errno the same way.Probe output (Windows 10, MinGW-w64 GCC 15.2,
std::filesystem::is_directorywith anerror_code):I did not check whether another call in the function also leaves errno set.
AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by ycbuzi on 2026-10-21T06:03:42Z.
Thanks for tracing it: agreed that a stale errno after a 0 return is outside what a caller may read, and that
is_directoryonmainis where it comes from, not this change.Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-21T22:53:10Z.
Review: COMMENTED
Confirmed
red→greenon Linux, which the description lists as not tested (both the author's run and @ycbuzi's are Windows). The fix is insymlink_nid_postfix, before any platform-specific work, so it applies to Linux too — and the unfixed path behaves differently there.Tested
Ubuntu 26.04, i7-8700, GCC 15.2.0, Release,
BUILD_TESTING=ON, onmaina6dcea927(head241c8d5973applies cleanly on it).guest_kernel_sysmaina6dcea927+ the test only (Export.cppreverted)GuestKernelSys.cpp:301, guest errno 36On Linux, with the length check reverted, the 1024-byte target reaches the host
symlink()and the guest ends up with errno 36 (LinuxENAMETOOLONG) rather than the FreeBSDENAMETOOLONG63 the test asserts — so the unfixed value differs from the Windows errno 1 reported earlier. With the PR,symlink_nid_postfixreturns63before the host call and the test passes, including the 1023-byte boundary case added in241c8d5973.Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.