fix(libkernel): hold the thread registry across posix pthread accesses #21742
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/21742"
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 AasishDairelSahayaGrinspan on 2026-11-16T18:07:41Z.
What
Four POSIX pthread wrappers dereferenced a
PthreadPrivateoutside the thread registry lock:pthread_getname_npread_joinedbefore taking any lock,scePthreadGetschedparamandscePthreadSetschedparamread and storedschedPolicyafter the priority call had returned and released the lock, andpthread_getcpuclockidread the thread's CPU clock id with no lock at all. A detached thread's object is deleted the moment it ends, so each was a use-after-free read or write (or an ABA onto a recycled object).Each dereference now happens under the existing
LockRegisteredGuestThread, and the wrapper answersESRCHwhen the thread is gone, matching the sibling exports.pthread_getname_npreleases the lock before callingscePthreadGetname, which takes it again itself.Residual, out of scope: the registry has no generation counter, so a recycled allocation landing on the same address between the priority call and the re-acquire could still read or store the wrong thread's
schedPolicy— value confusion, not memory unsafety.Tested
Linux (Omarchy 4.0.2), host build
ReleasewithBUILD_TESTING=ON:guest_pthread_released_handle— Passed, 0.01 s (each of its 20 release rounds now also requiresESRCHfrom all six wrappers on the ended detached handle)guest_pthread_getname— 0.01 sguest_pthread_schedparam— 0.01 sguest_pthread_final_release_race— 0.01 sguest_kernel_sys_pthreadwith its three modes — 0.10 s totalguest_thread_cpu_clock— 0.82 sChecklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-16T18:14:01Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
f4d92c494b:tools/check_conventions.pypassed;git diff --checkclean.guest_pthread_released_handle_testsbuilt cleanly.guest_pthread_released_handle):core/libs/prx/libkernel/Pthread/Posix/Thread.cpp,core/libs/prx/libkernel/Pthread/include/Pthread.hpp,core/libs/prx/libkernel/Pthread/src/Thread.cppreverted tomainand the new tests kept, the suite fails: Restoring the change makes it pass again.Looks Good To Me
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-20T11:31:24Z.
Review: APPROVED
Reviewed — looks good
The reviewed changes at
f4d92c494bead2841bbbb08bbcfe0cc35f712d03address the reported released-thread accesses; no blocking defect was verified in the files read.What I ran
Read the prepared description, commit list, manifest, diff, and each changed file listed as reviewed. Inspected the priority accessors and thread registry locking code through
repo_read.py. No tests or build commands were run; the test results in the description are author-reported.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
No build or tests were run in this review. The author's reported host test runs were not independently verified. All files listed as reviewed in the manifest were read; no files were excluded.
To get this to a good state
Nothing is required.