Skip to content

fix(libkernel): return EFAULT from cpuset and pthread affinity for invalid memory - #13908

Merged
adriadam10 merged 2 commits into
boykopovar:mainfrom
DeveshB-1:fix/cpuset-affinity-efault
Nov 1, 2026
Merged

adriadam10 merged 2 commits into
boykopovar:mainfrom
DeveshB-1:fix/cpuset-affinity-efault

Conversation

@DeveshB-1

Copy link
Copy Markdown
Contributor

What

Safely copy in and copy out CPU affinity masks using GuestCopyIn_nid_no_patch and GuestCopyOut_nid_no_patch in cpuset_getaffinity, cpuset_setaffinity, pthread_getaffinity_np, and pthread_setaffinity_np, returning EFAULT when the caller provides invalid or unmapped memory pointers.

Tested

Linux (Ubuntu 24.04, x86_64). Added negative control assertions passing unmapped pointer stores (0x10) to GuestAvailableCpumask.cpp. Verified that the unpatched base crashed with SIGSEGV and that the change cleanly returns EFAULT / sets errno to EFAULT (14). Verified guest_available_cpumask passes cleanly across repeated test runs. Ran python3 tools/check_conventions.py --base origin/main and python3 tools/pr_overlap.py --branch fix/cpuset-affinity-efault (no overlap).

Checklist

  • Based on current main; no other open PR implements the same functions
  • 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); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

@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.

Reviewed — looks good

The exact head 64ff517803b7017e2116c7348f46713d4c8bb9e7 safely copies affinity masks through the guest-memory helpers and reports EFAULT for invalid pointers.

I reviewed it against base 60bdb061356db736928eee431cd8bd4c9ba68036. The no-build precheck passed diff, conventions, and mergeability; its ABI/test-quality helper scripts were unavailable in the isolated PR checkout. The separate ABI audit passed with no findings. The author reports repeated focused Linux tests and a negative control; hosted Windows was still running and Linux was skipped in CI. I did not run a local C++ build or test binary.

python3 tools/pr_precheck.py --repo boykopovar/AnyPS5 --pr 13908
python3 tools/pr_abi_audit.py --base 60bdb061356db736928eee431cd8bd4c9ba68036 --head 64ff517803b7017e2116c7348f46713d4c8bb9e7 --json

@github-actions

github-actions Bot commented Oct 31, 2026 •

Copy link
Copy Markdown

Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
PR 14039 docs/dev/debt/libkernel.md L181

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 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
core/libs/tests/GuestAvailableCpumask.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 docs/dev/debt/libkernel.md
PR 8605 docs/dev/debt/libkernel.md
PR 9156 docs/dev/debt/libkernel.md
PR 9199 docs/dev/debt/libkernel.md
PR 9242 docs/dev/debt/libkernel.md
PR 9293 docs/dev/debt/libkernel.md
PR 9297 docs/dev/debt/libkernel.md
PR 9302 docs/dev/debt/libkernel.md
PR 9326 docs/dev/debt/libkernel.md
PR 9389 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 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 11215 docs/dev/debt/libkernel.md
PR 11624 docs/dev/debt/libkernel.md
PR 11625 docs/dev/debt/libkernel.md
PR 11628 docs/dev/debt/libkernel.md
PR 11661 docs/dev/debt/libkernel.md
PR 11689 docs/dev/debt/libkernel.md
PR 11698 docs/dev/debt/libkernel.md
PR 11896 docs/dev/debt/libkernel.md
PR 11939 docs/dev/debt/libkernel.md
PR 12560 docs/dev/debt/libkernel.md
PR 12682 docs/dev/debt/libkernel.md
PR 12688 docs/dev/debt/libkernel.md
PR 12700 docs/dev/debt/libkernel.md
PR 12826 docs/dev/debt/libkernel.md
PR 12925 docs/dev/debt/libkernel.md
PR 12965 docs/dev/debt/libkernel.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

@oneandonlydean

Copy link
Copy Markdown
Collaborator

@DeveshB-1 Reviewed at 64ff517803. No other open PR changes these four functions (the only affinity-related PR is #13127, cpuset_getid), and it merges clean with #13896, which edits other functions in the same Thread.cpp. The copy-in happens before any state change and the copy-out after the lookups, the buffers are large enough for every size the functions accept, and cpuset_* return -1 with errno 14 while pthread_*_np return 14, as FreeBSD and libthr do. One change, in docs/dev/debt/libkernel.md: the entries for cpuset_getaffinity, cpuset_setaffinity, pthread_getaffinity_np and pthread_setaffinity_np say nothing about a bad mask pointer, and this PR adds EFAULT for a non-null unreadable or unwritable one. Please add a sentence that this is a host-safety fallback and that the console's answer for a non-null invalid pointer was not measured, as the other pointer-fault PRs of this series do in their entries.

@adriadam10
adriadam10 force-pushed the fix/cpuset-affinity-efault branch from 64ff517 to 16135b4 Compare November 1, 2026 07:22
@github-actions github-actions Bot added the docs label Nov 1, 2026
@adriadam10
adriadam10 merged commit 6c0bdd2 into boykopovar:main Nov 1, 2026
11 checks passed
@adriadam10

Copy link
Copy Markdown
Collaborator

Checked the four functions: copy-in happens before any state change, copy-out after the lookups, buffers cover every accepted size, and the new test (0x10 pointers) would crash without the change.
Added as our own commit, as @oneandonlydean asked: a sentence in the docs/dev/debt/libkernel.md entries of cpuset_getaffinity, cpuset_setaffinity, pthread_getaffinity_np and pthread_setaffinity_np saying EFAULT is a host-safety fallback and the console's answer was not measured; merged.

oneandonlydean pushed a commit that referenced this pull request Nov 2, 2026
The conflict with #13908 in docs/dev/debt/libkernel.md keeps both sides: this branch's pthread_getaffinity_np entry, followed by #13908's sentence on the EFAULT fallback for a mask pointer that cannot be read or written.
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