Skip to content

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

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
milescoviello:fix/kernel-stat-null-buffer
Oct 14, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
milescoviello:fix/kernel-stat-null-buffer

Conversation

@milescoviello

@milescoviello milescoviello commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

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 dacd785, 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

Crimson Desert (PPSA25286) calls sceKernelStat with a null buffer at
start-up, and main throws "sceKernelStat: sb is null", which ends the
title in its first second.

FreeBSD 11.4 looks the path up first and only then copies the result
out, so a null buffer gets EFAULT for a path that exists and the lookup
error for one that does not (sys/kern/vfs_syscalls.c, sys_stat):

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

sceKernelStat now does the same: the lookup and its errors are as
before, and a null buffer returns SCE_KERNEL_ERROR_EFAULT where the
status would be copied.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

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

@xXPBSXx

xXPBSXx commented Oct 14, 2026

Copy link
Copy Markdown
Contributor

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

Copy link
Copy Markdown
Contributor Author

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

AI-assisted: yes

@oneandonlydean
oneandonlydean merged commit 979a4b9 into boykopovar:main Oct 14, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants