fix(libkernel): return ELOOP when stat follows a symlink loop #6992
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/6992"
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 MarcZX10 on 2026-10-17T02:24:53Z.
What
On Windows,
sceKernelStatcan identify a self-referencing symlink as not found throughstd::filesystem::status, then_wstat64fails while following the link andFillFileStatthrows. The exception escapes the syscall and aborts the process. This change adds a non-throwing stat helper for this syscall and maps WindowsERROR_CANT_RESOLVE_FILENAMEto guestELOOPthrough the existing Windows errno translation. Other stat failures return through the regular errno mapping.Tested
guest_filesystem_testsbuilds successfully.sceKernelStatself-loop assertion. Windows execution is not available here, so the_doserrnomapping and Windows regression remain unverified.python3 tools/check_conventions.py --base upstream/mainpasses;git diff --checkpasses.Checklist
main; no open PR implements the same stat-loop handlingImported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-17T02:27:54Z.
Additional validation: the changed Windows production translation units (
NativeStat.cppandOpen.cpp) andGuestFilesystem.cpppass MinGW-w64 GCC 12.2-fsyntax-onlycross-compilation with_WIN32and_WIN32_WINNT=0x0602. This verifies Windows API/type compilation only; no Windows runtime or_doserrnovalue is verified here. The focused Linux target also builds, while CTest remains blocked before assertions by this host CPU feature guard.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-17T02:34:55Z.
Thanks for this. I dispatched a full Linux + Windows build on 23ea5fdae (https://github.com/boykopovar/AnyPS5/actions/runs/38995470380), so the Windows
sceKernelStat(stat-loop)assertion gets its first real run.Two non-blocking notes from review:
SceKernelError(62)could use the existingSCE_KERNEL_ERROR_ELOOP(KernelErrors.hpp).sceKernelStatstill returns ENOENT for a loop:std::filesystem::status()reports typenonewithec == ELOOP, so the earlierexists()check inOpen.cppreturns beforeTryFillFileStatis reached. That's today's behaviour, not a regression, but the PS5 returns ELOOP there. If you want the title to hold on Linux too: afterstatus(),if (error.value() == ELOOP) return SCE_KERNEL_ERROR_ELOOP;, plus a LinuxsceKernelStat(loop) == 0x8002003Eassertion next to the Windows one.Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-17T02:38:10Z.
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.
core/libs/prx/libkernel/File/src/NativeStat.cppcore/libs/prx/libkernel/File/src/Open.cppcore/libs/tests/GuestFilesystem.cppcore/libs/prx/libkernel/File/src/NativeStat.cppcore/libs/prx/libkernel/File/src/Open.cppcore/libs/prx/libkernel/File/src/Open.cppcore/libs/prx/libkernel/File/src/NativeStat.cppcore/libs/prx/libkernel/File/src/Open.cppcore/libs/prx/libkernel/File/src/NativeStat.cppcore/libs/prx/libkernel/File/src/Open.cppImported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-17T02:40:34Z.
Addressed in
b2d9b59e7:sceKernelStatnow maps thestd::filesystem::statusloop error throughSCE_KERNEL_ERROR_ELOOP, the native stat error path uses the same named constant, and the Linux filesystem test asserts the syscall result on a self-referencing symlink. I also filled the PR template after the initial conventions check flagged the missing required fields. The added test and conventions check pass locally; I could not run this fresh worktree’s Linux test because SDL2’s CMake package is unavailable, and Windows execution remains pending hosted CI.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-17T03:18:29Z.
Thanks for the Linux mapping. Two things break CI: (1)
GuestFilesystem.cpp:672usesSCE_KERNEL_ERROR_ELOOP, but the test doesn't includeprx/libkernel/KernelErrors.hpp, so it doesn't compile (run 38997986325). (2) The newstat-loopsymlink is never removed, so the test's finalremove_nid_postfix(root)fails with ENOTEMPTY (Windows:Filesystem check failed at line 996 (guest errno 66, Win32 error 145), run 38995470380). Could you unlink it with the other links (Linux: next tounlink_nid_postfix(link...)around line 691; Windows:DeleteFileW(statLoop.c_str())with the other links around line 742)?Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-17T03:25:33Z.
Fixed in
03418d7c3: includedKernelErrors.hppfor the named error constant and remove the self-referencing symlink in both the Linux and Windows fixture cleanup paths.Validation:
guest_filesystem_testsbuilds successfully;check_conventions.py --base upstream/mainandgit diff --checkpass. CTest still stops before the assertions on this Xeon E5-1620 v2 because it lacks the project-required LZCNT/BMI1/BMI2/MOVBE/AVX2/FMA features. The fix is pushed; Windows execution remains for hosted CI.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-17T04:16:02Z.
Thanks for catching the Linux path. The current PR head now checks for too_many_symbolic_link_levels immediately after std::filesystem::status, maps it to SCE_KERNEL_ERROR_ELOOP, and adds a Linux sceKernelStat self-loop assertion. I have not run that assertion on this Xeon host because the test binary stops at the required CPU-feature guard; the Linux/Windows full-build dispatch is still the needed runtime check.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-17T04:27:40Z.
The latest head is
03418d7c3. The current Build workflow did not exercise either platform (both Linux and Windows jobs were skipped), so the two fixture cleanup changes in this head still need CI coverage. The full Linux + Windows run dispatched on the earlier head23ea5fdaedid start both jobs, but both test steps concluded with failure; it predates the Linux mapping and fixture-cleanup follow-ups. Could you dispatch a full build for the current head so we can see whether the updated regression test passes on both platforms?Imported from boykopovar/AnyPS5. Originally posted by LeandroLP23 on 2026-10-17T06:22:12Z.
Windows runtime check, since the description has none: the self-loop assertion runs, passes with this head, and reproduces #6983 without it.
Windows 11 (26300), Ryzen AI 7 350, WinLibs GCC 15.2.0, Release, Developer Mode on (without it the test prints
Windows lstat link checks skippedand never reaches the self-loop).main6a32550fdwith this head03418d7c3merged;ctest -R '^guest_filesystem$':stat-loopassertion (sceKernelStatreturns0x8002003E) reachedGuestFilesystem.cppovermain'sNativeStat/Open/WindowsFileTime0xC0000409:[libc] unhandled exception 'St13runtime_error',what(): FillFileStat: stat failed for ...\stat-loopSo the Windows translation of the self-loop failure to ELOOP works here. I did not capture
_doserrnoseparately.AI-assisted: yes (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-17T13:18:05Z.
Thanks for the Windows runtime check. It reaches the self-loop assertion, returns guest ELOOP, and the control reproduces the original abort, which verifies the Windows path on the current head. Linux execution is still pending because this host stops at its CPU-feature guard and hosted platform jobs were skipped; I’ll keep that limitation visible while awaiting a Linux-capable run.
AI-assisted: yes (Codex); report reviewed.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-17T14:03:39Z.
Thanks for the Windows run with Developer Mode enabled and for the parent-source negative control. It confirms the self-loop assertion is reached and translated to ELOOP on this Windows setup; I have noted that
_doserrnowas not captured separately.Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-17T15:16:28Z.
Review: COMMENTED
Linux runtime result for the new self-loop assertions, since the thread notes Linux execution is still pending (the author's Xeon stops at the host CPU guard).
Machine: Linux x86_64, i7-8700, Ubuntu 26.04, GCC 15.2, Release,
BUILD_TESTING=ON, full build.Head
03418d7c3merged ontomain40315fcf8(clean merge).guest_filesystempasses with the PR, 5 of 5 runs, so on Linux bothTryFillFileStaton the loop (errno == ELOOP) andsceKernelStat(SCE_KERNEL_ERROR_ELOOP) hold. The other stat, open and filesystem tests (ctest -R "filesystem|stat|open|symlink|kernel_sys|posix_scalar", 36 tests) also pass.Open.cppas onmain(keeping the newTryFillFileStat, so the test still builds):guest_filesystemaborts. The test file alone does not build onmain, since it callsFile::TryFillFileStat.ctest -E "^agc|gpu|vulkan|video_out"): 682/682, same asmainon this machine. In a first suite runguest_dynamic_loader_fixed_baseaborted once; it then passed 10 of 10 on its own both with the PR and onmain, and the full suite rerun passed, so I count it as unrelated.Not checked: Windows (covered above), macOS.
Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-17T15:25:03Z.
Thanks for running the Linux regression and negative control. This closes the Linux runtime gap:
guest_filesystempasses 5/5 with the self-loop mapping, and the control aborts whenOpen.cppis reverted. The broader non-GPU suite also matches main at 682/682. The Windows runtime result from Leandro covers the other platform; macOS remains untested.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-17T23:51:03Z.
Rebased onto current main
bd5856170and resolved theOpen.cppconflict while preservingNativeMetadataPathextended-path handling and the non-throwing stat error path. Theguest_filesystem_teststarget builds on Linux;guest_filesystemaborts before assertions because this Xeon E5-1620 v2 host lacks required AVX2/LZCNT/BMI/FMA features.check_conventions.py --base upstream/mainandgit diff --checkpass. Current hosted conventions/eligibility/report checks pass; platform build/test jobs are skipped by path selection. The branch is mergeable.Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-18T10:09:50Z.
Review: COMMENTED
Re-run on the rebased head
b34bf86d9, since theOpen.cppconflict resolution has no runtime result yet (the author's host stops at the CPU guard and the platform jobs were skipped). My earlier run was on03418d7c3.Machine: Linux x86_64, i7-8700, Ubuntu 26.04, GCC 15.2, Release,
BUILD_TESTING=ON, full build.Head
b34bf86d9merged ontomain9caecfd2d(clean merge).guest_filesystempasses, including both self-loop checks (TryFillFileStatwith errno 40 andsceKernelStatreturningSCE_KERNEL_ERROR_ELOOP). The other filesystem/stat tests also pass (ctest -R "filesystem|stat|symlink|open", 36 tests, the VideoOut ones skipped as onmain).Open.cpptaken frommain:guest_filesystemaborts at thesceKernelStatself-loop check, which gets0x80020002(ENOENT) instead. So the resolvedOpen.cppstill carries the fix and the test still covers it.ctest -E "^agc|gpu|vulkan|video_out"): 712/712, same asmain.Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
Imported from boykopovar/AnyPS5. Originally posted by cadenasynyster on 2026-10-18T17:00:48Z.
Windows run on the rebased head b34bf86d9 (the earlier Windows run was on 03418d7c3), merged onto current main (
889cee5f9). Windows 11, MinGW GCC 15.2.0, Developer Mode on.guest_filesystem: 3 of 3 runs pass, one at a time.Open.cpptaken from main and everything else from this PR, the test aborts (exit code 0xc0000409).Not run: macOS, other Windows configurations, Developer Mode off.
AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-18T22:07:18Z.
Thanks for rerunning the rebased head
b34bf86d9on Windows. The 3/3 filesystem runs and the negative control that revertsOpen.cppconfirm the fix remains effective on this head. This complements the Linux run on the same head, where the self-loop checks pass and the reverted control fails. macOS remains untested.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-19T16:02:09Z.
Rebased onto current main. The only conflict was in
Open.cpp: main now mapstoo_many_symbolic_link_levelsthroughFilesystemError(guest 62 =SCE_KERNEL_ERROR_ELOOP), so I kept main's line and dropped the duplicate Linux mapping from this PR. The non-throwingTryFillFileStat, the WindowsERROR_CANT_RESOLVE_FILENAME→ELOOPtranslation and the Linux/Windows self-loop assertions are unchanged. Build and ctest of the affected scope pass; also confirmed by the Windows and Linux runs in the thread. Merged.