fix(libkernel): fstat, stat, lstat, fstatfs and their sceKernel* forms crash on an output pointer into unmapped memory instead of failing with EFAULT #9617

Closed
opened 2026-10-22 04:39:14 +00:00 by xXPBSXx · 1 comment
xXPBSXx commented 2026-10-22 04:39:14 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-22T04:39:14Z.


A bad-pointer sweep over the libkernel exports (983 functions, pointer parameter replaced by 1 and 0xfffffffffffff000, one child process per call) found that fstat_nid_disambig1, _fstat, sceKernelFstat, stat, lstat, sceKernelStat and _fstatfs write the caller's struct without checking it, or check only for null (_fstatfs calls GuestArena::HostWrite::Open(), which returns true for any non-arena host pointer). They crash the host process (SIGSEGV on Linux, access violation on Windows). FreeBSD 11.4 returns EFAULT from copyout after the lookup succeeded: sys_fstat (sys/kern/kern_descrip.c:1328), sys_stat (sys/kern/vfs_syscalls.c:2066), sys_fstatfs (sys/kern/vfs_syscalls.c:337). This is the family of #8463 (sendmsg).

This issue covers only the stat family; other output-pointer families (getrlimit, getrusage, gettimeofday, getitimer, setitimer, pipe, getsockname) and the path-string arguments are separate topics.

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5973164082 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/9617). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-22T04:39:14Z. --- A bad-pointer sweep over the libkernel exports (983 functions, pointer parameter replaced by `1` and `0xfffffffffffff000`, one child process per call) found that `fstat_nid_disambig1`, `_fstat`, `sceKernelFstat`, `stat`, `lstat`, `sceKernelStat` and `_fstatfs` write the caller's struct without checking it, or check only for null (`_fstatfs` calls `GuestArena::HostWrite::Open()`, which returns true for any non-arena host pointer). They crash the host process (SIGSEGV on Linux, access violation on Windows). FreeBSD 11.4 returns EFAULT from `copyout` after the lookup succeeded: `sys_fstat` (sys/kern/kern_descrip.c:1328), `sys_stat` (sys/kern/vfs_syscalls.c:2066), `sys_fstatfs` (sys/kern/vfs_syscalls.c:337). This is the family of #8463 (`sendmsg`). This issue covers only the stat family; other output-pointer families (`getrlimit`, `getrusage`, `gettimeofday`, `getitimer`, `setitimer`, `pipe`, `getsockname`) and the path-string arguments are separate topics. AI-assisted (Claude Code).
MarcZX10 commented 2026-10-22 13:13:26 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T13:13:26Z.


The focused report is now covered by #9618, which adds regression cases for the stat-family wrappers and reports red/green runs on Windows and Linux. During review, I found the helper still falls through to unchecked memcpy on macOS/non-Windows/non-Linux hosts, and on Linux when process_vm_writev fails with an error other than EFAULT (for example, a seccomp EPERM). I requested fixes and read-only destination coverage on #9618. This issue should stay open until the merged implementation safely handles those supported-host paths as well.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6341641838 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/9617#issuecomment-6341641838). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-22T13:13:26Z. --- The focused report is now covered by #9618, which adds regression cases for the stat-family wrappers and reports red/green runs on Windows and Linux. During review, I found the helper still falls through to unchecked `memcpy` on macOS/non-Windows/non-Linux hosts, and on Linux when `process_vm_writev` fails with an error other than `EFAULT` (for example, a seccomp `EPERM`). I requested fixes and read-only destination coverage on #9618. This issue should stay open until the merged implementation safely handles those supported-host paths as well.
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#9617
No description provided.