fix(libkernel): fail sceKernelStat with EFAULT for a null buffer #5464

Merged
milescoviello merged 1 commit from upstream-pr/5464 into main 2026-10-14 01:24:25 +00:00
milescoviello commented 2026-10-13 20:21:11 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-13T20:21:11Z.


What

Crimson Desert (PPSA25286) calls sceKernelStat with a null buffer at start-up. On main that throws and ends the title in its first second:

[src/Open.cpp:207 sceKernelOpen] path=/temp0/Pearl Abyss/log flags=0x20000 nativeFlags=0x10000 mode=00
[libc] unhandled exception 'St16invalid_argument' thrown from 0x...
terminate called after throwing an instance of 'std::invalid_argument'
  what():  sceKernelStat: sb is null

FreeBSD 11.4 looks the path up first and only then copies the result out (sys_stat, sys/kern/vfs_syscalls.c):

	error = kern_statat(td, 0, AT_FDCWD, uap->path, UIO_USERSPACE,
	    &sb, NULL);
	if (error == 0)
		error = copyout(&sb, uap->ub, sizeof (sb));

So a null buffer gets EFAULT for a path that exists, and the lookup's own error for one that does not. sceKernelStat now does the same: the lookup and its errors are unchanged, and a null buffer returns SCE_KERNEL_ERROR_EFAULT where the status would be copied. stat already returns EFAULT for a null buffer before it calls sceKernelStat, so it is unaffected.

guest_filesystem gains two checks: sceKernelStat with a null buffer gets 0x80020002 for a missing path and 0x8002000E for ..

#4938 also rewrites the end of sceKernelStat (one host query instead of several) and keeps the null-buffer throw. The two do not depend on each other, and whichever lands second needs a small rebase.

Tested

Ubuntu 24.04, GCC 13.3 (CI's compiler), Release with CI's configure flags, on main dacd78525, RTX 4070 Ti (NVIDIA 580.142):

  • With main's Open.cpp and the new checks, guest_filesystem throws sceKernelStat: sb is null; with the change it passes 20/20.
  • All 342 guest_* tests pass in two runs.
  • Crimson Desert (PPSA25286), relinked with --to-intel and run on Linux:
    • On main it stops at 0 s with the lines above.
    • With this change it gets past the call and stops at its next missing function, sceHttp2SendRequestAsync not implemented, a separate gap.
  • tools/check_conventions.py --base upstream/main passes.
  • @xXPBSXx ran it on Windows: Windows 10 (19045), MinGW-w64 GCC 15.2.0, Release, this PR (eb78c6a45) merged onto main ce5c83953. guest_filesystem passes; with main's Open.cpp and the new checks it fails with an unhandled std::invalid_argument (0xc0000409).

Not checked on a console.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Unblocks: none
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4848986703 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5464). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-10-13T20:21:11Z. --- ### What Crimson Desert (PPSA25286) calls `sceKernelStat` with a null buffer at start-up. On `main` that throws and ends the title in its first second: ``` [src/Open.cpp:207 sceKernelOpen] path=/temp0/Pearl Abyss/log flags=0x20000 nativeFlags=0x10000 mode=00 [libc] unhandled exception 'St16invalid_argument' thrown from 0x... terminate called after throwing an instance of 'std::invalid_argument' what(): sceKernelStat: sb is null ``` FreeBSD 11.4 looks the path up first and only then copies the result out ([`sys_stat`, `sys/kern/vfs_syscalls.c`](https://github.com/freebsd/freebsd-src/blob/releng/11.4/sys/kern/vfs_syscalls.c#L1978-L1988)): ```c error = kern_statat(td, 0, AT_FDCWD, uap->path, UIO_USERSPACE, &sb, NULL); if (error == 0) error = copyout(&sb, uap->ub, sizeof (sb)); ``` So a null buffer gets `EFAULT` for a path that exists, and the lookup's own error for one that does not. `sceKernelStat` now does the same: the lookup and its errors are unchanged, and a null buffer returns `SCE_KERNEL_ERROR_EFAULT` where the status would be copied. `stat` already returns `EFAULT` for a null buffer before it calls `sceKernelStat`, so it is unaffected. `guest_filesystem` gains two checks: `sceKernelStat` with a null buffer gets `0x80020002` for a missing path and `0x8002000E` for `.`. #4938 also rewrites the end of `sceKernelStat` (one host query instead of several) and keeps the null-buffer throw. The two do not depend on each other, and whichever lands second needs a small rebase. ### Tested Ubuntu 24.04, GCC 13.3 (CI's compiler), Release with CI's configure flags, on `main` dacd78525, RTX 4070 Ti (NVIDIA 580.142): - With `main`'s `Open.cpp` and the new checks, `guest_filesystem` throws `sceKernelStat: sb is null`; with the change it passes 20/20. - All 342 `guest_*` tests pass in two runs. - Crimson Desert (PPSA25286), relinked with `--to-intel` and run on Linux: - On `main` it stops at 0 s with the lines above. - With this change it gets past the call and stops at its next missing function, `sceHttp2SendRequestAsync not implemented`, a separate gap. - `tools/check_conventions.py --base upstream/main` passes. - @xXPBSXx [ran it on Windows](https://github.com/boykopovar/AnyPS5/pull/5464#issuecomment-6158394490): Windows 10 (19045), MinGW-w64 GCC 15.2.0, Release, this PR (`eb78c6a45`) merged onto `main` `ce5c83953`. `guest_filesystem` passes; with `main`'s `Open.cpp` and the new checks it fails with an unhandled `std::invalid_argument` (`0xc0000409`). Not checked on a console. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Unblocks: none - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
github-actions[bot] commented 2026-10-13 20:32:25 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-13T20:32:25Z.


Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
#4938 core/libs/prx/libkernel/File/src/Open.cpp L301-313
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6154625892 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5464#issuecomment-6154625892). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-13T20:32:25Z. --- <!-- pr-overlap --> Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in **Depends on**. | Pull request | Conflicting files (lines on `main`) | Same exports | Same new files | |---|---|---|---| | #4938 | `core/libs/prx/libkernel/File/src/Open.cpp` [L301-313](https://github.com/boykopovar/AnyPS5/blob/ee9037d85154d0c840517c46c61087a736fe0641/core/libs/prx/libkernel/File/src/Open.cpp#L301-L313) | | |
xXPBSXx commented 2026-10-14 00:51:49 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-14T00:51:49Z.


Windows 10 (19045), MinGW-w64 GCC 15.2.0, Release, -j4: head eb78c6a45 of this PR merged onto main ce5c83953 (clean merge, 2 files).

  • guest_filesystem passes (0.82 s, ctest).
  • With core/libs/prx/libkernel/File/src/Open.cpp taken back to main and the PR's new test lines kept, guest_filesystem fails ([libc] unhandled exception 'St16invalid_argument', exit code 0xc0000409).
  • Not run: Linux, a console, a title.

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6158394490 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5464#issuecomment-6158394490). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-14T00:51:49Z. --- Windows 10 (19045), MinGW-w64 GCC 15.2.0, Release, `-j4`: head `eb78c6a45` of this PR merged onto `main` `ce5c83953` (clean merge, 2 files). - `guest_filesystem` passes (0.82 s, ctest). - With `core/libs/prx/libkernel/File/src/Open.cpp` taken back to `main` and the PR's new test lines kept, `guest_filesystem` fails (`[libc] unhandled exception 'St16invalid_argument'`, exit code `0xc0000409`). - Not run: Linux, a console, a title. AI-assisted (Claude Code).
milescoviello commented 2026-10-14 00:52:24 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-14T00:52:24Z.


Thanks, @xXPBSXx. That covers Windows, including the failing run without the change. I've added it to the description.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6158401292 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5464#issuecomment-6158401292). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-10-14T00:52:24Z. --- Thanks, @xXPBSXx. That covers Windows, including the failing run without the change. I've added it to the description. AI-assisted: yes
Sign in to join this conversation.
No reviewers
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!5464
No description provided.