fix(libkernel): reject alarm seconds beyond the itimer range #6945

Merged
MarcZX10 merged 1 commit from upstream-pr/6945 into main 2026-10-19 14:38:41 +00:00
MarcZX10 commented 2026-10-16 20:47:58 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-16T20:47:58Z.


What

Closes #6940. FreeBSD 11.4's alarm() delegates to setitimer(), which rejects it_value.tv_sec above INT32_MAX / 2 with EINVAL. The existing guest setitimer path already enforces that limit, but alarm() accepted larger unsigned values, replaced the pending timer, and returned its previous time.

Carries Hussein Kadhim's one-commit fix from the issue branch, preserving him as the commit author. The guest alarm() now sets errno to EINVAL and returns UINT_MAX before touching the timer state for out-of-range values. Regression coverage checks the boundary, invalid values, and preservation of an already pending alarm.

I manually reviewed the overlap notices. #3986 changes signal-mask handling elsewhere in Signals.cpp, not the alarm path. #6044 moves GuestGetitimer.cpp to tests/time/ with identical contents; if that reorganization merges first, this test change needs to be carried to the moved path. There is no behavioral dependency on either PR.

Tested

  • The issue reporter's Windows build ran guest_getitimer, guest_itimer, and guest_signals; all passed. The issue also records boundary/error probes, pending-alarm preservation, and main-versus-fix negative controls. One process-exit hang occurred once and did not recur in 15 fix runs or 12 main runs; its cause remains undetermined.
  • On Linux, the rebased head passes python3 tools/check_conventions.py --base upstream/main --head HEAD and git diff --check upstream/main...HEAD. I did not run the C++ tests: this checkout lacks the SDL2 submodule, and the host lacks XRandR development support.

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
  • 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
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4894092214 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6945). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-16T20:47:58Z. --- ### What Closes #6940. FreeBSD 11.4's `alarm()` delegates to `setitimer()`, which rejects `it_value.tv_sec` above `INT32_MAX / 2` with `EINVAL`. The existing guest `setitimer` path already enforces that limit, but `alarm()` accepted larger unsigned values, replaced the pending timer, and returned its previous time. Carries Hussein Kadhim's one-commit fix from the issue branch, preserving him as the commit author. The guest `alarm()` now sets `errno` to `EINVAL` and returns `UINT_MAX` before touching the timer state for out-of-range values. Regression coverage checks the boundary, invalid values, and preservation of an already pending alarm. I manually reviewed the overlap notices. #3986 changes signal-mask handling elsewhere in `Signals.cpp`, not the alarm path. #6044 moves `GuestGetitimer.cpp` to `tests/time/` with identical contents; if that reorganization merges first, this test change needs to be carried to the moved path. There is no behavioral dependency on either PR. ### Tested - The issue reporter's Windows build ran `guest_getitimer`, `guest_itimer`, and `guest_signals`; all passed. The issue also records boundary/error probes, pending-alarm preservation, and main-versus-fix negative controls. One process-exit hang occurred once and did not recur in 15 fix runs or 12 main runs; its cause remains undetermined. - On Linux, the rebased head passes `python3 tools/check_conventions.py --base upstream/main --head HEAD` and `git diff --check upstream/main...HEAD`. I did not run the C++ tests: this checkout lacks the SDL2 submodule, and the host lacks XRandR development support. ### 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) - [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] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
github-actions[bot] commented 2026-10-16 20:53:37 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-16T20:53:37Z.


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 3986 core/libs/prx/libkernel/System/src/Signals.cpp
PR 6044 core/libs/tests/GuestGetitimer.cpp
PR 7201 core/libs/prx/libkernel/System/src/Signals.cpp
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6224494296 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6945#issuecomment-6224494296). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-16T20:53:37Z. --- <!-- pr-overlap --> 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 3986](https://www.github.com/boykopovar/AnyPS5/pull/3986) | `core/libs/prx/libkernel/System/src/Signals.cpp` | | [PR 6044](https://www.github.com/boykopovar/AnyPS5/pull/6044) | `core/libs/tests/GuestGetitimer.cpp` | | [PR 7201](https://www.github.com/boykopovar/AnyPS5/pull/7201) | `core/libs/prx/libkernel/System/src/Signals.cpp` |
Dextroid17 commented 2026-10-16 21:59:55 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-16T21:59:55Z.


