fix(libkernel): fail scePthreadGetname and pthread_getname_np with EFAULT on an unwritable buffer #15571
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/15571"
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-03T19:19:34Z.
What
scePthreadGetnameandpthread_getname_npwrote the thread name and its terminator to the guest buffer with a rawmemcpy, so a non-null buffer that is not writable, such as 0x10, aPROT_NONEpage, a read-only page or one that runs out before the terminator, faulted the host.scePthreadGetnamenow builds the name (at most 31 characters and the terminator) in a local buffer, releases the thread's name lock, and writes it withGuestCopyOut_nid_no_patch, returningSCE_KERNEL_ERROR_EFAULTwhen the write fails;pthread_getname_npreturns 14.The order of the checks is unchanged:
scePthreadGetnamegivesEINVALfor a null thread or buffer andESRCHfor an unknown handle before it touches the buffer, andpthread_getname_npstill givesESRCHfor a null or joined thread andEFAULTfor a null buffer (the existing measured behaviour), with the buffer untouched in those cases. A valid buffer receives the same bytes as before.This is a host-safety fix, not console behaviour:
EFAULTfor a non-null bad buffer was not measured on a console, and FreeBSD 11.4's libthr has nopthread_get_name_npto take the order from. The entry is indocs/dev/debt/libkernel.md.Tested
Windows 11 (10.0.26200), WinLibs MinGW-w64 GCC 15.2.0 r7, Ninja, Release,
-DBUILD_TESTING=ON, on currentmain(rebased after the full suite onto 130 newer commits, one of which adds 6 lines elsewhere inPthread/src/Thread.cpp;guest_pthread_getnamewas rerun 3 times out of 3 on the rebased head).guest_pthread_getname: newCheckUnusableBufferscovers a buffer at 0x10, on aPROT_NONEpage, on a read-only page, and one byte short of the 5 byteskeptneeds before an unreadable page (EFAULTfrom both functions, also for a joined thread throughscePthreadGetname); the earlier checks winning over a bad buffer (ESRCHfor a null thread, a joined thread and an unknown handle;EINVALfor a null thread withscePthreadGetname); a buffer that ends exactly at the unreadable page (written, nothing before it disturbed); and a null buffer (EINVAL). Onmainthe test crashes; with this change it passes, three runs out of three. The existing name, joined-thread and null-buffer cases still pass.scePthreadRenamebranch (#15567). 95 are the relinker and ELF tool tests that main gained recently, whose Python driver cannot start therelinkerexecutable, which is not in this build tree;vulkan_validation_gate_reportsandcheck_compile_test_windows_gcc_response_text_mode_is_not_reinterpretedfail because of the WindowsApps Python on this machine;agc_driver_store_over_untrackedandagc_driver_direct_write_completionare GPU tests that also fail with the thread code reverted tomain. Nothing thread related fails.python tools/check_conventions.py --base upstream/main: passes.Overlaps
tools/pr_overlap.pyreports no conflicting file or export. It lists #3986, #4563, #8592, #12130 and #12642 as sharingThread.cppwithout comparing them, because those PRs conflict withmainthemselves; none of their diffs changesscePthreadGetname(#12130 and #12642 only call it in new tests with a valid buffer, which still works). My own #15567 changesscePthreadRenamein the same file, a different function, and appends its own entry todocs/dev/debt/libkernel.md; the two entries are adjacent lines. #15567 was opened first, so it goes first and this PR rebases.Checklist
main; no other open PR implements the same functionNotImplemented_nid_no_patch); no silent stubs added.mdfiles or images added to the repositorydocs/dev/debt/libkernel.md)AI-assisted (Claude Code).
🤖 Generated with Claude Code