Skip to content

fix(libkernel): answer scePthreadGetname with ESRCH for a null thread and EFAULT for a null buffer as the console does - #2003

Open
Thimo188 wants to merge 3 commits into
mainfrom
upstream-pr/28210
Open

Thimo188 wants to merge 3 commits into
mainfrom
upstream-pr/28210

Conversation

@Thimo188

@Thimo188 Thimo188 commented Dec 2, 2026 •

Copy link
Copy Markdown
Owner

Imported from boykopovar/AnyPS5#28210, originally opened by xXPBSXx.

Source commit: 91876d5c22bc5e5a2728dfcb7d988789c23ebbcd. The import branch preserves this fetched upstream PR snapshot. The description and validation below are copied from upstream; no new code changes or test runs were made for this import. Original reviews, discussions, and attachments remain at the linked upstream PR.


What

scePthreadGetname answered a null thread and a null buffer with SCE_KERNEL_ERROR_EINVAL (core/libs/prx/libkernel/Pthread/src/Thread.cpp:1646 on the base ffc6f26b0786). A PS5 (firmware 11.60, payload process; a title process may differ) returned 0x80020003 (ESRCH) for a null thread and 0x8002000e (EFAULT, errno 14) for a null buffer, in two runs whose outputs are equal line for line except the PROBE line (cases e.1 and e.2, lines 14 and 15 of the raw output in the first comment). On the same console pthread_getname_np returned 3 for a null thread and 14 for a null buffer (cases e.3 and e.4, lines 16 and 17), and pthread_getname_np_nid_postfix here already answers those two cases that way (core/libs/prx/libkernel/Pthread/Posix/Thread.cpp:488 and :489 on the base).

The fix commit (0b4a4c6fd9c, Thread.cpp, 2 lines added and 1 removed) answers a null thread with SCE_KERNEL_ERROR_ESRCH and, after it, a null buffer with SCE_KERNEL_ERROR_EFAULT (Thread.cpp:1646 and :1647); a thread that is not null is handled as before. The test commit (db305311061, GuestPthreadGetname.cpp, 2 lines added and 2 removed) expects ESRCH and EFAULT where it expected EINVAL (GuestPthreadGetname.cpp:62 and :70). The debt commit (91876d5c22b, fix-libkernel-getname-null-console.md, 5 lines added and 0 removed) adds the fragment that changes the entry scePthreadGetname, pthread_getname_np buffer to the measured results; the entry is 902 characters with its list marker.

Not measured and not claimed: the order of the checks when the thread and the buffer are both null (here the thread is checked first; neither order was measured), a title process, and a partial write before a failure. 39 of 56 local title run folders import scePthreadGetname, in the executable or in a bundled module (3 of them in the executable itself), and 1 imports pthread_getname_np; an import is not a call, so title use is not established. Counted on 2026-11-29 at 03:56 UTC from the import registries in the newest local run folder of each of the 56 titles.

Tested

Windows 10 Pro (10.0.19045), MinGW-W64 GCC 15.2.0 (WinLibs), CMake with Ninja, Release, BUILD_TESTING=ON, ccache, one machine, both arms on main ffc6f26. Red: with the test commit alone (db30531), guest_pthread_getname_tests ended with FATAL: abort() (SIGABRT) (exit 127). Green: with the fix and the debt commit (91876d5c22bc, the head of this branch) the same test returned 0 in three of three runs. The five neighbouring tests guest_pthread_handle_after_exit_tests, guest_pthread_rename_tests, guest_kernel_sys_thread_defaults_tests, guest_pthread_second_join_tests and guest_posix_thread_name_tests returned 0 in both arms. The red arm ran once (the abort comes from the two changed Require lines). Against a fresh main ea39f12 (fetched on 2026-11-29): tools/debt_fold.py --check exits with 0; tools/check_conventions.py --base upstream/main reports no findings; git merge-tree of the head with that main is clean. The builds ran on main ffc6f26, not on ea39f12. Not tested: other operating systems, a run of this code on a PS5, a title.

