fix(libkernel): fail pthread_rename_np and scePthreadRename with EFAULT on an unreadable name #15567
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/15567"
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:05:21Z.
What
pthread_rename_nptook the length of the guest name withstrlen, andscePthreadRenameassigned it to astd::string, both through the raw pointer, so a non-null name that is not readable, such as 0x10 or one that runs into an inaccessible page, faulted the host. They now copy the name withCopyGuestString_nid_no_patchand fail withEFAULT(14 frompthread_rename_np,SCE_KERNEL_ERROR_EFAULTfromscePthreadRename).The copy comes before the thread is looked up, so an unreadable name wins over
ESRCH; that order was chosen for the host and is not derived from FreeBSD (whose libthr finds the thread before it callsthr_set_name, which in turn runscopyinstr) or from a console. A null thread or null name still givesEINVALfirst, as before. Both read at most 32 bytes (31 characters and the terminator), so a longer name still givesENAMETOOLONG, as the console measurements onmain(#17091) pin for both functions, without reading past the 32nd byte. Thestrlencheck that #17091 added toscePthreadRenameis replaced by this bounded copy.The Sony functions were not measured with a bad name pointer, so this is a host-safety fix, not console behaviour. 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 currentmain.guest_pthread_rename: newCheckUnusableNamescovers a name at 0x10, on aPROT_NONEpage and a 31-byte name that runs into one (EFAULTfrom both functions, the stored name unchanged and the caller's errno untouched); a null thread with a bad name (EINVAL); a 32-byte name ending exactly at the unreadable page (ENAMETOOLONG, nothing read past it); a 31-character name ending exactly at it (stored); an unknown thread with a good name (ESRCH); a null name (EINVAL); and an unterminated 16 KiB name forscePthreadRename(ENAMETOOLONG). Onmainthe test fails; with this change it passes, three runs out of three. The existing names,ENAMETOOLONGsizes and Windows thread description cases still pass.elf_header,guest_*,windows_*,macos_*,restricted_undefined_symbols_*and the like): their 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; withThread.cppandPosix/Thread.cppreverted tomainthe second still fails, so they do not depend on this change. Nothing thread related fails.main7f64d6f057(2026-11-13), resolving the conflict with #17091 as above:guest_pthread_rename, including the #17091 cases, passes three runs out of three. The full-suite run above is from the previous base.python tools/check_conventions.py --base upstream/main: passes.Overlaps
tools/pr_overlap.pyreports no conflicting file or export. It lists #3986, #4563, #8592, #9447, #12130 and #12642 as sharingThread.cpporPosix/Thread.cppwithout comparing them, because those PRs conflict withmainthemselves; none of their diffs changesscePthreadRename,pthread_rename_npor the code around them (#12130 and #12642 only callscePthreadRenamewith short host names in new tests, which still work). The other listed PRs only append todocs/dev/debt/libkernel.md.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 gabichuuuuu on 2026-11-08T21:44:30Z.
Review: COMMENTED
Windows run of head
cd61402131, merged ontomain095ff72367in one tree with other open PRs that touch different files (each PR's test is its own file, so they don't interact). Setup: Windows 11, WinLibs GCC 15.2 r7 (x86_64-ucrt-posix-seh, the CI toolchain), Release,BUILD_TESTING=ON.guest_pthread_renamewith--repeat until-fail:5: 5 / 5 pass.main's twoThread.cppfiles and this PR's test: 5 / 5 runs fail.