Skip to content

fix(libkernel): fail rtprio_thread, sched_setscheduler and setpriority with the jail privilege errors - #13896

Merged
adriadam10 merged 2 commits into
boykopovar:mainfrom
Gruzzberry:fix/rtprio-jail
Nov 1, 2026
Merged

adriadam10 merged 2 commits into
boykopovar:mainfrom
Gruzzberry:fix/rtprio-jail

Conversation

@Gruzzberry

Copy link
Copy Markdown
Contributor

What

A title runs as a jailed uid 0 (the credential model agreed on #11216). FreeBSD 11.4's prison_priv_check grants a jailed caller only PRIV_SCHED_DIFFCRED and PRIV_SCHED_CPUSET of the scheduler privileges and sends every other one to its default: branch, which returns EPERM. main did the privileged work anyway. Three calls change, each at the position of priv_check in kern_resource.c and p1003_1b.c:

  • rtprio_thread with RTP_SET of a real-time (2), FIFO (10) or idle (4) class fails with EPERM (PRIV_SCHED_RTPRIO; idle needs it too because unprivileged_idprio is 0). It comes after the thread lookup (ESRCH) and the copy-in (EFAULT) and before rtp_to_pri, so a priority above 31 also gives EPERM. Before, these threw as not implemented.
  • setpriority with a negative nice fails with EACCES (donice: PRIV_SCHED_SETPRIORITY, the nice value of the process is 0), after the which (EINVAL) and who (ESRCH) checks and for PRIO_PROCESS, PRIO_PGRP and PRIO_USER. A nice of 0 or more behaves as before.
  • sched_setscheduler copies the parameter in first (EFAULT, now also for an unreadable non-null pointer), then finds the pid (ESRCH unless 0 or the guest's own), then fails every policy and priority with EPERM (PRIV_SCHED_SET is checked in kern_sched_setscheduler before the policy is looked at, so a bad policy no longer gives EINVAL). The call no longer records anything through scePthreadSetschedparam and the own-pid case no longer throws.

Not changed: rtprio is not modelled on main; sched_setparam, getpriority, cpuset and the scePthread* calls are untouched. The debt entries for the three calls say what a payload process outside a jail answered (rtprio_thread type 2 gave EINVAL; setpriority accepted -25 and -5) and that the jail result is not measured on a console.

Tested

Windows 11 (10.0.26200), WinLibs MinGW-w64 GCC 15.2.0 r7, Ninja, Release, -DBUILD_TESTING=ON, on current main (049619c).

  • guest_rtprio_thread: RTP_SET of types 2, 4, 10 and 12 with priorities 0, 15, 31, 32 and 999, on the calling thread and on another thread, gives EPERM and leaves the request alone; an unreadable pointer still gives EFAULT and an unknown thread ESRCH first.
  • guest_sched_priority: negative nice (-1, -5, -20, -25, -99) gives EACCES for the three which values, getpriority stays 0, an unknown pid with a negative nice still gives ESRCH, a bad which EINVAL, nice 0 and 5 return 0.
  • guest_kernel_sys: sched_setscheduler gives EFAULT for a null and for a 0x10 parameter (also with an unknown pid), ESRCH for an unknown pid, and EPERM for pid 0 and the guest's own pid with policies -1, 0, 1, 2, 3, 4 and 7 at priorities 700 and 300, leaving the thread's policy and priority as they were.
  • On main all three tests fail; with this change they pass, three runs out of three.
  • Full suite: the only failures are vulkan_validation_gate_reports and check_compile_test_windows_gcc_response_text_mode_is_not_reinterpreted (the WindowsApps python in this environment) and annotate_module, a timeout under load that passes alone; nothing else differs from the last main result.
  • python tools/check_conventions.py --base upstream/main: passes.
  • Not tested: a console, a title run, Linux and macOS.

Overlaps

tools/pr_overlap.py failed closed and listed 50 pull requests it could not compare; I read the diffs of those that touch Process.cpp, Thread.cpp or Export.Discovery.cpp. None changes rtprio_thread, setpriority or sched_setscheduler. The only neighbour is #9713, which adds a debt line two lines below the sched_setscheduler entry in docs/dev/debt/libkernel_sys.md; the hunks do not touch.

Checklist

  • Based on current main; no other open PR implements the same function
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); no silent stubs added
  • No notes, investigation .md files or images added to the repository
  • New third-party code is a submodule built from source: none added
  • Generic behaviour, not specific to one title
  • Depends on: none; merge order: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

AI-assisted (Claude Code).

🤖 Generated with Claude Code

@github-actions

github-actions Bot commented Oct 31, 2026 •

Copy link
Copy Markdown

Progress report (b415263 → 97ff67b)

📈 System libraries: 25.85% (+0.0029%, +1 implemented functions)

✅ 1 implemented
Library Name
libkernel_sys sched_setscheduler_nid_postfix

Changed libraries (implemented exports)

Library Before After Change
libkernel_sys 135/832 (16.23%) 136/832 (16.35%) +0.12%

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests run and reviewed — approval deferred

The source changes match the cited FreeBSD jail checks, but the exact-current-base Windows run did not execute guest_rtprio_thread.

What I ran

Reviewed head 59bda82d4daa7e9b5bef421b2fa5d5c9702ff1f0 against PR base cbed91529193c47194bef11811906c7cb6054af1; the merge preview against current main b8f0a6b2025605b78eb70646bda79f458a577c82 was clean. Environment: Debian 12, Linux x86_64, Python 3.11.2; no local compiler or build was used.

python3 tools/pr_precheck.py --repo boykopovar/AnyPS5 --pr 13896
git diff --check b8f0a6b2025605b78eb70646bda79f458a577c82...59bda82d4daa7e9b5bef421b2fa5d5c9702ff1f0
python3 tools/check_conventions.py --base b8f0a6b2025605b78eb70646bda79f458a577c82 --head 59bda82d4daa7e9b5bef421b2fa5d5c9702ff1f0
gh run view 41198173496 -R boykopovar/AnyPS5 --job 124528697285 --log | grep -E 'guest_rtprio_thread|guest_sched_priority|guest_kernel_sys|Test #[0-9]+|[0-9]+/[0-9]+ Test|100% tests passed|tests failed|Test project'

I also inspected the exact-head implementations and assertions, the current-main test registrations, and the precheck's current-main merge preview.

Results

Check Result
Diff check and conventions Passed against current main.
Current-main merge preview Clean against b8f0a6b2025605b78eb70646bda79f458a577c82; no declared dependencies.
Source review The setpriority and sched_setscheduler error ordering matches the cited FreeBSD flow; the real-time and idle rtprio_thread classes return EPERM. I found no separate source defect.
Hosted Windows Passed. It built guest_rtprio_thread_tests, but CTest ran guest_kernel_sys and guest_sched_priority, not guest_rtprio_thread.
Other hosted checks Eligibility, conventions, library portability, intake, labels and report passed; Linux and specialized jobs were skipped.
Author-provided tests The PR reports all three tests passing 3/3, but the cited test base 049619c202f00698b6d559817577726fbeb1ca4d is 63 commits behind the PR base. I did not independently rerun those tests.
Precheck helper scripts Diff, conventions and mergeability passed. Its ABI and test-quality helper invocations could not run because those helper files are absent from the isolated PR checkout; I manually verified the current-main CMake test registrations.
Unedited relevant check output
All conventions checks passed.
windows	Build and run changed guest core/libs tests	2026-10-31T11:56:50.5849589Z [2/8] Building CXX object core/libs/prx/libkernel/CMakeFiles/guest_sched_priority_tests.dir/__/__/tests/GuestSchedPriority.cpp.obj
windows	Build and run changed guest core/libs tests	2026-10-31T11:56:50.7268866Z [3/8] Linking CXX executable tests\guest_sched_priority_tests.exe
windows	Build and run changed guest core/libs tests	2026-10-31T11:56:50.7300857Z [4/8] Building CXX object core/libs/prx/libkernel/CMakeFiles/guest_rtprio_thread_tests.dir/__/__/tests/GuestRtprioThread.cpp.obj
windows	Build and run changed guest core/libs tests	2026-10-31T11:56:50.8518021Z [5/8] Linking CXX executable tests\guest_rtprio_thread_tests.exe
windows	Build and run changed guest core/libs tests	2026-10-31T11:56:59.2810169Z Test project D:/a/AnyPS5/AnyPS5/build
windows	Build and run changed guest core/libs tests	2026-10-31T11:56:59.3832758Z     Start  439: guest_kernel_sys
windows	Build and run changed guest core/libs tests	2026-10-31T11:56:59.3904560Z     Start 2805: guest_sched_priority
windows	Build and run changed guest core/libs tests	2026-10-31T11:56:59.4208619Z 1/3 Test #2805: guest_sched_priority .................................................   Passed    0.03 sec
windows	Build and run changed guest core/libs tests	2026-10-31T11:56:59.5524887Z 2/3 Test  #439: guest_kernel_sys .....................................................   Passed    0.17 sec
windows	Build and run changed guest core/libs tests	2026-10-31T11:57:01.0992896Z 100% tests passed, 0 tests failed out of 3
/usr/bin/python3: can't open file '/tmp/anyps5-pr-precheck/boykopovar-AnyPS5-pr-13896-59bda82d4daa/head-59bda82d4daa-6235b747/tools/pr_abi_audit.py': [Errno 2] No such file or directory
/usr/bin/python3: can't open file '/tmp/anyps5-pr-precheck/boykopovar-AnyPS5-pr-13896-59bda82d4daa/head-59bda82d4daa-6235b747/tools/pr_test_quality.py': [Errno 2] No such file or directory

Findings

Blocking

No source-level defect identified. Approval is deferred because the exact-current-base CI run does not execute the changed rtprio_thread test, and the reported local run used a substantially older main.

Non-blocking

The current-main CMake tree registers guest_rtprio_thread; the hosted job built its executable but its selected CTest run omitted it. The review would be complete with that focused test run on the current merge of this head and main.

Sources

Not verified

I did not build or run C++ tests locally, independently reproduce the author’s Windows results, run Linux/macOS tests, or test a PS5. The exact-head Windows CI run did not execute guest_rtprio_thread.

To get this to a good state

Run guest_rtprio_thread on the exact PR head merged with current main and add the tested head/base and result to the PR. I will re-check the updated evidence and head.

@github-actions

github-actions Bot commented Oct 31, 2026 •

Copy link
Copy Markdown

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 4630 docs/dev/debt/libkernel.md
PR 5021 core/libs/prx/libkernel/System/src/Process.cpp
docs/dev/debt/libkernel.md
PR 6936 docs/dev/debt/libkernel.md
PR 7088 docs/dev/debt/libkernel.md
PR 7105 docs/dev/debt/libkernel.md
PR 7121 docs/dev/debt/libkernel.md
PR 7135 core/libs/prx/libkernel/Pthread/Posix/Thread.cpp
docs/dev/debt/libkernel.md
PR 7149 docs/dev/debt/libkernel.md
PR 7192 docs/dev/debt/libkernel.md
PR 7447 docs/dev/debt/libkernel.md
PR 7464 docs/dev/debt/libkernel.md
PR 7509 docs/dev/debt/libkernel.md
PR 7804 core/libs/prx/libkernel/System/src/Process.cpp
docs/dev/debt/libkernel.md
PR 8605 docs/dev/debt/libkernel.md
PR 9097 core/libs/prx/libkernel_sys/Export.Discovery.cpp
core/libs/tests/GuestKernelSys.cpp
PR 9156 core/libs/prx/libkernel_sys/Export.Discovery.cpp
docs/dev/debt/libkernel.md
PR 9162 core/libs/prx/libkernel/System/src/Process.cpp
core/libs/prx/libkernel_sys/Export.Discovery.cpp
docs/dev/debt/libkernel_sys.md
PR 9199 docs/dev/debt/libkernel.md
PR 9242 core/libs/prx/libkernel_sys/Export.Discovery.cpp
docs/dev/debt/libkernel.md
PR 9293 core/libs/prx/libkernel_sys/Export.Discovery.cpp
docs/dev/debt/libkernel.md
PR 9297 core/libs/prx/libkernel_sys/Export.Discovery.cpp
docs/dev/debt/libkernel.md
docs/dev/debt/libkernel_sys.md
PR 9302 core/libs/prx/libkernel_sys/Export.Discovery.cpp
docs/dev/debt/libkernel.md
docs/dev/debt/libkernel_sys.md
PR 9326 core/libs/prx/libkernel_sys/Export.Discovery.cpp
docs/dev/debt/libkernel.md
PR 9383 core/libs/prx/libkernel_sys/Export.Discovery.cpp
PR 9389 core/libs/prx/libkernel_sys/Export.Discovery.cpp
docs/dev/debt/libkernel.md
PR 9447 core/libs/prx/libkernel/Pthread/Posix/Thread.cpp
PR 9557 docs/dev/debt/libkernel.md
PR 9566 docs/dev/debt/libkernel.md
PR 9843 docs/dev/debt/libkernel.md
PR 9929 core/libs/prx/libkernel/System/src/Process.cpp
PR 9938 docs/dev/debt/libkernel.md
PR 10025 docs/dev/debt/libkernel.md
PR 10319 docs/dev/debt/libkernel.md
PR 10442 docs/dev/debt/libkernel.md
PR 10645 docs/dev/debt/libkernel.md
PR 11002 docs/dev/debt/libkernel.md
PR 11212 core/libs/prx/libkernel_sys/Export.Discovery.cpp
docs/dev/debt/libkernel_sys.md
PR 11215 docs/dev/debt/libkernel.md
PR 11624 core/libs/prx/libkernel/System/src/Process.cpp
docs/dev/debt/libkernel.md
PR 11625 docs/dev/debt/libkernel.md
PR 11628 core/libs/prx/libkernel/System/src/Process.cpp
docs/dev/debt/libkernel.md
PR 11661 core/libs/prx/libkernel/System/src/Process.cpp
docs/dev/debt/libkernel.md
PR 11689 core/libs/prx/libkernel/System/src/Process.cpp
docs/dev/debt/libkernel.md
PR 11698 core/libs/prx/libkernel/System/src/Process.cpp
docs/dev/debt/libkernel.md
PR 11896 docs/dev/debt/libkernel.md
PR 11939 core/libs/prx/libkernel/System/src/Process.cpp
docs/dev/debt/libkernel.md
PR 12560 docs/dev/debt/libkernel.md
PR 12642 core/libs/prx/libkernel_sys/Export.Discovery.cpp
docs/dev/debt/libkernel_sys.md
PR 12682 docs/dev/debt/libkernel.md
PR 12688 docs/dev/debt/libkernel.md
PR 12700 docs/dev/debt/libkernel.md
PR 12826 core/libs/prx/libkernel_sys/Export.Discovery.cpp
docs/dev/debt/libkernel.md
PR 12925 core/libs/tests/GuestKernelSys.cpp
docs/dev/debt/libkernel.md
docs/dev/debt/libkernel_sys.md
PR 12965 docs/dev/debt/libkernel.md
PR 13129 docs/dev/debt/libkernel_sys.md
PR 13253 docs/dev/debt/libkernel_sys.md
PR 13256 docs/dev/debt/libkernel_sys.md
PR 14108 docs/dev/debt/libkernel.md
PR 14111 docs/dev/debt/libkernel.md
PR 14128 docs/dev/debt/libkernel.md
PR 14212 docs/dev/debt/libkernel.md
docs/dev/debt/libkernel_sys.md

@oneandonlydean

Copy link
Copy Markdown
Collaborator

@Gruzzberry Reviewed at 59bda82d4d. The checks match FreeBSD 11.4: rtprio_thread fails with EPERM for the real-time, FIFO and idle classes after the thread lookup and copy-in and before the priority range check; setpriority gives EACCES for a negative nice after the which and who checks; sched_setscheduler copies in, finds the pid, then gives EPERM before the policy is looked at. Two changes, both in the debt files:

  1. The rewrite of the rtprio_thread and getpriority entries in libkernel.md drops sourced or limiting text that was there before: "no accepted value or set by another thread's id measured", "(unknown ids measured)", the note that sce attributes allow only SCHED_FIFO and SCHED_RR, "as PS5 firmware 13.60 did in a payload process for sets of -25, -5, 5 and 25", and the sentence that what a title process reads and the host nice raised by APS5_THREAD_PRIORITY=high are not reported. Please restore that text and change only the sentences about the new results.
  2. All three new results rest on "a title is taken to run jailed" and contradict the only console data in the entries: a payload process (not jailed) accepted a negative nice and answered type 2 with EINVAL. The entries say the jail result is not measured, which is right. Please add that the scePthread and sceKernel priority calls do not go through these three functions (nothing in the tree calls them), so the change only reaches a title that imports rtprio_thread, setpriority or sched_setscheduler itself, and name the one importer the rtprio_thread entry already lists.

Gruzzberry and others added 2 commits November 1, 2026 07:56
…y with the jail privilege errors

A title is jailed (agreed on boykopovar#11216). FreeBSD 11.4 prison_priv_check denies
PRIV_SCHED_RTPRIO, PRIV_SCHED_SET and PRIV_SCHED_SETPRIORITY to a jailed caller.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…etpriority debt entries

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@adriadam10
adriadam10 merged commit c2ba690 into boykopovar:main Nov 1, 2026
11 checks passed
@adriadam10

Copy link
Copy Markdown
Collaborator

Checked the three jail privilege paths against FreeBSD 11.4 (sys_rtprio_thread, donice, sys_sched_setscheduler): error order and values match, and the tests pin exact errnos that main does not return.

Added a commit with both debt changes @oneandonlydean asked for: the measured text in the rtprio_thread and getpriority entries is restored with only the new-result sentences changed, and each entry now says the scePthread/sceKernel priority calls do not go through these functions, so the change reaches only a title importing them itself (Morrowind for rtprio_thread); merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants