Repository navigation
fix(libkernel): follow the 13.60 kernel's cpuset affinity size and jail checks - #22325
Merged
oneandonlydean merged 2 commits intoNov 17, 2026
Merged
oneandonlydean merged 2 commits into
oneandonlydean merged 2 commits into
Conversation
The firmware 13.60 kernel's cpuset_getaffinity handler accepts set sizes from 8 to 16 bytes and returns ERANGE for every other size before its other checks, so the 17 to 23 byte range no longer throws. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The firmware 13.60 kernel looks a jail up only among the caller's descendant jails, so cpuset_getaffinity and cpuset_setaffinity answer a jail target with ESRCH. cpuset_getaffinity also reports target and level errors before a null mask, as the handler copies out last. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
fogydes
force-pushed
the
fix/libkernel-cpuset-getaffinity-size
branch
from
November 17, 2026 12:27
f385019 to
b761169
Compare
12 tasks done
PrivacyOnion
approved these changes
Nov 17, 2026
PrivacyOnion
left a comment
Contributor
There was a problem hiding this comment.
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against b76116919c:
- Conventions:
tools/check_conventions.pypassed. - Build:
guest_available_cpumask_testsbuilt cleanly. - CTest (
guest_available_cpumask):1/1 Test #5439: guest_available_cpumask .......... Passed 0.02 sec 100% tests passed, 0 tests failed out of 1 - Negative control: with
core/libs/prx/libkernel/Pthread/Posix/Thread.cppreverted tomainand the new tests kept, the suite fails:Restoring the change makes it pass again.1/1 Test #5439: guest_available_cpumask ..........Subprocess aborted***Exception: 0.47 sec 0% tests passed, 1 tests failed out of 1 - Code reading:
- Verified cpuset_getaffinity_nid_postfix size boundary check: 'if (size < sizeof(KernelCpumask) || size > 16) return fail(GuestErange);' correctly returns ERANGE for size < 8 and size in [17, 23] as documented for 13.60 kernel behavior.
- Verified cpuset_getaffinity_nid_postfix error ordering: size check (ERANGE) -> target lookup (WhichJail returns ESRCH, WhichThread/WhichProcess checks) -> level check -> null mask check (EFAULT) -> GuestCopyOut. null mask with missing thread or jail correctly yields ESRCH before EFAULT.
- Verified cpuset_setaffinity_nid_postfix WhichJail handling: returns ESRCH at LevelRoot, LevelCpuset, and LevelWhich after size check and copyin/zero-tail validation.
- Checked technical debt fragment in docs/dev/debt/changes/fix-libkernel-cpuset-getaffinity-size.md: correctly formats change and remove sections per TechnicalDebt.md rules without introducing untracked or non-debt files.
- Verified unit tests in core/libs/tests/GuestAvailableCpumask.cpp: exercises sizes 17, 20, 23, 24 with valid and null masks, invalid id/level ordering with null mask, and WhichJail across levels 1..3 with get and set affinity.
Looks Good To Me
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Follow the firmware 13.60 kernel's handlers for
cpuset_getaffinity(syscall 487) andcpuset_setaffinity(syscall 488) in the cases that still threw or diverged:cpuset_getaffinityno longer throw: every size outside 8 to 16 bytes returns-1/ERANGEbefore any other check. Syscall 487's thunk (kernel-13.60 @ 0xffffffff9e655cc0) goes through 0xffffffff9ec2de60 to 0xffffffff9ec2dac0, which loadscpusetsize(@ 0xffffffff9ec2dae5), comparescpusetsize - 17with -9 (@ 0xffffffff9ec2dae9..0xffffffff9ec2daf1) and returnsr12d= 0x22 (set @ 0xffffffff9ec2dad8) at 0xffffffff9ec2dd66.CPU_WHICH_JAIL) returnESRCHfrom both calls at every level instead of throwing. Both handlers call the target lookup at 0xffffffff9ec2c5e0: getaffinity from 0xffffffff9ec2db28, setaffinity's core (0xffffffff9ec2de90, reached from 488 through 0xffffffff9ec2e320) from 0xffffffff9ec2e10e (ROOT/CPUSET) and 0xffffffff9ec2e184 (WHICH), after its size check, copyin and check on the bytes past 8. The lookup's jail case (0xffffffff9ec2c67e) passes the caller'scr_prisonand the id to 0xffffffff9efd9ae0. That walk starts at the prison's first child and never compares the caller's own prison, so a miss returns 3 (ESRCH) at 0xffffffff9ec2c81a. A title can't create jails, so every id misses.cpuset_getaffinitynull mask: a null mask now givesEFAULTafter the target and level errors, as the handler copies out last. A missing thread with a null mask now answersESRCH.Still throwing: numbered sets, WHICH interrupt and domain masks, the ROOT/CPUSET and WHICH-cpuset setters. The dump settles their lookup, but not the PS5 set and interrupt IDs a title would see.
cpuset_getid's jail case uses the same lookup and should answerESRCHtoo. I left it out because #21987 (open) rewrites that function's debt entry, and two fragments can't change one entry; it can follow once #21987 lands.Debt (
docs/dev/debt/changes/fix-libkernel-cpuset-getaffinity-size.md):cpuset_setaffinityandcpuset_getaffinityentries are rewritten with the kernel addresses, each under 1000 characters;ERANGEfrom 24 bytes onmain).Reachability:
cpuset_getaffinityis imported by 3 homebrew titles in the import sweep (cpuset_setaffinityby 5), and ProsperoWeb (PRWB00001) calls it. No title is known to pass these exact arguments; this removes throws from imported exports, it doesn't unblock a known stop.Overlap:
cpuset_setaffinitydebt entry inlibkernel.mddirectly; whichever merges second reconciles that entry.main; I checked its diff by hand, and it doesn't touch these lines.Tested
maincb28e72guest_available_cpumaskandguest_kernel_sys_cpuset: 2/2 passed. New cases:ERANGE, leave the buffer untouched, and do so with a null mask too;ESRCHfrom both calls, with no output written and before a null-maskEFAULT;ESRCH, and level 0 with a null mask returnsEINVAL.main'sThread.cpp,guest_available_cpumaskfails (cpuset_getaffinity with a size of 17 to 23 bytes not implemented);python tools/check_conventions.py --base origin/main: all checks passed;python tools/debt_fold.py --check: exit 0Checklist
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)