fix(libkernel): fail condition variable init, destroy and setname with EFAULT on an unusable pointer #17220
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/17220"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by Gruzzberry on 2026-11-08T15:03:01Z.
What
pthread_cond_init,pthread_cond_destroy,pthread_cond_setname_np,scePthreadCondInitandscePthreadCondDestroyread and wrote the guest condition variable pointer, and the init calls also read the guest attribute pointer, without checking them, so an unusable pointer such as0x10or a read-only page crashed the host. FreeBSD 11.4's_pthread_cond_initand_pthread_cond_destroystore through the pointer the same way and the process faults, so libthr has no error to copy here; this is a host-safety fallback, andpthread_cond_setname_nphas no libthr counterpart. A condition variable pointer that cannot be read, or cannot be written where the call stores, now returnsEFAULT(SCE_KERNEL_ERROR_EFAULTfrom thescecalls), as does an attribute pointer that cannot be read, usingGuestCopyIn_nid_no_patchandGuestCopyOut_nid_no_patch. Destroy reads the slot first and writes only where it stores, so theEINVALfor a destroyed condition variable and the 0 for a null static initializer are unchanged even in a read-only page; setname writes only when it creates the condition variable for a null slot. A null condition variable pointer keeps throwing (orEINVALfrompthread_cond_setname_np) and a null attribute still means the default.pthread_cond_signal,broadcast,wait,timedwaitandscePthreadCondSignaltoare untouched: they are hot paths and a copy helper would cost them on every call. The new debt entry records that theEFAULTis unmeasured.Tested
Windows 11 (10.0.26200), WinLibs MinGW-w64 GCC 15.2.0 r7, Ninja, Release,
-DBUILD_TESTING=ON, onmainf5fe807353.guest_pthread_cond_setname: new checks for the condition variable pointer0x10, a read-only page and an unreadable page (EFAULTfrompthread_cond_init,pthread_cond_setname_npand, for0x10and the unreadable page,pthread_cond_destroy;SCE_KERNEL_ERROR_EFAULTfromscePthreadCondInitandscePthreadCondDestroy;pthread_cond_destroyof the zeroed read-only page gives 0), an attribute pointer0x10and an unreadable page (EFAULTfrom both init calls, the slot stays null), and the success path afterwards. WithPthread/src/Cond.cppreverted tomainthe test crashes (SegFault); with this change it passes, three runs out of three.guest_pthread_cond,guest_pthread_condattr,guest_cond_timedwait,guest_cond_unowned_mutex,guest_cond_recursive_mutex,guest_posix_cond_broadcast,guest_pthread_cancel,guest_pthread_cancel_recovery,guest_pthread_destroyed_objectsand the coarse variants) pass.python tools/check_conventions.py --base upstream/main: passes.Overlaps
pr_overlap.pylists #13582, #15524, #15567, #17212 and #17216, and every row isdocs/dev/debt/libkernel.mdat the same appended place as this PR's entry, which keeps both lines; no other PR touchesPthread/src/Cond.cpporGuestPthreadCondSetname.cpp.Checklist
main; no other open PR implements the same functionNotImplemented_nid_no_patch); no silent stubs added.mdfiles or images added to the repositoryAI-assisted (Claude Code).
🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-08T15:34:36Z.
Review: APPROVED
What I ran
53feebc4c79805d76d4948a3d5ec7b653457a3e3f5fe8073533b671946ab8999ebbee85f4f78c597(merges cleanly with currentmain).Tools and Checks
python tools/check_conventions.py --base upstream/main --head pr-17220: 0 errors.git diff --check upstream/main...pr-17220: clean.Windows Test Suite & Negative Control
guest_pthread_cond_setnameguest_pthread_condguest_pthread_condattrguest_cond_timedwaitguest_cond_recursive_mutexguest_cond_unowned_mutexguest_posix_cond_broadcastcore/libs/prx/libkernel/Pthread/src/Cond.cppfrommainfailsguest_pthread_cond_setnamewithSIGSEGVonwrite of 0x0000000000000010(0xc0000005). With this PR, all invalid slot and attribute checks cleanly returnEFAULT/SCE_KERNEL_ERROR_EFAULT.std::unique_ptrrelease is guarded by successfulGuestCopyOut_nid_no_patch, preventing leaks on write failures. InscePthreadCondDestroy, the handle is deleted only ifGuestCopyOutsuccessfully overwrote the slot withdestroyedCond(), avoiding dangling pointers in the guest address space.Please remove the generated attribution footer below the checklist; the AI-assisted checkbox can stay.
Looks Good To Me