fix(libkernel): return EFAULT from ktimer_create and ktimer_gettime for unwritable pointers #13964
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/13964"
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 FFwLo on 2026-10-31T14:09:36Z.
What
ktimer_createandktimer_gettimewrote the timer id and the remaining time straight through the guest pointer, so an unwritable pointer such as0x10crashed the process. FreeBSD 11'ssys_ktimer_createandsys_ktimer_gettimewrite them withcopyoutand returnEFAULT(sys/kern/kern_time.c). Both now write throughGuestCopyOut_nid_no_patchand fail withEFAULT(14).ktimer_createcopies the id out before it marks the timer live, so a failed copy leaves no timer behind, as FreeBSD deletes the timer it created whencopyoutfails. The test checks this: the following creations still get ids 3 to 31.ktimer_settimeis left out because #12281 changes it; its uncheckedcopyinofvalueandcopyoutofoldValueare recorded in the libkernel debt entry.Tested
Windows 10 x64, WinLibs GCC 15.2.0 (posix-seh, ucrt r7), Release,
ctest --test-dir build -R "^guest_kernel_sys_ktimer$":0x10withktimer_createandktimer_gettimereturns-1witherrno14, and the ids 3 to 31 that follow the failed create are unchanged.main'sKtimer.cpp:SEGFAULT.Not tested on Linux.
Checklist
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)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-31T14:21:53Z.
Review: APPROVED
Reviewed — looks good
At head
6c415b7e9b7a0a6634394b946d2c5d0cbd1b7ef9on base73f4f7e06e4f210a8c6570e335fd654dc0a86134, both output writes use the guest-safe copy helper, andktimer_createpublishes the timer ID before marking its slot live.What I ran
Linux x86_64, Python 3.11.2, GCC 12.2.0, Git 2.39.5. I did not build or run C++ tests locally.
Results
GuestKernelSysKtimertestPrecheck output
Negative control
The author reports that the same test using base
Ktimer.cppsegfaults on the invalid pointer. I did not independently run that control.Sources
Not verified
No local build or C++ test run; Linux behavior was not tested. Hosted product-test jobs were not present in the check snapshot.
Imported from boykopovar/AnyPS5. Originally posted by ahmadmuj on 2026-11-06T09:58:09Z.
Review: APPROVED
Checked head
2b04038926078057d74fa15d0d265cc36c3214d9, base73f4f7e06e4f210a8c6570e335fd654dc0a86134.Linux x86_64: built
guest_kernel_sys_ktimer_tests; its focused ctest passes. A separate probe links the actuallibkernel_sys,libkernelandlibcmodules.dladdrconfirms the timer and copyout exports.page_end-2returns-1/EFAULT. Its writable prefix changes fromA5 A5to03 00.-1/EAGAIN; every delete succeeds.page_end-16returns-1/EFAULTafter its 16 writable bytes change to zero. A valid read afterward has four zero fields. Delete succeeds; a second delete returnsEINVAL.EINVAL, before the output error.These results match the create rollback and gettime ordering in FreeBSD kern_time.c. Partial output changes are observations, not required behavior.
Sensitivity checks pass: removing create's rollback yields ID4 instead of ID3; ignoring gettime's failed copy incorrectly returns 0. Valid-pointer controls pass under both mutations. Restoring the exact head makes every case pass again.
Conventions pass against main
85e291c12b7ed08fdf83ebfa79e3057934a46ec9; the merge preview is clean. This covers Linux CPU behavior only, with no console dump, concurrent timer deletion, or full current-main build.