fix(libkernel_sys): read and link through the paths the 32-link walk resolved #23786
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/23786"
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 Colewiz7 on 2026-11-19T16:40:53Z.
What
readlink,readlinkat,linkandlinkatwalk their paths throughSymbolicLinkLimitError(FreeBSD's 32-link limit), then hand the host the original paths, so the host walks the same chains again. On Linux that second walk can fail.filename_lookupinfs/namei.csetstotal_link_countonce inset_nameidata, tries the lockless walk, and on-ECHILDretries the locked walk without resetting it. In my measurements, another process creating mount namespaces is what forces that retry. So a chain of more than 20 links counts twice and can exceedMAXSYMLINKS(40), and the host returnsELOOP.All four calls now pass the host the paths the walk resolved, on Windows too, so the host follows no links. A trailing
/is kept, and is computed before the walk writes its result, sincelinkandlinkatpass the same path in and out.That is what made
guest_kernel_sys_paths_readlink_limits,guest_kernel_sys_paths_readlinkat_limits(both variants) andguest_kernel_sys(Kernel sys check failed at line 467,471or475) fail now and then in parallel runs. Two test-side causes are fixed too:GuestKernelSysPaths.cppnamed its directory aftersteady_clockalone, and two variants started together could pick the same name (create_directoryfailed at line 116). Astd::random_devicesuffix fixes it.guest_kernel_sys's cleanup removedfolder32/created.txtthrough the 32-link chain and could fail the same way (cannot remove: Too many levels of symbolic links). It now removesfolder/created.txt.The new
guest_kernel_sys_paths_readlink_remounts(and_patched) pins the fix. A child process creates user and mount namespaces in a loop while the test reads a link at the end of a 31-link chain 20,000 times. It skips where unprivileged user namespaces are not allowed, and off Linux.Tested
Linux 7.3.4 (CachyOS), GCC 16.2.1 Release,
maind2082a7ef3.mainguest_kernel_sys_paths_readlink_remounts, 3 runs of both variantsunshare -rm trueguest_kernel_syswhile a loop ranunshare -rm trueThe
maincolumn of the first row is this branch withmain'slibkernel_sys/Export.cpp.ctest -R '^guest_kernel_sys|^guest_(libc_)?filesystem|^guest_libc_internal_unversioned_filesystem': 72/72.Python
os.lstatshows the host side alone: under the sameunshareloop, 150,000 calls per row gaveELOOP3,396 times through 21 links, 3,707 through 22, 3,536 through 23 and 4,748 through 31, and none through 18 or 20. Without the loop, 31 links gave none.The MinGW cross build succeeds. Under wine every
guest_kernel_sys_pathstest fails within 0.05 s onmaintoo (the binary stops before any case runs), and so do the two new ones.Not tested: Windows hosts, macOS, other Linux kernels at runtime.
Overlap
#9389 (
sigqueue) and #15037 (mountprivilege checks) edit other functions inlibkernel_sys/Export.cpp. This PR replaces #23767.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)Summary by CodeRabbit
Bug Fixes
readlinkreliability when mount namespaces are changing.Tests
readlinkbehavior during mount activity and for symbolic-link path handling.Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-19T16:51:13Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
805708d8e4:tools/check_conventions.pypassed.guest_kernel_sys_paths_tests,guest_kernel_sys_testsbuilt cleanly.guest_kernel_sys_paths_statfs,guest_kernel_sys_paths_statfs_patched,guest_kernel_sys_paths_symlinkat,guest_kernel_sys_paths_symlinkat_patched,guest_kernel_sys_paths_symlinkat_errors,guest_kernel_sys_paths_symlinkat_errors_patched,guest_kernel_sys_paths_futimesat,guest_kernel_sys_paths_futimesat_patched,guest_kernel_sys_paths_readlink_limits,guest_kernel_sys_paths_readlink_limits_patched,guest_kernel_sys_paths_readlinkat_limits,guest_kernel_sys_paths_readlinkat_limits_patched,guest_kernel_sys):core/libs/prx/libkernel_sys/Export.cppreverted tomainand the new tests kept, the suite fails: Restoring the change makes it pass again.Looks Good To Me
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-20T22:28:49Z.
Review: APPROVED
Reviewed — looks good
The reviewed change is sound based on the inspected code, and I found no verified blocking defects.
What I ran
Reviewed head
a2fcb097b841b4f7252945b289f9f7e65a8454f5using the prepared diff and targeted source reads throughrepo_read.py. No tests or builds were run.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
No test or build was run during this review. The author reports Linux test results and a MinGW cross build; those results were not independently verified. Windows hosts, macOS, and other Linux kernels were not runtime-tested per the description. Read:
core/libs/CMakeLists.txt,core/libs/prx/libkernel_sys/Export.cpp,core/libs/tests/GuestKernelSys.cpp, andcore/libs/tests/GuestKernelSysPaths.cpp. Excluded changed files: none (files.jsonwas not available as a review-folder document; the manifest and file listing show all four changed files included).To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-30T00:24:58Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the points below are optional.
What I ran
Reviewed head
78f8cb978eddb851ea661fb3d7608e93afdb7fd1. No commands or tests were run; the author-reported test results were not independently verified.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
Runtime behavior, builds, and the reported tests were not independently verified. All four changed files listed in the manifest were read; no files were excluded by the manifest.
To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-11-30T00:25:21Z.
Review: COMMENTED
Actionable comments posted: 2
Architecture findings (2)
Advisory architecture findings (2)
9f5d53be-6841-40c9-9103-3c941b955948Reviewing files that changed from the base of the PR and between
b3856362f3and78f8cb978e.core/libs/CMakeLists.txtcore/libs/prx/libkernel_sys/Export.cppcore/libs/tests/GuestKernelSys.cppcore/libs/tests/GuestKernelSysPaths.cppIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T13:05:42Z.
Review: COMMENTED
Built the change through the project on Linux and passed all 14 registered kernel sys-path cases, including the paired raw and patched library tests for path limits and symlink resolution.
AI-assisted: yes.