fix(libkernel): fail pthread_attr_get_np with EFAULT on an unreadable attribute pointer #17216
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/17216"
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-08T14:52:28Z.
What
pthread_attr_get_npread the guest attribute pointer without checking it, so an unusable pointer such as0x10or an unreadable page crashed the host. FreeBSD 11.4's_pthread_attr_get_npreads*dstin its first check, where the process faults, so libthr has no error to copy here; this is a host-safety fallback. The attribute slot is now read withGuestCopyIn_nid_no_patchand an unreadable pointer returnsEFAULT. The order of the other checks is unchanged: a null thread or attribute pointer givesEINVAL, then theEFAULT, thenEINVALfor an attribute that was never initialised, thenESRCHfor a thread that is not live. The success path fills the same fields as before. The new debt entry records that theEFAULTis unmeasured.Tested
Windows 11 (10.0.26200), WinLibs MinGW-w64 GCC 15.2.0 r7, Ninja, Release,
-DBUILD_TESTING=ON, onmainf5fe807353.guest_pthread_attr: new checks for the attribute pointer0x10and an unreadable page (EFAULTwith the calling thread, with an unknown thread and with a null thread, which staysEINVAL), a null attribute pointer, an uninitialised attribute and a null thread (EINVAL), an unknown thread with a valid attribute (ESRCH) and the success path. WithPosix/Attr.cppreverted tomainthe test crashes; with this change it passes, three runs out of three.python tools/check_conventions.py --base upstream/main: passes.Overlaps
honor caller-provided pthread stacks) adds one line topthread_attr_get_npinPosix/Attr.cpp, next to the lines this PR edits: proposed on #9938 that it goes first and this PR rebases.core/libs/tests/GuestPthreadAttr.cppinCheckEndedThreads, away from the function this PR adds at the end of the file; the hunks do not touch.docs/dev/debt/libkernel.mdat the same place as this one, which keeps both lines.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 PrivacyOnion on 2026-11-08T15:34:22Z.
Review: APPROVED
What I ran
e113f944810316a09ca6b137cb773b89446aacd9f5fe8073533b671946ab8999ebbee85f4f78c597(merges cleanly with currentmain828e44310ec98912f041d0e51b8adc809848741b).Tools and Checks
python tools/check_conventions.py --base upstream/main --head pr-17216: 0 errors.git diff --check upstream/main...pr-17216: clean.Windows Test Suite & Negative Control
guest_pthread_attr: Passed (0.57 s).guest_pthread_attr_stack: Passed (0.04 s).guest_pthread_attr_errors: Passed (0.05 s).core/libs/prx/libkernel/Pthread/Posix/Attr.cppfrommainreproduces the unhandled exception onread of 0x0000000000000010(0xc0000005,SIGSEGV). With this PR, the bad pointer cleanly returnsEFAULT.Code Observation (Non-blocking)
core/libs/prx/libkernel/Pthread/Posix/Attr.cppalready defines the static helperLoadAttribute(const PthreadAttr* attr, PthreadAttr& handle)at line 16, which performs the exact null,GuestCopyIn, and handle validation logic used by 14 other functions in the same file. Inpthread_attr_get_np_nid_postfix, invokingif (const int error = LoadAttribute(attr, handle)) return error;would avoid inlining those 4 lines.Also, please remove the
🤖 Generated with [Claude Code]footer below the checklist per repository conventions; the AI-assisted checkbox can stay.Looks Good To Me