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

Merged
DeveshB-1 merged 2 commits from upstream-pr/13908 into main 2026-11-01 09:55:39 +00:00
DeveshB-1 commented 2026-10-31 12:27:21 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by DeveshB-1 on 2026-10-31T12:27:21Z.


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
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5097494865 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/13908). Originally posted by [DeveshB-1](https://github.com/DeveshB-1) on 2026-10-31T12:27:21Z. --- ### 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 <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
MarcZX10 commented 2026-10-31 12:32:15 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-31T12:32:15Z.

Review: APPROVED


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
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5722718168 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/13908#pullrequestreview-5722718168). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-31T12:32:15Z. **Review:** APPROVED --- # 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. ```sh python3 tools/pr_precheck.py --repo boykopovar/AnyPS5 --pr 13908 python3 tools/pr_abi_audit.py --base 60bdb061356db736928eee431cd8bd4c9ba68036 --head 64ff517803b7017e2116c7348f46713d4c8bb9e7 --json ```
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!13908
No description provided.