fix(libkernel_sys): read a link through the path its 32-link walk resolved #23767
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/23767"
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:06:10Z.
What
guest_kernel_sys_paths_readlink_limits,guest_kernel_sys_paths_readlinkat_limitsandguest_kernel_sys_paths_readlinkat_limits_patchedabort now and then in a parallelctestrun and pass alone. They show up as one-off failures in our full-suite runs onmain. There are two causes:ELOOPon long chains.ReadNativeLinkfirst walks the path itself (SymbolicLinkLimitError, FreeBSD's 32-link limit), then callssymlink_statusandread_symlinkon the original path, so Linux walks the same chain again. On this machine's kernel,lstatthrough a chain of more than 20 links sometimes fails withELOOP, though the limit is 40. A loop ofunshare -rm truein another process triggers it reliably. It also happened, less often, while our full test suite was running on the same machine; I haven't pinned down what in the suite triggers it. In the test that shows up asreadlink("p2/cycle")returning -1 with errno 62, when the walk had accepted the path. Now the walk hands back the host path it resolved, andreadlinkreads the last component there, so the host follows no links. A trailing/is kept, and the Windows branch is unchanged.steady_clockalone. The variants start together underctest -j, and twice two of them got the same name, so the second one'screate_directoryfailed at line 116. Astd::random_devicesuffix fixes it.The host behaviour, measured with Python
os.lstaton a chain of links ending in a link, 150,000 calls per row, while a loop ranunshare -rm true:ELOOPWithout that loop, 31-link chains gave 0 in 150,000 calls, and so did a loop that only created, renamed and deleted files. My guess is that the kernel counts the links twice when a mount change makes its lockless lookup fall back to the locked one: 2 × 21 = 42 is over 40, 2 × 20 = 40 is not. I have not confirmed this in the kernel source.
Tested
Linux 7.3.4 (CachyOS), GCC 16.2.1 Release,
maina8b2a7d2a5.ctest -R '^guest_kernel_sys': 66/66.readlinkat_limitsvariants andreadlink_limitsstarted together, 1,000 rounds each:unshare -rm truemainThe MinGW cross build succeeds. Its
guest_kernel_sys_pathstests fail under wine onmaintoo, so they say nothing here.Not tested: Windows hosts, other Linux kernels, macOS.
Overlap
#9389 (
sigqueue) and #15037 (mountprivilege checks) edit other functions inlibkernel_sys/Export.cpp.linkandlinkatuse the same walk and still pass the original path to the host; this PR leaves them alone.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 PrivacyOnion on 2026-11-19T16:16:20Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
ce75ed2cc1:tools/check_conventions.pypassed.guest_kernel_sys_paths_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):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
Pull request closed