Overlap: counted on 2026-11-29 from the 2133 open pull requests (file lists from the GitHub API, the pull requests with 100 or more files read in full through the files API; the 1345 pull requests that change a file under docs/dev/debt/, core/libs/prx/libkernel/Pthread/, GuestPthreadGetname.cpp or libkernel.md, or have pthread, getname, thread name or libkernel in the title or branch name, had their patches of the files under docs/dev/debt/ and of the files with libkernel or Pthread in the path searched for scePthreadGetname, pthread_getname_np, PthreadGetname, the fragment name and the text getname, from 04:10 to 05:40 UTC, main at ea39f127f401 at the start). No open pull request changes the fragment docs/dev/debt/changes/fix-libkernel-getname-null-console.md or the entry scePthreadGetname, pthread_getname_np buffer at docs/dev/debt/libkernel.md:445, and of the 175 commits on main since ffc6f26b0786 (the base of this branch; up to 859a238b8c73) only one, boykopovar#27554, changed a file under core/libs/prx/libkernel/Pthread/ (Posix/Sem.cpp); none changed Pthread/src/Thread.cpp, core/libs/tests/GuestPthreadGetname.cpp or libkernel.md. 24 of the open pull requests change a file named Thread.cpp or the test file GuestPthreadGetname.cpp: 8 of them merge cleanly with this head, and the other 16 conflict with main alone in as many files, so none because of this change. boykopovar#21571 (fix(libkernel): look the thread up before the name in pthread renames) is the closest: it changes scePthreadRename in the same Thread.cpp (a hunk at about line 1608; this change is at :1646 and :1647), the rename checks in GuestPthreadGetname.cpp (about line 81; this change is at :62 and :70) and its own fragment, which has other entries; it merges cleanly with this head. boykopovar#18190 (feat(libs): mirror libkernel exports through libkernel_sys) adds scePthreadGetname_nid_no_patch to provider files and removes pthread_getname_np_nid_postfix from Posix/Thread.cpp, the function whose lines :488 and :489 this text cites for the base; it conflicts with this head in 1 file and with main alone in 1 file, so not because of this change, and boykopovar#18112 (... libkernel_web) only declares pthread_getname_np_nid_no_patch and merges cleanly. Other patches only call the functions: boykopovar#21464, boykopovar#12642 and boykopovar#12130 (scePthreadGetname in GuestPthreadSuspend.cpp) and boykopovar#28064 and boykopovar#23953 (pthread_getname_np_nid_postfix in tests); the other hits of getname are other functions (getnameinfo, ucnv_getName, uloc_getName, getNamedItem, GetNamedPipeHandleState and similar). The merges of this head with each of the 95 pull requests that change a file under core/libs/prx/libkernel/Pthread/, GuestPthreadGetname.cpp or libkernel.md or have a searched name were made with git merge-tree from 04:10 to 05:40 UTC: 42 are clean; the other 53 already conflict with main alone, in at least as many files as with this head, so none of them conflicts because of this change. The count was repeated for the 36 pull requests that were opened or updated since 04:10 UTC (of the 2135 open pull requests, from 06:08 to 06:11 UTC; 29 of them were patch-scanned for the same names): one hit, boykopovar#21464 (a call of scePthreadGetname), which now merges cleanly with this head. A merge of this head into main at 859a238b8c73 was checked at 06:09 UTC and is clean. This pull request does not depend on any of them (Depends on: none).

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt and the licence notice of code adapted from upstream (see AGENTS.md)
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a (no graphics change)
  • AI-assisted: yes

Summary by CodeRabbit

  • Bug Fixes
    • Thread-name lookup now returns the appropriate error when the thread is missing or the output buffer is null, rather than using the same generic error for both cases.
    • Lookup behavior and copying the thread name to a valid buffer remain unchanged.

