fix(libkernel): fail the time getters and setitimer with EFAULT on an unmapped pointer #10978

Closed
AdnanKhan-ak47 wants to merge 1 commit from upstream-pr/10978 into main
AdnanKhan-ak47 commented 2026-10-25 11:51:39 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by AdnanKhan-ak47 on 2026-10-25T11:51:39Z.


What

gettimeofday, sceKernelGettimeofday, sceKernelGettimezone, getitimer and setitimer fail with EFAULT (0x8002000e for the sceKernel forms) when a pointer argument is unmapped, as FreeBSD's copyin and copyout make sys_gettimeofday, sys_getitimer and sys_setitimer fail, instead of crashing the host. The null checks already in place stay as they were.

The outputs go through GuestCopyOut_nid_no_patch, which fstat and the descriptor calls already use. setitimer reads its value through a new GuestCopyIn_nid_no_patch in libc, the read counterpart of the existing checked write: ReadProcessMemory on Windows, process_vm_readv on Linux and mach_vm_read_overwrite on macOS, after GuestArenaPrepareHostRead. setitimer keeps FreeBSD's order, copyin then EINVAL checks then set then copyout, so a previous pointer that fails after the timer was set leaves it set, as sys_setitimer does; the regression probes that path with a disarming value. gettimeofday computes the time once into a local and copies it out, which is what let sceKernelGettimeofday answer its own error code.

GuestFreebsdClocks.cpp, GuestGetitimer.cpp and GuestItimer.cpp probe the issue's two addresses, 1 and 0xfffffffffffff000, on every pointer parameter and check that a failed call writes nothing to the other output.

Tested

Arch Linux x86-64, GCC 16.2.1: ctest -R '^guest_(freebsd_clocks|getitimer|itimer)$' 3/3 pass; with main's Time.cpp and Signals.cpp restored, all three fail with SegFault. tools/check_conventions.py --base origin/main clean. tools/pr_overlap.py reports #10499, which changes the body of sceKernelGettimezone to report host zone offsets; this PR changes the same two lines to a checked copy-out, so whichever lands second rebases that body. Windows and macOS not run; the copy helpers are the ones GuestCopyOut and the getrlimit fix (#8986) already exercise there.

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: #10969
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5004483115 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10978). Originally posted by [AdnanKhan-ak47](https://github.com/AdnanKhan-ak47) on 2026-10-25T11:51:39Z. --- ### What `gettimeofday`, `sceKernelGettimeofday`, `sceKernelGettimezone`, `getitimer` and `setitimer` fail with `EFAULT` (`0x8002000e` for the sceKernel forms) when a pointer argument is unmapped, as FreeBSD's `copyin` and `copyout` make `sys_gettimeofday`, `sys_getitimer` and `sys_setitimer` fail, instead of crashing the host. The null checks already in place stay as they were. The outputs go through `GuestCopyOut_nid_no_patch`, which `fstat` and the descriptor calls already use. `setitimer` reads its value through a new `GuestCopyIn_nid_no_patch` in libc, the read counterpart of the existing checked write: `ReadProcessMemory` on Windows, `process_vm_readv` on Linux and `mach_vm_read_overwrite` on macOS, after `GuestArenaPrepareHostRead`. `setitimer` keeps FreeBSD's order, copyin then `EINVAL` checks then set then copyout, so a `previous` pointer that fails after the timer was set leaves it set, as `sys_setitimer` does; the regression probes that path with a disarming value. `gettimeofday` computes the time once into a local and copies it out, which is what let `sceKernelGettimeofday` answer its own error code. `GuestFreebsdClocks.cpp`, `GuestGetitimer.cpp` and `GuestItimer.cpp` probe the issue's two addresses, `1` and `0xfffffffffffff000`, on every pointer parameter and check that a failed call writes nothing to the other output. ### Tested Arch Linux x86-64, GCC 16.2.1: `ctest -R '^guest_(freebsd_clocks|getitimer|itimer)$'` 3/3 pass; with `main`'s `Time.cpp` and `Signals.cpp` restored, all three fail with `SegFault`. `tools/check_conventions.py --base origin/main` clean. `tools/pr_overlap.py` reports #10499, which changes the body of `sceKernelGettimezone` to report host zone offsets; this PR changes the same two lines to a checked copy-out, so whichever lands second rebases that body. Windows and macOS not run; the copy helpers are the ones `GuestCopyOut` and the `getrlimit` fix (#8986) already exercise there. ### 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: #10969 - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
MarcZX10 commented 2026-10-25 11:53:17 +00:00 (Migrated from github.com)

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

Review: CHANGES_REQUESTED


Requesting changes for contribution coordination: #10975 was already open and implements the same six time-related exports, adds the same checked GuestCopyIn/GuestCopyOut helpers, and also declares Fixes: #10969. This PR independently changes those same exports and fixes the same issue, so the checklist statement that no open PR implements the same functions is no longer accurate. The repository asks authors of overlapping PRs to agree which one goes first and declare Depends on when one builds on the other.

There is useful distinct work here: this PR adds the checked macOS mach_vm_read_overwrite path that the current #10975 head is missing. Please coordinate with the #10975 author and maintainers on one implementation path, preserving that macOS fix and its tests without leaving two competing implementations of the same exports. Update the dependency/fix checklist and rebase the selected path once that order is agreed. I have not approved either implementation pending that coordination; the Linux and Windows-focused evidence does not settle the macOS runtime case.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5643092359 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10978#pullrequestreview-5643092359). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-25T11:53:17Z. **Review:** CHANGES_REQUESTED --- Requesting changes for contribution coordination: #10975 was already open and implements the same six time-related exports, adds the same checked `GuestCopyIn`/`GuestCopyOut` helpers, and also declares `Fixes: #10969`. This PR independently changes those same exports and fixes the same issue, so the checklist statement that no open PR implements the same functions is no longer accurate. The repository asks authors of overlapping PRs to agree which one goes first and declare `Depends on` when one builds on the other. There is useful distinct work here: this PR adds the checked macOS `mach_vm_read_overwrite` path that the current #10975 head is missing. Please coordinate with the #10975 author and maintainers on one implementation path, preserving that macOS fix and its tests without leaving two competing implementations of the same exports. Update the dependency/fix checklist and rebase the selected path once that order is agreed. I have not approved either implementation pending that coordination; the Linux and Windows-focused evidence does not settle the macOS runtime case.

Pull request closed

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!10978
No description provided.