Windows: sceKernelStat on a self-referencing symlink throws in FillFileStat and aborts the process #6983

Closed
opened 2026-10-17 01:38:30 +00:00 by cadenasynyster · 7 comments
cadenasynyster commented 2026-10-17 01:38:30 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by cadenasynyster on 2026-10-17T01:38:30Z.


On Windows, sceKernelStat on a symbolic link that points to itself does not return an error: FillFileStat throws std::runtime_error and the process aborts.

[libc] unhandled exception 'St13runtime_error' thrown from ...
  what():  FillFileStat: stat failed for C:\Users\...\Temp\anyps5-path-errors-...\loop

Exit code 0xC0000409.

On Linux, main returns ENOENT for the same call (per the table in #6648), and #6648 / #6942 change that to ELOOP (0x8002003E), which is what FreeBSD returns.

Repro

In an empty directory, create loop -> loop (CreateSymbolicLinkA("loop", "loop", SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE); needs Developer Mode or elevation), then call sceKernelStat("loop", &st).

Other results from the same run

main f3263dfbf; identical with #6942 merged:

Call Windows result FreeBSD
sceKernelStat("loop") process abort ELOOP
sceKernelOpen("loop") EINVAL (0x80020016) ELOOP
sceKernelOpen("loop/inside") ENOENT (0x80020002) ELOOP
sceKernelOpen / sceKernelStat / sceKernelMkdir, 300-char name (cwd 70 chars) ENOENT (0x80020002) ENAMETOOLONG
POSIX open, 300-char name errno 2 errno 63

Found by running #6942's GuestPathErrors.cpp on Windows with its symlinks created through CreateSymbolicLinkA, since MinGW has no symlink(). A control with #6942's test and HostErrno files on main's Open.cpp / Stdio.cpp gives the same values and the same abort, so this predates both PRs.

Windows 11 10.0.26200.9711 (NTFS), Developer Mode on, WinLibs GCC 15.2.0 posix UCRT r7, Release.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5893631516 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/6983). Originally posted by [cadenasynyster](https://github.com/cadenasynyster) on 2026-10-17T01:38:30Z. --- On Windows, `sceKernelStat` on a symbolic link that points to itself does not return an error: `FillFileStat` throws `std::runtime_error` and the process aborts. ``` [libc] unhandled exception 'St13runtime_error' thrown from ... what(): FillFileStat: stat failed for C:\Users\...\Temp\anyps5-path-errors-...\loop ``` Exit code 0xC0000409. On Linux, `main` returns `ENOENT` for the same call (per the table in #6648), and #6648 / #6942 change that to `ELOOP` (0x8002003E), which is what FreeBSD returns. ### Repro In an empty directory, create `loop -> loop` (`CreateSymbolicLinkA("loop", "loop", SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE)`; needs Developer Mode or elevation), then call `sceKernelStat("loop", &st)`. ### Other results from the same run main f3263dfbf; identical with #6942 merged: | Call | Windows result | FreeBSD | |---|---|---| | `sceKernelStat("loop")` | **process abort** | `ELOOP` | | `sceKernelOpen("loop")` | `EINVAL` (0x80020016) | `ELOOP` | | `sceKernelOpen("loop/inside")` | `ENOENT` (0x80020002) | `ELOOP` | | `sceKernelOpen` / `sceKernelStat` / `sceKernelMkdir`, 300-char name (cwd 70 chars) | `ENOENT` (0x80020002) | `ENAMETOOLONG` | | POSIX `open`, 300-char name | errno 2 | errno 63 | Found by running #6942's `GuestPathErrors.cpp` on Windows with its symlinks created through `CreateSymbolicLinkA`, since MinGW has no `symlink()`. A control with #6942's test and `HostErrno` files on main's `Open.cpp` / `Stdio.cpp` gives the same values and the same abort, so this predates both PRs. Windows 11 10.0.26200.9711 (NTFS), Developer Mode on, WinLibs GCC 15.2.0 posix UCRT r7, Release. AI-assisted: yes
MarcZX10 commented 2026-10-17 01:48:07 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-17T01:48:07Z.


I have a focused follow-up draft for this case: it avoids throwing from the native stat path and translates the Windows failure to guest ELOOP. Before I treat it as ready, could you capture errno and _doserrno immediately after _wstat64 fails for the self-link on your Windows setup? The draft currently maps ERROR_CANT_RESOLVE_FILENAME (1921) from _doserrno; Microsoft documents that as a Win32 error code, and documents _doserrno as the OS-error equivalent for CRT I/O failures, but I have no Windows runtime to verify those exact values. The current draft is based on latest main and does not reuse code from #6648/#6942.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6228135600 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/6983#issuecomment-6228135600). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-17T01:48:07Z. --- I have a focused follow-up draft for this case: it avoids throwing from the native stat path and translates the Windows failure to guest ELOOP. Before I treat it as ready, could you capture `errno` and `_doserrno` immediately after `_wstat64` fails for the self-link on your Windows setup? The draft currently maps `ERROR_CANT_RESOLVE_FILENAME` (1921) from `_doserrno`; Microsoft documents that as a Win32 error code, and documents `_doserrno` as the OS-error equivalent for CRT I/O failures, but I have no Windows runtime to verify those exact values. The current draft is based on latest main and does not reuse code from #6648/#6942.
MarcZX10 commented 2026-10-17 02:24:57 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-17T02:24:57Z.


I opened #6992 with the non-throwing stat path and Windows self-loop regression assertion. The Linux focused target builds, but this host aborts at the CPU feature guard before test assertions. I have not verified _doserrno == ERROR_CANT_RESOLVE_FILENAME on the reported Windows runtime; the Windows PR check will provide the next validation opportunity.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6228469869 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/6983#issuecomment-6228469869). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-17T02:24:57Z. --- I opened #6992 with the non-throwing stat path and Windows self-loop regression assertion. The Linux focused target builds, but this host aborts at the CPU feature guard before test assertions. I have not verified `_doserrno == ERROR_CANT_RESOLVE_FILENAME` on the reported Windows runtime; the Windows PR check will provide the next validation opportunity.
cadenasynyster commented 2026-10-17 19:19:39 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by cadenasynyster on 2026-10-17T19:19:39Z.


@MarcZX100 answering your question: on this setup _wstat64 does not fail on the self-link. The failure comes from the CreateFileW call that follows it in DoStat.

Standalone probe, compiled with the same WinLibs GCC 15.2.0 r7 (UCRT), doing the two DoStat calls in order on loop -> loop (absolute path, created with CreateSymbolicLinkW(..., SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE)):

step 1 _wstat64:    result=0 errno=0 _doserrno=0
step 2 CreateFileW: FAILED GetLastError=1921 (ERROR_CANT_RESOLVE_FILENAME=1921)

CreateFileW is called with FILE_READ_ATTRIBUTES, OPEN_EXISTING and FILE_FLAG_BACKUP_SEMANTICS, as in DoStat. A relative _wstat64("loop") also returns 0 with errno and _doserrno 0.

So on #6992:

  • 1921 is the right code, and the ERROR_CANT_RESOLVE_FILENAME -> ELOOP mapping in WindowsFileTime::Failure is what produces the 0x8002003E result here.
  • The _doserrno == ERROR_CANT_RESOLVE_FILENAME branch after _wstat64 is not reached on this setup, since _wstat64 succeeds. I can't say whether other Windows/CRT versions fail there instead.

Windows 11 10.0.26200.9711 (NTFS), Developer Mode on.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6239422901 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/6983#issuecomment-6239422901). Originally posted by [cadenasynyster](https://github.com/cadenasynyster) on 2026-10-17T19:19:39Z. --- @MarcZX100 answering your question: on this setup `_wstat64` does not fail on the self-link. The failure comes from the `CreateFileW` call that follows it in `DoStat`. Standalone probe, compiled with the same WinLibs GCC 15.2.0 r7 (UCRT), doing the two `DoStat` calls in order on `loop -> loop` (absolute path, created with `CreateSymbolicLinkW(..., SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE)`): ``` step 1 _wstat64: result=0 errno=0 _doserrno=0 step 2 CreateFileW: FAILED GetLastError=1921 (ERROR_CANT_RESOLVE_FILENAME=1921) ``` `CreateFileW` is called with `FILE_READ_ATTRIBUTES`, `OPEN_EXISTING` and `FILE_FLAG_BACKUP_SEMANTICS`, as in `DoStat`. A relative `_wstat64("loop")` also returns 0 with `errno` and `_doserrno` 0. So on #6992: - 1921 is the right code, and the `ERROR_CANT_RESOLVE_FILENAME` -> `ELOOP` mapping in `WindowsFileTime::Failure` is what produces the `0x8002003E` result here. - The `_doserrno == ERROR_CANT_RESOLVE_FILENAME` branch after `_wstat64` is not reached on this setup, since `_wstat64` succeeds. I can't say whether other Windows/CRT versions fail there instead. Windows 11 10.0.26200.9711 (NTFS), Developer Mode on. AI-assisted: yes
MarcZX10 commented 2026-10-17 20:19:04 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-17T20:19:04Z.


Thanks for the probe. That confirms the observed Windows path: _wstat64 succeeds for the self-link, then CreateFileW fails with ERROR_CANT_RESOLVE_FILENAME (1921), which the current #6992 head maps to guest ELOOP. The earlier question about _doserrno after _wstat64 is not relevant to this setup; #6992 also handles the later CreateFileW failure. The PR has Windows runtime validation and Linux runtime validation reported, with conventions/eligibility/report passing; hosted platform build jobs were skipped on its latest workflow run.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6240367738 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/6983#issuecomment-6240367738). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-17T20:19:04Z. --- Thanks for the probe. That confirms the observed Windows path: `_wstat64` succeeds for the self-link, then `CreateFileW` fails with `ERROR_CANT_RESOLVE_FILENAME` (1921), which the current #6992 head maps to guest `ELOOP`. The earlier question about `_doserrno` after `_wstat64` is not relevant to this setup; #6992 also handles the later `CreateFileW` failure. The PR has Windows runtime validation and Linux runtime validation reported, with conventions/eligibility/report passing; hosted platform build jobs were skipped on its latest workflow run.
aarushkha commented 2026-10-20 16:33:42 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by aarushkha on 2026-10-20T16:33:42Z.


The abort in the title looks fixed on main by #6992 (merged as 32004dfa5). sceKernelStat now goes through File::TryFillFileStat instead of the throwing FillFileStat. DoStat maps the CreateFileW failure ERROR_CANT_RESOLVE_FILENAME (1921) to ELOOP in WindowsFileTime::Failure. GuestFilesystem.cpp has a Windows case that creates stat-loop -> stat-loop with CreateSymbolicLinkW and requires sceKernelStat to return 0x8002003E.

I checked this by reading main. I didn't run it. I also didn't check the other rows of the table (sceKernelOpen on the loop and the 300-character ENAMETOOLONG cases), so those may still need their own issue before this one is closed.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6295915580 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/6983#issuecomment-6295915580). Originally posted by [aarushkha](https://github.com/aarushkha) on 2026-10-20T16:33:42Z. --- The abort in the title looks fixed on `main` by #6992 (merged as `32004dfa5`). `sceKernelStat` now goes through `File::TryFillFileStat` instead of the throwing `FillFileStat`. `DoStat` maps the `CreateFileW` failure `ERROR_CANT_RESOLVE_FILENAME` (1921) to `ELOOP` in `WindowsFileTime::Failure`. `GuestFilesystem.cpp` has a Windows case that creates `stat-loop -> stat-loop` with `CreateSymbolicLinkW` and requires `sceKernelStat` to return `0x8002003E`. I checked this by reading `main`. I didn't run it. I also didn't check the other rows of the table (`sceKernelOpen` on the loop and the 300-character `ENAMETOOLONG` cases), so those may still need their own issue before this one is closed. AI-assisted: yes (Claude Code)
cadenasynyster commented 2026-10-20 19:56:22 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by cadenasynyster on 2026-10-20T19:56:22Z.


Status check on current main, run on Windows rather than read from the source. #6992 fixed the abort in the title, and this updates the other rows of the table above.

Windows 11 (NTFS, Developer Mode on), WinLibs GCC 15.2.0 r7 UCRT, Release, main fetched today. The link loop -> loop was created with CreateSymbolicLinkW(..., SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE) (it reported ok), because MinGW's std::filesystem::create_symlink returns "Function not implemented". The 300-character name is a single path component under the temp directory. A throwaway probe linked against libkernel and libc printed these rows:

Call Windows result FreeBSD Status
sceKernelStat("loop") ELOOP (0x8002003E) ELOOP fixed (#6992)
sceKernelStat("loop/inside") ELOOP ELOOP fixed
sceKernelOpen("loop") EINVAL (0x80020016), POSIX open errno 22 ELOOP open, #8640
sceKernelOpen("loop/inside") ENOTDIR (0x80020014), POSIX open errno 20 ELOOP open, no PR found
sceKernelStat, sceKernelOpen, sceKernelMkdir of a 300-character name ENAMETOOLONG (0x8002003F) for all three; POSIX stat, open, mkdir errno 63 ENAMETOOLONG fixed

So two rows from my original table no longer reproduce (the abort and the 300-character names), and two remain. GuestFilesystem.cpp runs its 300-character and loop checks only under #ifndef _WIN32, which is why main's own tests never exercised these rows on Windows. I did not re-measure the 300-character case with the original 70-character cwd; the probe used the temp directory as the parent.

Not run: Linux, macOS, a name of exactly 255 or 256 characters, or any call other than the ones listed.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6300139604 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/6983#issuecomment-6300139604). Originally posted by [cadenasynyster](https://github.com/cadenasynyster) on 2026-10-20T19:56:22Z. --- Status check on current main, run on Windows rather than read from the source. #6992 fixed the abort in the title, and this updates the other rows of the table above. Windows 11 (NTFS, Developer Mode on), WinLibs GCC 15.2.0 r7 UCRT, Release, main fetched today. The link `loop -> loop` was created with `CreateSymbolicLinkW(..., SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE)` (it reported ok), because MinGW's `std::filesystem::create_symlink` returns "Function not implemented". The 300-character name is a single path component under the temp directory. A throwaway probe linked against libkernel and libc printed these rows: | Call | Windows result | FreeBSD | Status | |---|---|---|---| | `sceKernelStat("loop")` | ELOOP (0x8002003E) | ELOOP | fixed (#6992) | | `sceKernelStat("loop/inside")` | ELOOP | ELOOP | fixed | | `sceKernelOpen("loop")` | EINVAL (0x80020016), POSIX `open` errno 22 | ELOOP | open, #8640 | | `sceKernelOpen("loop/inside")` | ENOTDIR (0x80020014), POSIX `open` errno 20 | ELOOP | **open, no PR found** | | `sceKernelStat`, `sceKernelOpen`, `sceKernelMkdir` of a 300-character name | ENAMETOOLONG (0x8002003F) for all three; POSIX `stat`, `open`, `mkdir` errno 63 | ENAMETOOLONG | fixed | So two rows from my original table no longer reproduce (the abort and the 300-character names), and two remain. `GuestFilesystem.cpp` runs its 300-character and loop checks only under `#ifndef _WIN32`, which is why main's own tests never exercised these rows on Windows. I did not re-measure the 300-character case with the original 70-character cwd; the probe used the temp directory as the parent. Not run: Linux, macOS, a name of exactly 255 or 256 characters, or any call other than the ones listed. AI-assisted: yes
MarcZX10 commented 2026-10-20 20:11:03 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-20T20:11:03Z.


The remaining Windows sceKernelOpen("loop/inside") row is now covered by #8655. The PR adds ELOOP handling for failed opens when a path resolves through the self-link and tests both the kernel API result and POSIX open errno. Its author reports the focused Windows CTest selection passing 75/75; hosted platform build jobs were skipped. The other rows in this issue remain separate.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6300431156 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/6983#issuecomment-6300431156). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-20T20:11:03Z. --- The remaining Windows `sceKernelOpen("loop/inside")` row is now covered by #8655. The PR adds `ELOOP` handling for failed opens when a path resolves through the self-link and tests both the kernel API result and POSIX `open` errno. Its author reports the focused Windows CTest selection passing 75/75; hosted platform build jobs were skipped. The other rows in this issue remain separate.
Sign in to join this conversation.
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5#6983
No description provided.