fix(libkernel): fail sigemptyset, sigfillset, sigaddset, sigdelset, sigismember with EFAULT on an unusable set #15508

Merged
Gruzzberry merged 1 commit from upstream-pr/15508 into main 2026-11-07 07:11:20 +00:00
Gruzzberry commented 2026-11-03 16:36:51 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Gruzzberry on 2026-11-03T16:36:51Z.


What

sigemptyset, sigfillset, sigaddset, sigdelset and sigismember in libkernel wrote or read the guest signal set through the raw pointer, and a null set threw std::invalid_argument before the signal number was looked at. A non-null unusable pointer such as 0x10 faulted the host. They now copy the 16-byte set with GuestCopyIn_nid_no_patch / GuestCopyOut_nid_no_patch and fail with -1 and EFAULT when the set cannot be read or written.

This is a host-safety fix, not console behaviour. FreeBSD 11.4's sigsetops.c works on the set in user space with no system call, so a bad pointer faults a console process and sets no errno; EFAULT was not measured on a console. The entry is in docs/dev/debt/libkernel.md.

The signal check stays first, as in the source: sigaddset, sigdelset and sigismember with a signal outside 1 to 128 give EINVAL without touching the set, so a null set with signal 0 gives EINVAL, not EFAULT. sigemptyset and sigfillset have no error in the source and only report EFAULT.

Tested

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

  • guest_signal_sets: new CheckBadPointers covers a null set, 0x10, a PROT_NONE page, a read-only page (sigismember succeeds, the four writers fail and leave the set unchanged), a set straddling a readable and an unreadable page, and EINVAL before EFAULT for signals 0, -1 and 129. On main the test aborts; with this change it passes, three runs out of three.
  • Full suite (3918 tests) on this branch: 23 failed in the parallel run (GPU agc_* timeouts under load); rerun alone, 20 pass and 3 fail. vulkan_validation_gate_reports and check_compile_test_windows_gcc_response_text_mode_is_not_reinterpreted fail because of the WindowsApps Python on this machine, and agc_driver_store_over_untracked fails the same way with SignalSets.cpp reverted to main.
  • python tools/check_conventions.py --base upstream/main: passes.
  • Not tested: Linux, macOS, a console, a title run.

Overlaps

tools/pr_overlap.py reports no conflicting file or export. It lists #12682, #12688, #12700 and #12965 as sharing SignalSets.cpp and GuestSignalSets.cpp without comparing them, because those PRs conflict with main themselves; their hunks in SignalSets.cpp are in the sigsetjmp / siglongjmp assembly below the five functions changed here, and their test changes are elsewhere in GuestSignalSets.cpp, so there is no overlapping line. The other listed PRs only append to docs/dev/debt/libkernel.md.

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
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

AI-assisted (Claude Code).

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5140943518 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15508). Originally posted by [Gruzzberry](https://github.com/Gruzzberry) on 2026-11-03T16:36:51Z. --- ### What `sigemptyset`, `sigfillset`, `sigaddset`, `sigdelset` and `sigismember` in libkernel wrote or read the guest signal set through the raw pointer, and a null set threw `std::invalid_argument` before the signal number was looked at. A non-null unusable pointer such as 0x10 faulted the host. They now copy the 16-byte set with `GuestCopyIn_nid_no_patch` / `GuestCopyOut_nid_no_patch` and fail with -1 and `EFAULT` when the set cannot be read or written. This is a host-safety fix, not console behaviour. FreeBSD 11.4's [`sigsetops.c`](https://github.com/freebsd/freebsd-src/blob/release/11.4.0/lib/libc/gen/sigsetops.c) works on the set in user space with no system call, so a bad pointer faults a console process and sets no errno; `EFAULT` was not measured on a console. The entry is in `docs/dev/debt/libkernel.md`. The signal check stays first, as in the source: `sigaddset`, `sigdelset` and `sigismember` with a signal outside 1 to 128 give `EINVAL` without touching the set, so a null set with signal 0 gives `EINVAL`, not `EFAULT`. `sigemptyset` and `sigfillset` have no error in the source and only report `EFAULT`. ### Tested Windows 11 (10.0.26200), WinLibs MinGW-w64 GCC 15.2.0 r7, Ninja, Release, `-DBUILD_TESTING=ON`, on current `main`. - `guest_signal_sets`: new `CheckBadPointers` covers a null set, 0x10, a `PROT_NONE` page, a read-only page (`sigismember` succeeds, the four writers fail and leave the set unchanged), a set straddling a readable and an unreadable page, and `EINVAL` before `EFAULT` for signals 0, -1 and 129. On `main` the test aborts; with this change it passes, three runs out of three. - Full suite (3918 tests) on this branch: 23 failed in the parallel run (GPU `agc_*` timeouts under load); rerun alone, 20 pass and 3 fail. `vulkan_validation_gate_reports` and `check_compile_test_windows_gcc_response_text_mode_is_not_reinterpreted` fail because of the WindowsApps Python on this machine, and `agc_driver_store_over_untracked` fails the same way with `SignalSets.cpp` reverted to `main`. - `python tools/check_conventions.py --base upstream/main`: passes. - Not tested: Linux, macOS, a console, a title run. ### Overlaps `tools/pr_overlap.py` reports no conflicting file or export. It lists #12682, #12688, #12700 and #12965 as sharing `SignalSets.cpp` and `GuestSignalSets.cpp` without comparing them, because those PRs conflict with `main` themselves; their hunks in `SignalSets.cpp` are in the `sigsetjmp` / `siglongjmp` assembly below the five functions changed here, and their test changes are elsewhere in `GuestSignalSets.cpp`, so there is no overlapping line. The other listed PRs only append to `docs/dev/debt/libkernel.md`. ### Checklist - [x] Based on current `main`; no other open PR implements the same function - [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`); no silent stubs added - [x] No notes, investigation `.md` files or images added to the repository - [x] New third-party code is a submodule built from source: none added - [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 AI-assisted (Claude Code). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
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!15508
No description provided.