fix(libkernel): check settimeofday and clock_settime pointers #11402

Merged
00xDisaster merged 1 commit from upstream-pr/11402 into main 2026-10-27 08:25:30 +00:00
00xDisaster commented 2026-10-26 10:56:58 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by 00xDisaster on 2026-10-26T10:56:58Z.


What

clock_settime read the caller's timespec in place, and settimeofday read its timeval and timezone in place, so a pointer into unmapped memory crashed the host. Both now copy the structures in with a checked read first, as FreeBSD 11.4's sys_clock_settime and sys_settimeofday do, and return EFAULT before validation when a non-null pointer is unreadable. clock_settime still returns EFAULT for a null time, and settimeofday still treats a null argument as omitted. This keeps EFAULT ahead of EINVAL and keeps an unreadable time zone from being stored.

The checked read is independent of #10975, which adds a shared GuestCopyIn helper for the getters and setitimer but not these setters. clock_settime overlaps #11042, which replaces the valid-time descriptive throw with NotImplemented_nid_no_patch and changes the same clock test. The merged function keeps this PR's copy, EFAULT and EINVAL order, then #11042's NotImplemented path for a valid request; neither change replaces the other. #9677 adds a GuestTime.hpp include in Time.cpp; #9713 adds includes and ThreadAndSessionTests in GuestKernelSys.cpp. Those are merge-order conflicts only.

Merge order proposal: this PR first, then #9677, #11042 and #9713 rebase and keep both sides. No code dependency is required.

Tested

Linux x86_64, GCC 16.2.1, Release build, base upstream/main 4b1a9a3b2f; head 78571ca2fb. guest_freebsd_clocks and guest_kernel_sys pass 2/2 with new cases that pass 1 as the time, time zone, or both pointers:

  • clock_settime returns -1/EFAULT for an unreadable time with both a valid and an invalid clock.
  • settimeofday returns -1/EFAULT for an unreadable time, an unreadable zone, both, and a valid time with an unreadable zone.
  • An unreadable zone returns EFAULT before invalid time values return EINVAL.
  • The stored zone is unchanged after each failure.

Negative control with upstream/main 4b1a9a3b2f Time.cpp and the tests from this head: guest_freebsd_clocks and guest_kernel_sys both fail with Exception: SegFault at the first unreadable pointer. Tests were not run on Windows, macOS, the console, or a title.

Checklist

  • Based on current main; no other open PR adds the checked reads; #11042 changes the valid clock_settime tail and is preserved on rebase
  • 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 (merge order only: #9677, #11042 and #9713 after this PR; no code dependency)
  • Fixes: #11370
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: no
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5016256084 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11402). Originally posted by [00xDisaster](https://github.com/00xDisaster) on 2026-10-26T10:56:58Z. --- ### What `clock_settime` read the caller's `timespec` in place, and `settimeofday` read its `timeval` and `timezone` in place, so a pointer into unmapped memory crashed the host. Both now copy the structures in with a checked read first, as FreeBSD 11.4's `sys_clock_settime` and `sys_settimeofday` do, and return `EFAULT` before validation when a non-null pointer is unreadable. `clock_settime` still returns `EFAULT` for a null time, and `settimeofday` still treats a null argument as omitted. This keeps `EFAULT` ahead of `EINVAL` and keeps an unreadable time zone from being stored. The checked read is independent of #10975, which adds a shared `GuestCopyIn` helper for the getters and `setitimer` but not these setters. `clock_settime` overlaps #11042, which replaces the valid-time descriptive throw with `NotImplemented_nid_no_patch` and changes the same clock test. The merged function keeps this PR's copy, `EFAULT` and `EINVAL` order, then #11042's `NotImplemented` path for a valid request; neither change replaces the other. #9677 adds a `GuestTime.hpp` include in `Time.cpp`; #9713 adds includes and `ThreadAndSessionTests` in `GuestKernelSys.cpp`. Those are merge-order conflicts only. Merge order proposal: this PR first, then #9677, #11042 and #9713 rebase and keep both sides. No code dependency is required. ### Tested Linux x86_64, GCC 16.2.1, Release build, base `upstream/main` `4b1a9a3b2f`; head `78571ca2fb`. `guest_freebsd_clocks` and `guest_kernel_sys` pass 2/2 with new cases that pass `1` as the time, time zone, or both pointers: - `clock_settime` returns `-1`/`EFAULT` for an unreadable time with both a valid and an invalid clock. - `settimeofday` returns `-1`/`EFAULT` for an unreadable time, an unreadable zone, both, and a valid time with an unreadable zone. - An unreadable zone returns `EFAULT` before invalid time values return `EINVAL`. - The stored zone is unchanged after each failure. Negative control with `upstream/main` `4b1a9a3b2f` `Time.cpp` and the tests from this head: `guest_freebsd_clocks` and `guest_kernel_sys` both fail with `Exception: SegFault` at the first unreadable pointer. Tests were not run on Windows, macOS, the console, or a title. ### Checklist - [x] Based on current `main`; no other open PR adds the checked reads; #11042 changes the valid `clock_settime` tail and is preserved on rebase - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except technical debt - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's technical 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 (merge order only: #9677, #11042 and #9713 after this PR; no code dependency) - [x] Fixes: #11370 - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: no
MarcZX10 commented 2026-10-26 11:24:28 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-26T11:24:28Z.

Review: CHANGES_REQUESTED


Changes requested for the stale base and unresolved file-level integrations described in my comment. I have not run a full review vote on the merged behavior until the branch is current and the overlapping clock_settime edits are coordinated.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5651221074 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11402#pullrequestreview-5651221074). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-26T11:24:28Z. **Review:** CHANGES_REQUESTED --- Changes requested for the stale base and unresolved file-level integrations described in my comment. I have not run a full review vote on the merged behavior until the branch is current and the overlapping clock_settime edits are coordinated.
MarcZX10 commented 2026-10-26 11:37:25 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-26T11:37:25Z.

Review: APPROVED


Re-reviewed exact head 78571ca2fb against current main 4b1a9a3b2f. The checked copies happen before clock/value validation, preserving EFAULT precedence; settimeofday only updates the stored timezone after both requested structures are readable, and the added cases cover unreadable time/zone pointers and unchanged state. The author reports guest_freebsd_clocks and guest_kernel_sys passing 2/2 on Linux, plus a negative control that segfaults on the same pointers with main. Hosted product jobs are skipped by path policy. I independently inspected the Linux, Windows, and macOS checked-copy branches and the existing GuestArena read hook. No blocking correctness issue found. Integration note: #11042 author agreed to rebase after this PR and keep the NotImplemented path for valid clock_settime; #9677 and #9713 make separate edits in shared files, so preserve their additions when they rebase.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5651351503 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11402#pullrequestreview-5651351503). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-26T11:37:25Z. **Review:** APPROVED --- Re-reviewed exact head 78571ca2fb9fcfed62e3de7ebfb4b4071a3fe1d4 against current main 4b1a9a3b2f. The checked copies happen before clock/value validation, preserving EFAULT precedence; settimeofday only updates the stored timezone after both requested structures are readable, and the added cases cover unreadable time/zone pointers and unchanged state. The author reports guest_freebsd_clocks and guest_kernel_sys passing 2/2 on Linux, plus a negative control that segfaults on the same pointers with main. Hosted product jobs are skipped by path policy. I independently inspected the Linux, Windows, and macOS checked-copy branches and the existing GuestArena read hook. No blocking correctness issue found. Integration note: #11042 author agreed to rebase after this PR and keep the NotImplemented path for valid clock_settime; #9677 and #9713 make separate edits in shared files, so preserve their additions when they rebase.
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!11402
No description provided.