xXPBSXx and others added 3 commits November 29, 2026 02:52
…r a null thread and a null buffer

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
… and EFAULT for a null buffer as the console does

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…ead_getname_np for bad arguments

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Changes: Thread name error handling

Layer / File(s) Summary
Null-argument errors and validation
core/libs/prx/libkernel/Pthread/src/Thread.cpp, core/libs/tests/GuestPthreadGetname.cpp, docs/dev/debt/changes/fix-libkernel-getname-null-console.md
A null thread now returns SCE_KERNEL_ERROR_ESRCH, and a null name returns SCE_KERNEL_ERROR_EFAULT. The tests assert these results. The debt-change document records observed behavior and unmeasured cases.

Suggested reviewers: gruzzberry, milescoviello, boykopovar

Change: Bug fix

Merge Risk: Minimal · up to 91876

This change makes the thread-name API return distinct errors for a null thread and a null name, with tests and notes updated to match. No concrete merge-blocking risk was found.

Security architecture risk: Minimal · up to 91876

Direct scePthreadGetname callers receive more specific errors for null arguments. The POSIX wrapper already returns those errors, and the change does not give guests access to additional thread data or memory operations.

Security review details

Security Blast Radius

  • inferred — The new result distinguishes which guest-supplied argument is null without consulting the thread registry or touching guest memory. It does not expose new thread state or expand reachability into the copy-out path.

Trust Boundaries and Controls

  • observed — For non-null arguments, scePthreadGetname still checks thread registration before reading the name under its lock and uses the existing guest copy-out helper to write the bounded, null-terminated result.
Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Usage-based review receipt

  • Mode: Continue automatically
  • Reviewed files: 3
  • Waived: $0.75 (charged $0.00)
  • View usage details

Note

This review exceeded your plan’s limits and used usage-based reviews—free during trial, billed after paid activation unless disabled. Manage usage-based reviews.

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: a784c385-6e11-46b6-87a3-7a9af64571b5
Commits

Reviewing files that changed from the base of the PR and between 4131f51 and 91876d5.

Files selected for processing: 3

  • core/libs/prx/libkernel/Pthread/src/Thread.cpp
  • core/libs/tests/GuestPthreadGetname.cpp
  • docs/dev/debt/changes/fix-libkernel-getname-null-console.md

Limit details: You’ve used all 10 included reviews currently available.

@github-actions

github-actions Bot commented Dec 6, 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 1 docs/dev/debt/changes/fix-libkernel-getname-null-console.md
PR 4 docs/dev/debt/changes/fix-libkernel-getname-null-console.md
PR 5 docs/dev/debt/changes/fix-libkernel-getname-null-console.md
PR 6 docs/dev/debt/changes/fix-libkernel-getname-null-console.md
PR 7 docs/dev/debt/changes/fix-libkernel-getname-null-console.md
PR 8 docs/dev/debt/changes/fix-libkernel-getname-null-console.md
PR 9 docs/dev/debt/changes/fix-libkernel-getname-null-console.md
PR 10 docs/dev/debt/changes/fix-libkernel-getname-null-console.md
PR 11 docs/dev/debt/changes/fix-libkernel-getname-null-console.md
PR 12 docs/dev/debt/changes/fix-libkernel-getname-null-console.md
PR 13 docs/dev/debt/changes/fix-libkernel-getname-null-console.md
PR 14 docs/dev/debt/changes/fix-libkernel-getname-null-console.md
PR 15 docs/dev/debt/changes/fix-libkernel-getname-null-console.md
PR 16 docs/dev/debt/changes/fix-libkernel-getname-null-console.md
PR 17 docs/dev/debt/changes/fix-libkernel-getname-null-console.md
PR 18 docs/dev/debt/changes/fix-libkernel-getname-null-console.md
PR 19 docs/dev/debt/changes/fix-libkernel-getname-null-console.md
PR 20 docs/dev/debt/changes/fix-libkernel-getname-null-console.md

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants