Repository navigation
fix(libkernel_sys): stop link at 32 symbolic links as FreeBSD does - #14548
Conversation
|
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
|
There was a problem hiding this comment.
Correction (2026-11-01): the title-ID/log demand below is not a CONTRIBUTING requirement; Unblocks: none is allowed. The technical points below are unaffected.
Two questions on SymbolicLinkLimitError in libkernel_sys/Export.cpp, and one on evidence.
-
Absolute targets.
if (target.has_root_path()) current = target.root_path();restarts the walk at the host root. When a guest created the link with an absolute guest path (/app0/...,/data/...), what doessymlinkstore on disk, the guest string or a translated host path? If it stores the guest string, this walk resolves it against the host filesystem, not the guest mount table, so the count for that chain is wrong (and a link the host cannot read is not counted at all). The test only uses relative targets, so it cannot show which case applies. Please add an absolute-target chain, or point at where the translation happens. -
Walk and the real link are separate operations. The count is taken first by walking the path with per-component
symlink_status/GetFileAttributesW, and then the reallinkruns. That is two lookups of the same path, so a concurrent rename can make the answer differ from what the call acts on. ForELOOPonly that is probably acceptable, but it should be stated as the reason this is not done by letting the host report its own loop error. Is there a reason the hostELOOP/ERROR_CANT_RESOLVE_FILENAMEresult is not mapped instead of reimplementing the walk? (I can see the Windows host does not report it, but on Linux the limit is 40, so the code is needed on both; a note on that would help.) -
Evidence. No title ID with a log line showing a title hitting
link/linkaton a chain of symlinks on main. Without that this is a debt-entry fix with a 113-line diff and the walk costs severalstat-class syscalls per component on everylinkcall.
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed — no blocking findings
The change counts symbolic links while resolving the source and the new name in link and linkat, and returns ELOOP at the 33rd, as the debt entry describes for FreeBSD 11.4's MAXSYMLINKS (32). I read the whole production hunk: relative link targets are resolved against the directory that holds the link, absolute targets reset the walk, and .. is handled. The new test's counts (32 allowed, 33 refused, on the file chain, the folder chain, and the destination side) agree with that logic. The guest test did not run in the hosted Windows job, and its symlink-unavailable branch returns early and passes.
What I ran
- Head
de2b3c010fe4e546d505366d1a198d7fb08e0553; basef2d874c1fdccf781c0fa5d86619bb5dd8894b958. 3 files, +113/-1:core/libs/prx/libkernel_sys/Export.cpp(+54),core/libs/tests/GuestKernelSys.cpp(+58) anddocs/dev/debt/libkernel_sys.md. - Read the full production hunk (
ReadSymbolicLinkTargetandSymbolicLinkLimitError, and their call sites inlink_nid_postfixandlinkat_nid_postfix) and the test'sCheckLinkSymbolicLinkLimit. - Read-only checks from the trusted main checkout (precheck not run: no PR-head code is run here): diff check, conventions and the stack check passed; the ABI audit is not applicable.
- Hosted: the windows CTest run has one case, a tool check.
guest_kernel_syswas not in the run. - No MarcZX10 review at this head.
Results
| Check | Result | Note |
|---|---|---|
| Diff check | passed | |
| Conventions and PR template | passed | conventions check from the main checkout |
| Mergeability and dependencies | passed | depends on none; the stack check passed |
| Link counting and ELOOP at the 33rd link | passed | read in SymbolicLinkLimitError |
| Relative and absolute targets | passed | read; a relative target keeps the directory of the link |
| Test counts (32 allowed, 33 refused) | passed | read; agree with the logic on each chain |
guest_kernel_sys (hosted) |
not run | not in the Windows CTest run |
| Symlink-unavailable branch | noted | returns early and passes vacuously (see Findings) |
| ABI audit | not applicable | no exported symbol changed |
| Build and runtime tests | not run | no local build |
| Negative controls | not run | no local build |
| Hosted CI | passed | windows passed (one tool case); linux and relinkers skipped |
Read-only check output
Precheck was not run: no PR-head code is run here. Conventions: passed. Hosted: gh api repos/boykopovar/AnyPS5/commits/de2b3c010fe4e546d505366d1a198d7fb08e0553/check-runs.
Negative control
Not run here. A negative control needs a build, and code from this head is not run here.
Findings
Blocking
None.
Non-blocking
CheckLinkSymbolicLinkLimitreturns early whensymlink_nid_postfixfails on the first link, after printing "the link chain limit not tested". The test then passes, so on a host without symlink support the limit is not checked and the run is green. Please make that case a skip (as the other tests do) or a failure, not a pass.
Sources
- Production hunk: https://github.com/boykopovar/AnyPS5/blob/de2b3c010fe4e546d505366d1a198d7fb08e0553/core/libs/prx/libkernel_sys/Export.cpp
- Test: https://github.com/boykopovar/AnyPS5/blob/de2b3c010fe4e546d505366d1a198d7fb08e0553/core/libs/tests/GuestKernelSys.cpp
- Debt entry: https://github.com/boykopovar/AnyPS5/blob/de2b3c010fe4e546d505366d1a198d7fb08e0553/docs/dev/debt/libkernel_sys.md
Not verified
- The guest test did not run hosted.
- The FreeBSD 11.4
nameireference in the debt entry was not checked.
To get this to a good state
- Nothing blocking. Make the symlink-unavailable branch report a skip or a failure, and run the guest test once.
|
Correction to my review 5732251799 (COMMENTED, head de2b3c0). The ABI row says "not applicable". The audit was not run when the review was posted. I have now run tools/pr_abi_audit.py from the main checkout at this head: status passed, 64 symbols, 0 findings, 2 limitations. The diff changes only the bodies of link_nid_postfix and linkat_nid_postfix in core/libs/prx/libkernel_sys/Export.cpp, and adds two internal helpers (ReadSymbolicLinkTarget and SymbolicLinkLimitError) with no APS5_VABI export. No export signature changed, so the statement "no exported symbol changed" still holds. The rest of the review is unchanged. |
|
Thanks, @CnRJay.
CI note: the hosted Windows job built |
What
linkandlinkatnow stop at FreeBSD 11.4's limit of 32 symbolic links per lookup. The libkernel_sys debt entry recorded the gap for Windows: there the host resolved the source, so a chain of 40 links was linked. Linux had the same gap through its own limit of 40.nameicounts every symbolic link it meets in one lookup,if (ndp->ni_loopcnt++ >= MAXSYMLINKS) error = ELOOP;, withMAXSYMLINKS32 (param.h):ELOOP.lookupfollows the last component only withFOLLOWor a trailing slash.kern_linkatlooks up the source withFOLLOWforlinkand forlinkatwithAT_SYMLINK_FOLLOW, and the new name without it. Each of the two lookups has its own count.SymbolicLinkLimitErrorwalks the host path from its root one component at a time and counts the links it follows:..goes to the parent of the resolved directory, as FreeBSD's physical lookup does...after a missing or non-directory component stops the count, so the existing checks still reportENOENTorENOTDIRas FreeBSD does.IO_REPARSE_TAG_SYMLINKreparse points count, read with the existingWindowsSymbolicLink::Read. Junctions are walked through without being counted.linkchecks the source (last component followed) and the new name (last component not followed).linkatdoes the same and follows the source's last component only withAT_SYMLINK_FOLLOW. The order of errors followskern_linkat:ELOOP/ENOENT/ENOTDIREPERMfor a directoryELOOP/ENOENT/ENOTDIREEXIST, thenEXDEVThe debt entry now states what is left:
..already dropped lexically.Tested
guest_kernel_sysgetsCheckLinkSymbolicLinkLimit. It builds chains of 33 file links and 33 directory links, made with the guest'ssymlink, and checks:linkthrough 32 links makes the hard link. Through 33,linkandlinkatwithAT_SYMLINK_FOLLOWreturnELOOP, andlinkatwithout the flag links the 33rd link itself.linkandlinkatreturnELOOP.ELOOP.linkandlinkatreturnELOOP.missing/../file33returnsENOENTandfile.txt/../file33returnsENOTDIR, as FreeBSD stops at the missing or non-directory component. Win32 dropsmissing\..lexically, so these cases are not run on Windows.Linux (Ubuntu 24.04 container, GCC 13.3.0, non-root, seccomp off):
guest_kernel_sysfails at the first 33-linklink, which succeeds.guest_kernel_sys*tests pass with--repeat until-fail:3. The 128 tests matchingkernel_sys|filesystem|link|access|directory|rename|realpath|stat|openpass...case: with the count but without the stop at a missing component,missing/../file33returnedELOOP. With the stop it returnsENOENT.Windows 11 Pro, Intel Core i5-14600KF, WinLibs GCC 15.2.0, full Release build with
libs:ctest:99% tests passed, 2 tests failed out of 3282. Both fail onmainon this machine too:guest_wide_formatting:%Zgives the host's non-ASCII zone name.agc_driver_image_plane_address_on_line.check_skips.pyreports one skip,guest_fopen_errors. It skips itself here for the same symbolic link reason.macOS: not tested. The walk shares the Linux code; macOS's own limit is 32, so the 32-link success cases hold there.
Overlaps: #11298 (dangling Windows link prefixes) and #14101 (
fchmodaton a link) also changeExport.cpp. Both merge with this branch without conflicts (git merge-tree).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)