fix(libkernel): return EFAULT for an unwritable pthread_key_create key pointer #15748
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/15748"
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-04T12:05:43Z.
What
pthread_key_createstored the new key through the guest pointer with a raw write, so an unusable pointer such as0x10or a read-only page crashed the host. FreeBSD 11.4's_pthread_key_createdoes the same unchecked*key = i + 1and the process faults, so there is no libthr error to copy; this is a host-safety fallback. The key is now taken, written withGuestCopyOut_nid_no_patch, and given back withscePthreadKeyDeleteif the write fails, so a failed call returnsEFAULTand leaves the key number free. A NULL key pointer keeps returningEINVALas before, andscePthreadKeyCreateis not touched (#14128 changes its null check).pthread_key_deletetakes no pointer and already matches_pthread_key_delete(EINVALfor key 0, a key past the table and a key that is not allocated), so it is unchanged; the test pins it.pthread_getspecificandpthread_setspecificare hot paths and are unchanged. 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, onmainb11c7bf84f.guest_posix_specific: new checks for0x10and a read-only page as the key pointer (EFAULT, and the nextpthread_key_createreturns the same key number, so nothing leaked), NULL (EINVAL), andpthread_key_deleteof a deleted key, key 0 and key0x7fffffff(EINVAL). WithPosix/Tsd.cppreverted tomainthe test crashes (SegFault); with this change it passes, three runs out of three.vulkan_validation_gate_reports,check_compile_test_windows_gcc_response_text_mode_is_not_reinterpretedandagc_driver_direct_write_completion, which are environment failures here (Python and GPU tests);agc_driver_direct_write_completionalso fails with the changed source reverted tomain.python tools/check_conventions.py --base upstream/main: passes.Overlaps
tools/pr_overlap.pyreports no conflicting source or test file. The PRs it lists only append todocs/dev/debt/libkernel.mdat the same place as this one, which keeps both lines. #14128 changesscePthreadKeyCreateinPthread/src/Tsd.cppandGuestPthreadKey.cpp, neither of which this PR edits.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 ahmadmuj on 2026-11-06T11:05:57Z.
Review: APPROVED
Checked head
979af971268f237766b452b13eb15fa1d8683944, PR basee64c194c4343f473e815f00321fcd03910381949and pinned main5299939ecfa9e186e1eb457c6f4bd133bdb087c7.On Ubuntu 24.04.2/WSL2, GCC 13.3 Release, a separate probe links the actual libkernel/libc modules with the existing fixture's flags. Loaded paths and symbols match the build.
guest_posix_specificpass.python3 tools/check_conventions.py --base origin/mainpasses.Commands:
cmake --build <build> --target guest_posix_specific_tests -j 8,ctest --test-dir <build> -R '^guest_posix_specific$' --output-on-failure, andtimeout 30s <build>/tests/key_capacity_rollback_probe. Both revisions use separate builds. The final runner uses an environment without credentials. Each passing probe finishes below 0.02 seconds.The pinned FreeBSD source checks allocation before output. EFAULT rollback remains the documented host fallback; this does not establish console behavior.
No scoped correctness finding. CPU-only evidence; no Windows, macOS, console, game or GPU execution in this review.