Skip to content

fix(libkernel): fail scePthreadGetname and pthread_getname_np with EFAULT on an unwritable buffer - #15571

Merged
oneandonlydean merged 2 commits into
boykopovar:mainfrom
Gruzzberry:fix/pthread-getname-efault
Nov 13, 2026
Merged

oneandonlydean merged 2 commits into
boykopovar:mainfrom
Gruzzberry:fix/pthread-getname-efault

Conversation

@Gruzzberry

Copy link
Copy Markdown
Contributor

What

scePthreadGetname and pthread_getname_np wrote the thread name and its terminator to the guest buffer with a raw memcpy, so a non-null buffer that is not writable, such as 0x10, a PROT_NONE page, a read-only page or one that runs out before the terminator, faulted the host. scePthreadGetname now builds the name (at most 31 characters and the terminator) in a local buffer, releases the thread's name lock, and writes it with GuestCopyOut_nid_no_patch, returning SCE_KERNEL_ERROR_EFAULT when the write fails; pthread_getname_np returns 14.

The order of the checks is unchanged: scePthreadGetname gives EINVAL for a null thread or buffer and ESRCH for an unknown handle before it touches the buffer, and pthread_getname_np still gives ESRCH for a null or joined thread and EFAULT for 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: EFAULT for a non-null bad buffer was not measured on a console, and FreeBSD 11.4's libthr has no pthread_get_name_np to take the order from. The entry is in docs/dev/debt/libkernel.md.

Tested

