fix(libkernel): fail mutex and rwlock setname_np with EFAULT on an unusable pointer #17222
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/17222"
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:14:10Z.
What
pthread_mutex_setname_npandpthread_rwlock_setname_npread the guest mutex or lock pointer and the guestnamestring without checking them, so an unusable pointer such as0x10or an unreadable page crashed the host (std::stringwas built straight from the rawname). The console passes both to the module and the kernel, which fault on a bad pointer, so there is no measured error to copy; this is a host-safety fallback, as for the mergedpthread_barrier_setname_np. A mutex or lock pointer that cannot be read now returnsEFAULT(14) withGuestCopyIn_nid_no_patch, and the name is read withCopyGuestString_nid_no_patchand a 1024-byte bound (the boundpthread_barrier_setname_npuses): an unreadable or unterminated-at-a-page-edgenamegivesEFAULTand anameof 1024 bytes or more givesENAMETOOLONG(63). The existing order is kept: theEAGAINfor an already named object and, for a lock, theEINVALfor a nullnamecome before the name is read, a null mutexnamestill returns 0 and leaves it unnamed, and null, statically initialized and destroyed objects still throw. The new debt entry records that theEFAULTand the bound are unmeasured.Tested
Windows 11 (10.0.26200), WinLibs MinGW-w64 GCC 15.2.0 r7, Ninja, Release,
-DBUILD_TESTING=ON, onmainf5fe807353.guest_pthread_setname: new checks for the mutex and lock pointers0x10and an unreadable page, and for anameof0x10, an unreadable page and 8 bytes ending at a page edge without a terminator (EFAULT, the object stays unnamed), a 1024-byte name (ENAMETOOLONG), a null mutex name (0, unnamed) and a name that ends exactly at the page edge (0, stored). WithPthread/src/Mutex.cppandPthread/src/Rwlock.cppreverted tomainthe test crashes (SegFault); with this change it passes, three runs out of three.python tools/check_conventions.py --base upstream/main: passes.Overlaps
pr_overlap.pylists #13582, #15524, #15567, #17212, #17216 and #17220, and each row isdocs/dev/debt/libkernel.mdat the same appended place as this PR's entry, which keeps both lines.pthread_suspend_np) and #12642 (pthread_suspend_all_np) conflict withmainthemselves, sopr_overlap.pydid not compare them; their hunks inPthread/src/Mutex.cppare inTimedlockandscePthreadMutexLock, away frompthread_mutex_setname_npat the end of the file and from the constants this PR adds at the top.Posix/Rwlock.cpp, notsrc/Rwlock.cpp, so the hunks do not touch.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:47Z.
Review: CHANGES_REQUESTED
Finding (Blocking)
core/libs/tests/ProbeFault.cppappears to have been committed inadvertently:0x10calls.CMakeLists.txtor mentioned in the PR description.git diff --check upstream/main...HEADdue to trailing whitespace on every line.Please remove
core/libs/tests/ProbeFault.cppfrom the commit.Code & Tests Verification
The changes in
Mutex.cpp,Rwlock.cpp, andGuestPthreadSetname.cppare sound:ENAMETOOLONG), page boundary termination, and bad pointer detection (EFAULT) are cleanly implemented viaCopyGuestString_nid_no_patchandGuestCopyIn_nid_no_patch.🤖 Generated with [Claude Code]footer below the checklist; the AI-assisted checkbox can stay.Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-12T06:09:45Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
0e9b4a0e4c:tools/check_conventions.pypassed;git diff --checkclean.guest_pthread_setname_testsbuilt cleanly.guest_pthread_setname):core/libs/prx/libkernel/Pthread/src/Mutex.cpp,core/libs/prx/libkernel/Pthread/src/Rwlock.cppreverted tomainand the new tests kept, the suite fails: Restoring the change makes it pass again.Generated withfooter from the description; the AI-assisted checkbox can stay.Looks Good To Me