fix(libkernel): reject overlong POSIX thread names #2230

Merged
QRMOE merged 3 commits from upstream-pr/2230 into main 2026-10-10 08:01:28 +00:00
QRMOE commented 2026-10-09 12:30:50 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by QRMOE on 2026-10-09T12:30:50Z.


What

Rejects pthread_rename_np names of 32 bytes or more with guest ENAMETOOLONG (63), before changing the stored or native thread name. Names up to 31 bytes continue to succeed.

This matches the published PS5 firmware 13.60 probe and raw output: 31 bytes succeed; 32 and 40 bytes return 63 and preserve the previous 31-byte name. That measurement was made by the author of #1798, not locally for this PR. This fixes an existing export; no title-unblocking or new-export claim is made.

The dedicated test avoids changing GuestThreadSelf.cpp. Local merges with the inspected heads of #1798, #1739, #1676 and #2184 are clean. Actual library diffs of 522 open PR heads were inspected; no competing rename-length implementation was found. The latest additional PRs were checked before publication.

Tested

Windows 11, WinLibs MinGW-w64 GCC 15.2.0 UCRT/POSIX/SEH, Ninja Release, BUILD_TESTING=ON, ANYPS5_ENABLE_SPIRV_TOOLS=ON; based on main d70b89989473ba1f6ae13e44e079e67f1f8a44b0.

  • Complete project build, including patched libraries, passed.
  • Eight focused runtime tests passed: guest_pthread_rename, guest_thread_self, guest_pthread_attr, guest_kernel_errors, guest_errors, guest_thread_atexit, host_thread_local and guest_thread_callback_abi.
  • guest_pthread_rename checks empty, 1-, 11- and 31-byte names, rejects 32-, 40- and 1024-byte names, verifies the old name survives rejection, checks that a later valid rename succeeds, and checks output guards and errno preservation. It runs on both the adopted main thread and a created guest thread. Final runtime: 0.02 s.
  • The regression fails without the length check (32-byte name returned 0; expected ENAMETOOLONG=63). It also detects three deliberate faults: rejecting 31 bytes, returning EINVAL, and changing the name before reporting the error. The final source was restored and rebuilt afterward.
  • Conventions, whitespace and test registration checks passed.

Linux, a new console run, games and the full CTest suite have not been run. No new dependency, silent stub or code comment is added.

AI-assisted: yes — OpenAI Codex assisted with implementation, testing and this description.

Checklist

  • Based on current main; no competing rename-length implementation found in the inspected open PRs
  • One topic per PR
  • No new code comments
  • No new silent stubs or fallback behavior
  • Reports, logs and screenshots kept outside the repository
  • No new third-party dependencies
  • General behavior, not specific to one title
  • Depends on: none
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4800432575 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2230). Originally posted by [QRMOE](https://github.com/QRMOE) on 2026-10-09T12:30:50Z. --- ### What Rejects `pthread_rename_np` names of 32 bytes or more with guest `ENAMETOOLONG` (63), before changing the stored or native thread name. Names up to 31 bytes continue to succeed. This matches [the published PS5 firmware 13.60 probe and raw output](https://github.com/boykopovar/AnyPS5/pull/1798#issuecomment-6067446019): 31 bytes succeed; 32 and 40 bytes return 63 and preserve the previous 31-byte name. That measurement was made by the author of #1798, not locally for this PR. This fixes an existing export; no title-unblocking or new-export claim is made. The dedicated test avoids changing `GuestThreadSelf.cpp`. Local merges with the inspected heads of #1798, #1739, #1676 and #2184 are clean. Actual library diffs of 522 open PR heads were inspected; no competing rename-length implementation was found. The latest additional PRs were checked before publication. ### Tested Windows 11, WinLibs MinGW-w64 GCC 15.2.0 UCRT/POSIX/SEH, Ninja Release, `BUILD_TESTING=ON`, `ANYPS5_ENABLE_SPIRV_TOOLS=ON`; based on main `d70b89989473ba1f6ae13e44e079e67f1f8a44b0`. - Complete project build, including patched libraries, passed. - Eight focused runtime tests passed: `guest_pthread_rename`, `guest_thread_self`, `guest_pthread_attr`, `guest_kernel_errors`, `guest_errors`, `guest_thread_atexit`, `host_thread_local` and `guest_thread_callback_abi`. - `guest_pthread_rename` checks empty, 1-, 11- and 31-byte names, rejects 32-, 40- and 1024-byte names, verifies the old name survives rejection, checks that a later valid rename succeeds, and checks output guards and errno preservation. It runs on both the adopted main thread and a created guest thread. Final runtime: 0.02 s. - The regression fails without the length check (`32-byte name returned 0; expected ENAMETOOLONG=63`). It also detects three deliberate faults: rejecting 31 bytes, returning EINVAL, and changing the name before reporting the error. The final source was restored and rebuilt afterward. - Conventions, whitespace and test registration checks passed. Linux, a new console run, games and the full CTest suite have not been run. No new dependency, silent stub or code comment is added. AI-assisted: yes — OpenAI Codex assisted with implementation, testing and this description. ### Checklist - [x] Based on current main; no competing rename-length implementation found in the inspected open PRs - [x] One topic per PR - [x] No new code comments - [x] No new silent stubs or fallback behavior - [x] Reports, logs and screenshots kept outside the repository - [x] No new third-party dependencies - [x] General behavior, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes
oneandonlydean commented 2026-10-10 03:19:21 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-10T03:19:21Z.


This conflicts with main after today's merges; could you rebase? It passed testing and is otherwise ready.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6093235286 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2230#issuecomment-6093235286). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-10T03:19:21Z. --- This conflicts with main after today's merges; could you rebase? It passed testing and is otherwise ready.
adriadam10 commented 2026-10-10 07:56:50 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T07:56:50Z.


Rebased onto current main as @oneandonlydean asked (only conflict: adjacent test registrations in libkernel/CMakeLists.txt, kept both). Rebuilt and ran guest_pthread_rename plus the libkernel/libs tests on Linux: green, and the new test fails without the length check in Thread.cpp; merging on green CI.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6095363370 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2230#issuecomment-6095363370). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-10T07:56:50Z. --- Rebased onto current main as @oneandonlydean asked (only conflict: adjacent test registrations in `libkernel/CMakeLists.txt`, kept both). Rebuilt and ran `guest_pthread_rename` plus the libkernel/libs tests on Linux: green, and the new test fails without the length check in `Thread.cpp`; merging on green CI.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!2230
No description provided.