Linux run of this head, since the description says no local runtime result is claimed for it (the Windows results it cites are from #6940).

Setup: head e5c93279f (based on main 2fab88d10), Release, BUILD_TESTING=ON, CachyOS (kernel 7.2.9), i9-11900K, GCC 16.2.1. Tests ran under env -i with only HOME and PATH set (configure and build used the normal shell environment). Each arm ran ctest on guest_getitimer, guest_itimer and guest_signals 3 times.

  • Head: 3 of 3 pass in each of the 3 runs.
  • Repeat runs: guest_getitimer_tests run directly 50 more times on the head, each in its own process under timeout 30: 0 failures, none took over 10 s. The hang in #6940 was in a Windows probe run, which I did not run, so this says nothing about it; it only shows the test binary did not hang here.
  • Revert arm: with Signals.cpp as on 2fab88d10 and the PR's test changes kept, guest_getitimer fails 3 of 3 with an alarm beyond the itimer range did not fail with EINVAL, and the other 2 pass.
  • Merged with main at e9a3343a2: clean merge, 3 of 3 pass in each of the 3 runs.

Overlaps, by git merge-tree (not built):

  • #6044 (5fa62e596): no conflict in Signals.cpp or the test. In the merged tree the old test path is gone and the moved tests/time/GuestGetitimer.cpp is identical to this head's test. The 12 conflicts it reports (11 CMakeLists.txt files and core/libs/tests/exceptions/WindowsBacktraceReport.cpp) also appear when #6044 is merged with main alone.
  • #3986 (066b18da0): conflicts in Signals.cpp, GuestSignals.cpp and docs/dev/TechnicalDebt.md; the same 3 appear when #3986 is merged with main alone.

By reading, the new check matches the FreeBSD 11.4 rule quoted in #6940 (kern_setitimer returns EINVAL for tv_sec > INT32_MAX / 2 before the timer changes). Here the guest alarm (libSceLibcInternal) calls GuestAlarm_nid_no_patch, which now applies that bound itself.

Not checked: Windows and macOS on this head; the pending-alarm checks against the old Signals.cpp (the revert arm aborts at the first EINVAL check, before them); the setitimer limit (unchanged here); behaviour on PS5 hardware.

Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6225506654 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6945#issuecomment-6225506654). Originally posted by [Dextroid17](https://github.com/Dextroid17) on 2026-10-16T21:59:55Z. --- Linux run of this head, since the description says no local runtime result is claimed for it (the Windows results it cites are from #6940). **Setup:** head `e5c93279f` (based on `main` `2fab88d10`), Release, `BUILD_TESTING=ON`, CachyOS (kernel 7.2.9), i9-11900K, GCC 16.2.1. Tests ran under `env -i` with only `HOME` and `PATH` set (configure and build used the normal shell environment). Each arm ran `ctest` on `guest_getitimer`, `guest_itimer` and `guest_signals` 3 times. - **Head:** 3 of 3 pass in each of the 3 runs. - **Repeat runs:** `guest_getitimer_tests` run directly 50 more times on the head, each in its own process under `timeout 30`: 0 failures, none took over 10 s. The hang in #6940 was in a Windows probe run, which I did not run, so this says nothing about it; it only shows the test binary did not hang here. - **Revert arm:** with `Signals.cpp` as on `2fab88d10` and the PR's test changes kept, `guest_getitimer` fails 3 of 3 with `an alarm beyond the itimer range did not fail with EINVAL`, and the other 2 pass. - **Merged with `main` at `e9a3343a2`:** clean merge, 3 of 3 pass in each of the 3 runs. Overlaps, by `git merge-tree` (not built): - **#6044** (`5fa62e596`): no conflict in `Signals.cpp` or the test. In the merged tree the old test path is gone and the moved `tests/time/GuestGetitimer.cpp` is identical to this head's test. The 12 conflicts it reports (11 `CMakeLists.txt` files and `core/libs/tests/exceptions/WindowsBacktraceReport.cpp`) also appear when #6044 is merged with `main` alone. - **#3986** (`066b18da0`): conflicts in `Signals.cpp`, `GuestSignals.cpp` and `docs/dev/TechnicalDebt.md`; the same 3 appear when #3986 is merged with `main` alone. By reading, the new check matches the FreeBSD 11.4 rule quoted in #6940 (`kern_setitimer` returns `EINVAL` for `tv_sec > INT32_MAX / 2` before the timer changes). Here the guest `alarm` (libSceLibcInternal) calls `GuestAlarm_nid_no_patch`, which now applies that bound itself. Not checked: Windows and macOS on this head; the pending-alarm checks against the old `Signals.cpp` (the revert arm aborts at the first EINVAL check, before them); the `setitimer` limit (unchanged here); behaviour on PS5 hardware. Written with AI assistance (Claude Code). I ran the builds and tests above on my machine. AI-assisted: yes
MarcZX10 commented 2026-10-16 22:14:40 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-16T22:14:40Z.


Thanks for the independent Linux validation. The three repeated runs and 50 extra process launches passed on this head, while reverting the Signals.cpp change consistently reproduces the out-of-range alarm failure. The merged-main runs and overlap analysis with #6044/#3986 are helpful; I have noted that Windows/macOS, the pending-alarm checks against the old source, setitimer, and PS5 hardware remain untested in your report. I have not run those checks locally.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6225722147 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6945#issuecomment-6225722147). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-16T22:14:40Z. --- Thanks for the independent Linux validation. The three repeated runs and 50 extra process launches passed on this head, while reverting the `Signals.cpp` change consistently reproduces the out-of-range `alarm` failure. The merged-main runs and overlap analysis with #6044/#3986 are helpful; I have noted that Windows/macOS, the pending-alarm checks against the old source, `setitimer`, and PS5 hardware remain untested in your report. I have not run those checks locally.
MarcZX10 commented 2026-10-18 00:01:23 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-18T00:01:23Z.


Rebased onto current main a8581d333. The conflict was from an already-defined GuestSigalrm; I retained that definition and moved the shared MaxItimerSeconds bound into scope before both alarm() and setitimer() use it. The carried commit still preserves Hussein Kadhim as author. Linux syntax checks for Signals.cpp and GuestGetitimer.cpp and the conventions check pass. Current hosted eligibility/conventions/report checks pass; platform build/test jobs are skipped by path filters.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6243464156 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6945#issuecomment-6243464156). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-18T00:01:23Z. --- Rebased onto current main `a8581d333`. The conflict was from an already-defined `GuestSigalrm`; I retained that definition and moved the shared `MaxItimerSeconds` bound into scope before both `alarm()` and `setitimer()` use it. The carried commit still preserves Hussein Kadhim as author. Linux syntax checks for `Signals.cpp` and `GuestGetitimer.cpp` and the conventions check pass. Current hosted eligibility/conventions/report checks pass; platform build/test jobs are skipped by path filters.
MarcZX10 commented 2026-10-18 05:05:07 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-18T05:05:07Z.


I built guest_getitimer_tests from current main plus this change with GCC 12. The binary links successfully, but ctest -R '^guest_getitimer$' aborts before its assertions at the emulator's host CPU feature guard: this Xeon E5-1620 v2 lacks LZCNT, BMI1/BMI2, MOVBE, AVX2 and FMA. So I cannot independently confirm the test assertions on this Linux host; Dextroid17's separate Linux runs reported 3/3 passes on a newer CPU.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6245926477 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6945#issuecomment-6245926477). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-18T05:05:07Z. --- I built `guest_getitimer_tests` from current `main` plus this change with GCC 12. The binary links successfully, but `ctest -R '^guest_getitimer$'` aborts before its assertions at the emulator's host CPU feature guard: this Xeon E5-1620 v2 lacks LZCNT, BMI1/BMI2, MOVBE, AVX2 and FMA. So I cannot independently confirm the test assertions on this Linux host; Dextroid17's separate Linux runs reported 3/3 passes on a newer CPU.
jotitadev commented 2026-10-18 10:09:48 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-18T10:09:48Z.

Review: COMMENTED


Run on the rebased head d6190d9a0, which the author's host cannot execute (CPU guard). The earlier Linux run in this thread was on e5c93279f, before the Signals.cpp conflict was resolved.

Machine: Linux x86_64, i7-8700, Ubuntu 26.04, GCC 15.2, Release, BUILD_TESTING=ON, full build.
Head d6190d9a0 merged onto main 9caecfd2d (clean merge).

  • guest_getitimer passes, as do the other timer and signal tests (ctest -R "itimer|signal|alarm", 7 tests). With the shared MaxItimerSeconds now above alarm(), an alarm of INT_MAX / 2 is accepted, INT_MAX / 2 + 1, INT_MAX and UINT_MAX return -1 with errno 22 and leave the pending alarm alone. guest_itimer (the setitimer() side of the moved constant) also passes.
  • GuestGetitimer.cpp only, on main: fails at an alarm beyond the itimer range did not fail with EINVAL, so the test still covers the change after the rebase.
  • Non-GPU suite (ctest -E "^agc|gpu|vulkan|video_out"): 712/712, same as main.

Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5562495764 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6945#pullrequestreview-5562495764). Originally posted by [jotitadev](https://github.com/jotitadev) on 2026-10-18T10:09:48Z. **Review:** COMMENTED --- Run on the rebased head `d6190d9a0`, which the author's host cannot execute (CPU guard). The earlier Linux run in this thread was on `e5c93279f`, before the `Signals.cpp` conflict was resolved. Machine: Linux x86_64, i7-8700, Ubuntu 26.04, GCC 15.2, Release, `BUILD_TESTING=ON`, full build. Head `d6190d9a0` merged onto `main` `9caecfd2d` (clean merge). - `guest_getitimer` passes, as do the other timer and signal tests (`ctest -R "itimer|signal|alarm"`, 7 tests). With the shared `MaxItimerSeconds` now above `alarm()`, an alarm of `INT_MAX / 2` is accepted, `INT_MAX / 2 + 1`, `INT_MAX` and `UINT_MAX` return -1 with errno 22 and leave the pending alarm alone. `guest_itimer` (the `setitimer()` side of the moved constant) also passes. - `GuestGetitimer.cpp` only, on `main`: fails at `an alarm beyond the itimer range did not fail with EINVAL`, so the test still covers the change after the rebase. - Non-GPU suite (`ctest -E "^agc|gpu|vulkan|video_out"`): 712/712, same as `main`. Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
MarcZX10 commented 2026-10-18 15:08:43 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-18T15:08:43Z.

Review: COMMENTED


Carried the issue's tested alarm fix onto current , preserving Hussein Kadhim as the commit author. The rebased patch passes conventions, eligibility, and report checks; all platform matrix jobs were skipped by path filters. The issue reporter's Windows suite and boundary probes are documented in the PR, including the unexplained one-off process-exit hang. I did not run the C++ tests locally.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5563602852 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6945#pullrequestreview-5563602852). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-18T15:08:43Z. **Review:** COMMENTED --- Carried the issue's tested alarm fix onto current , preserving Hussein Kadhim as the commit author. The rebased patch passes conventions, eligibility, and report checks; all platform matrix jobs were skipped by path filters. The issue reporter's Windows suite and boundary probes are documented in the PR, including the unexplained one-off process-exit hang. I did not run the C++ tests locally.
MarcZX10 commented 2026-10-18 15:08:47 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-18T15:08:47Z.

Review: COMMENTED


Carried the issue tested alarm fix onto the current upstream main, preserving Hussein Kadhim as the commit author. The rebased patch passes conventions, eligibility, and report checks; all platform matrix jobs were skipped by path filters. The issue reporter Windows suite and boundary probes are documented in the PR, including the unexplained one-off process-exit hang. I did not run the C++ tests locally.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5563603172 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6945#pullrequestreview-5563603172). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-18T15:08:47Z. **Review:** COMMENTED --- Carried the issue tested alarm fix onto the current upstream main, preserving Hussein Kadhim as the commit author. The rebased patch passes conventions, eligibility, and report checks; all platform matrix jobs were skipped by path filters. The issue reporter Windows suite and boundary probes are documented in the PR, including the unexplained one-off process-exit hang. I did not run the C++ tests locally.
adriadam10 commented 2026-10-19 14:39:40 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-19T14:39:40Z.


Checked alarm() against FreeBSD kern_setitimer (tv_sec > INT32_MAX / 2 → EINVAL) and the shared MaxItimerSeconds with setitimer; the test pins the boundary, the rejected values and the preserved pending alarm; Linux runs by @Dextroid17 and @jotitadev cover it; merged.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6269879629 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6945#issuecomment-6269879629). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-19T14:39:40Z. --- Checked `alarm()` against FreeBSD `kern_setitimer` (`tv_sec > INT32_MAX / 2` → `EINVAL`) and the shared `MaxItimerSeconds` with `setitimer`; the test pins the boundary, the rejected values and the preserved pending alarm; Linux runs by @Dextroid17 and @jotitadev cover it; merged.
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!6945
No description provided.