Windows 11 (10.0.26200), WinLibs MinGW-w64 GCC 15.2.0 r7, Ninja, Release, -DBUILD_TESTING=ON, on current main (rebased after the full suite onto 130 newer commits, one of which adds 6 lines elsewhere in Pthread/src/Thread.cpp; guest_pthread_getname was rerun 3 times out of 3 on the rebased head).

  • guest_pthread_getname: new CheckUnusableBuffers covers a buffer at 0x10, on a PROT_NONE page, on a read-only page, and one byte short of the 5 bytes kept needs before an unreadable page (EFAULT from both functions, also for a joined thread through scePthreadGetname); the earlier checks winning over a bad buffer (ESRCH for a null thread, a joined thread and an unknown handle; EINVAL for a null thread with scePthreadGetname); a buffer that ends exactly at the unreadable page (written, nothing before it disturbed); and a null buffer (EINVAL). On main the test crashes; with this change it passes, three runs out of three. The existing name, joined-thread and null-buffer cases still pass.
  • Full suite (3924 tests) on this branch: 98 failed, the same set as on the scePthreadRename branch (fix(libkernel): fail pthread_rename_np and scePthreadRename with EFAULT on an unreadable name #15567). 95 are the relinker and ELF tool tests that main gained recently, whose Python driver cannot start the relinker executable, which is not in this build tree; vulkan_validation_gate_reports and check_compile_test_windows_gcc_response_text_mode_is_not_reinterpreted fail because of the WindowsApps Python on this machine; agc_driver_store_over_untracked and agc_driver_direct_write_completion are GPU tests that also fail with the thread code reverted to main. Nothing thread related fails.
  • python tools/check_conventions.py --base upstream/main: passes.
  • Not tested: Linux, macOS, a console, a title run.

Overlaps

tools/pr_overlap.py reports no conflicting file or export. It lists #3986, #4563, #8592, #12130 and #12642 as sharing Thread.cpp without comparing them, because those PRs conflict with main themselves; none of their diffs changes scePthreadGetname (#12130 and #12642 only call it in new tests with a valid buffer, which still works). My own #15567 changes scePthreadRename in the same file, a different function, and appends its own entry to docs/dev/debt/libkernel.md; the two entries are adjacent lines. #15567 was opened first, so it goes first and this PR rebases.

Checklist

AI-assisted (Claude Code).

🤖 Generated with Claude Code

@Gruzzberry

Copy link
Copy Markdown
Contributor Author

Rebased onto main f79ea3f893 (now 19f33b39d7). The only conflict was the end of docs/dev/debt/libkernel.md, where main added an entry; both entries are kept. guest_pthread_getname passes three runs out of three and check_conventions.py passes.

@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Nov 6, 2026
@github-actions

github-actions Bot commented Nov 7, 2026 •

Copy link
Copy Markdown

Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
PR 18547 core/libs/tests/GuestPthreadGetname.cpp L3, L10, L35

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 4563 core/libs/prx/libkernel/Pthread/src/Thread.cpp
PR 6149 docs/dev/debt/libkernel.md
PR 6936 docs/dev/debt/libkernel.md
PR 7121 docs/dev/debt/libkernel.md
PR 7149 core/libs/prx/libkernel/Pthread/src/Thread.cpp
docs/dev/debt/libkernel.md
PR 7447 docs/dev/debt/libkernel.md
PR 8592 core/libs/prx/libkernel/Pthread/src/Thread.cpp
PR 9156 docs/dev/debt/libkernel.md
PR 9293 docs/dev/debt/libkernel.md
PR 9297 docs/dev/debt/libkernel.md
PR 9302 docs/dev/debt/libkernel.md
PR 9389 docs/dev/debt/libkernel.md
PR 9557 docs/dev/debt/libkernel.md
PR 9566 docs/dev/debt/libkernel.md
PR 9938 core/libs/prx/libkernel/Pthread/src/Thread.cpp
docs/dev/debt/libkernel.md
PR 10442 docs/dev/debt/libkernel.md
PR 11215 docs/dev/debt/libkernel.md
PR 11628 docs/dev/debt/libkernel.md
PR 11661 docs/dev/debt/libkernel.md
PR 11689 docs/dev/debt/libkernel.md
PR 11698 docs/dev/debt/libkernel.md
PR 11896 docs/dev/debt/libkernel.md
PR 12642 core/libs/prx/libkernel/Pthread/src/Thread.cpp
PR 12682 core/libs/prx/libkernel/Pthread/src/Thread.cpp
docs/dev/debt/libkernel.md
PR 12688 core/libs/prx/libkernel/Pthread/src/Thread.cpp
docs/dev/debt/libkernel.md
PR 12700 core/libs/prx/libkernel/Pthread/src/Thread.cpp
docs/dev/debt/libkernel.md
PR 12965 core/libs/prx/libkernel/Pthread/src/Thread.cpp
docs/dev/debt/libkernel.md
PR 14108 docs/dev/debt/libkernel.md
PR 15040 core/libs/prx/libkernel/Pthread/src/Thread.cpp
docs/dev/debt/libkernel.md
PR 17551 docs/dev/debt/libkernel.md
PR 17609 docs/dev/debt/libkernel.md
PR 17638 docs/dev/debt/libkernel.md
PR 17958 docs/dev/debt/libkernel.md
PR 18515 docs/dev/debt/libkernel.md

@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Nov 7, 2026
@oneandonlydean oneandonlydean self-assigned this Nov 7, 2026
@oneandonlydean

Copy link
Copy Markdown
Collaborator

Hi @Gruzzberry,

Main moved and the branch conflicted in docs/dev/debt/libkernel.md, so we merged current main into it (3bd7e73). Both debt entries are kept, and your code and tests are untouched. Windows CI is running again on the new head. Thanks for the change.

@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Nov 7, 2026
@JJenkx

JJenkx commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

Windows check of head 3bd7e73634, merged onto main 4ab649f4d8 (4e7dcf31c8, clean merge).

Setup: Windows 11 Enterprise 22621, WinLibs GCC 15.2 UCRT, Release. The hosted Windows check does not run these tests on pull requests.

  • guest_pthread_getname passes in 3 of 3 runs, none skipped.

AI-assisted: yes.

…AULT on an unwritable buffer

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@oneandonlydean
oneandonlydean merged commit aa5f2b5 into boykopovar:main Nov 13, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants