libkernel: ksem_getvalue faults on invalid memory pointers instead of returning EFAULT #13951

Closed
opened 2026-10-31 13:45:34 +00:00 by pushkarreddyy · 0 comments
pushkarreddyy commented 2026-10-31 13:45:34 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by pushkarreddyy on 2026-10-31T13:45:34Z.


What happens

ksem_getvalue (core/libs/prx/libkernel/Semaphore/src/Ksem.cpp:150) crashes the host process with SIGSEGV when passed an invalid or unwritable guest memory pointer (such as reinterpret_cast<int*>(0x10)).

In FreeBSD, ksem_getvalue is backed by sys_ksem_getvalue (sys/kern/uipc_sem.c), which safely writes to user-space memory via copyout, returning EFAULT (errno 14) when the memory is unmapped or unwritable. In AnyPS5, ksem_getvalue_nid_postfix directly assigned to *value without checking destination writability via GuestCopyOut_nid_no_patch.

Title, test or build step

core/libs/tests/GuestKernelSysKsem.cpp

AnyPS5 commit

origin/main at 828ac0b2ae

System

Windows 11 / Linux x86_64, GCC 15.2.0, Release

Steps to reproduce

Call ksem_getvalue_nid_postfix(id, reinterpret_cast<int*>(0x10)).

Log

***Exception: SegFault
FATAL: abort() (SIGSEGV) on thread

What was checked

Verified on unmodified origin/main that passing 0x10 crashes with SIGSEGV. With GuestCopyOut_nid_no_patch, the call safely returns -1 with errno == GuestEfault (14).

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:6135491871 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/13951). Originally posted by [pushkarreddyy](https://github.com/pushkarreddyy) on 2026-10-31T13:45:34Z. --- ### What happens `ksem_getvalue` (`core/libs/prx/libkernel/Semaphore/src/Ksem.cpp:150`) crashes the host process with `SIGSEGV` when passed an invalid or unwritable guest memory pointer (such as `reinterpret_cast<int*>(0x10)`). In FreeBSD, `ksem_getvalue` is backed by `sys_ksem_getvalue` (`sys/kern/uipc_sem.c`), which safely writes to user-space memory via `copyout`, returning `EFAULT` (errno 14) when the memory is unmapped or unwritable. In AnyPS5, `ksem_getvalue_nid_postfix` directly assigned to `*value` without checking destination writability via `GuestCopyOut_nid_no_patch`. ### Title, test or build step `core/libs/tests/GuestKernelSysKsem.cpp` ### AnyPS5 commit `origin/main` at `828ac0b2ae` ### System Windows 11 / Linux x86_64, GCC 15.2.0, Release ### Steps to reproduce Call `ksem_getvalue_nid_postfix(id, reinterpret_cast<int*>(0x10))`. ### Log ``` ***Exception: SegFault FATAL: abort() (SIGSEGV) on thread ``` ### What was checked Verified on unmodified `origin/main` that passing `0x10` crashes with `SIGSEGV`. With `GuestCopyOut_nid_no_patch`, the call safely returns `-1` with `errno == GuestEfault` (14).
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#13951
No description provided.