fix(libkernel): sched_getparam reads out-of-range priorities, sched_setparam EPERM outside 256-767, own pid on the main thread #11865
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/11865"
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 ionut27001 on 2026-10-27T10:01:34Z.
What
sched_getparamno longer throws for a priority outsidesched_get_priority_mintosched_get_priority_max,sched_setparamreturnsEPERMthere instead of throwing, and the own pid works from the process's main thread:sched_getparamreturns the thread's priority as it is (a thread put at 900 or 959 byscePthreadSetprioreads back 900 or 959, p83 lines 217 and 221).sched_setparamon aSCHED_FIFOorSCHED_RRthread with a priority outside 256-767 fails withEPERMand leaves the priority unchanged. Measured on aSCHED_FIFOthread with 255 and 768;SCHED_RRwas not probed and follows FreeBSD'skschedrange check.sched_getparam,sched_getschedulerandsched_setparamwith the own pid (getpid()) act on the calling thread when it is the process's initial thread (IsInitialPthread_nid_no_patch, whichpthread_main_npalready uses), the same as pid 0. From any other thread the own pid still throws, as onmain: in a payload process on a PS5 (firmware 12.70) it read the priority of the thread that ran the payload's main (p84 line 20); whether that is the process's first thread is unmeasured. This is not modelled and stays in the debt entry. On macOS the guest's main thread runs on a second host thread, which is not the initial thread, so the own pid throws there too; the test's own-pid check is compiled out on macOS.sched_setparamon a thread whose policy is neitherSCHED_FIFOnorSCHED_RRstill throws.Evidence, probe
p83_libkernel(a payload process on a PS5, firmware 12.70),result.log:sched_get_priority_min/maxare 256/767 for policies 1 and 3 andEINVALfor 0, 2, 4.sched_getparam(0)returns 0 with 900 and 959.sched_setparam(0)with 255 and 768 returns -1EPERMandsched_getparam(0)then reads 700; with 256 and 767 it returns 0 and reads back 256 and 767.Evidence, probe
p84_libkernel(a payload process on a PS5, firmware 12.70),result.log:getpid()both read 600,sched_getscheduler1.getpid()throughsched_getparam;sched_getscheduler(getpid())is 1, the policy of both threads.Test:
GuestSchedParams.cppgainsCheckOutOfRange(read of 900 and 959;EPERMfor 255 and 768 with the priority unchanged) andCheckOwnPid(the main thread at 600 reads 600 and its own policy throughgetpid(), then restores its priority throughgetpid()), only values the probes answered.Tested
Windows 11, WinLibs GCC 15.2.0 (Release, Ninja), commit
e679177c1bon main431a5156b9:ctest -R ^guest_sched_params$passed twice.Pthread/Posix/Common.hppandPthread/Posix/Thread.cpprestored from main and rebuilt, the same test aborts (sched_getparamthrows for priority 900).Checklist
main(rebased onto it); 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 MarcZX10 on 2026-10-27T10:25:57Z.
Review: DISMISSED
I independently verified the lifetime race described in the existing inline review comment on the current head
c566f667bccdf894153b82fa6a83b3c84dc95ca4.SchedTargetloads the raw main-thread pointer beforeReadLiveSchedacquires the live-thread registry lock. If that thread exits and its address is reused before validation, the read can accept the replacement thread.sched_setparamalso releases the validation lock before callingscePthreadSetprio, leaving the same stale-address window for a write.This can report or mutate the wrong guest thread, so it blocks approval. Please address the existing request by keeping identity/lifetime stable through selection and use, and add deterministic teardown/address-reuse coverage for reads and writes. I am not repeating the inline comment's detailed implementation suggestions.