fix(libkernel): fail gettimeofday, getitimer, setitimer and the sceKernel time getters with EFAULT on an unusable pointer #10975

Merged
xXPBSXx merged 9 commits from upstream-pr/10975 into main 2026-10-28 00:02:14 +00:00
xXPBSXx commented 2026-10-25 11:46:20 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-25T11:46:20Z.


What

The six functions compute into a local and copy out with the checked write from #9618 (GuestCopyOut_nid_no_patch); setitimer reads its value with a new checked read, GuestCopyIn_nid_no_patch. They fail with EFAULT (guest 14, or 0x8002000E from the sceKernel forms). The order of the existing error checks is unchanged. sceKernelGettimeofday now returns 0x8002000E instead of -1 when the copy-out fails.

Fixes: #10969

Tested

New guest_output_pointer_fault: bad pointers 1 and 0xfffffffffffff000 through gettimeofday (both pointers), getitimer, setitimer (value and previous), sceKernelGettimeofday and sceKernelGettimezone expect -1/EFAULT and 0x8002000E; a valid pointer still succeeds. Head c8430e739c on main 66e6772ca2; git merge-tree against current main a5a780eaaa is clean:

  • Windows 10, MinGW-w64 GCC 15.2, Release: the build succeeds and 8 of 8 tests pass: guest_output_pointer_fault, guest_fstat_fault, guest_freebsd_clocks, guest_getitimer, guest_itimer, guest_itimer_pending_default, guest_system_configuration and the public_headers audit. With General.hpp, General.cpp, Signals.cpp and Time.cpp taken from main and the test kept, guest_output_pointer_fault fails with a SegFault.
  • Ubuntu 24.04 under WSL2 (a virtualised kernel, not bare-metal), GCC 13.3, Release: the build succeeds and the same 8 of 8 pass; with the same four files from main, guest_output_pointer_fault fails with a SegFault.
  • check_conventions --base upstream/main passes.
  • Run by others on macOS (Apple M5 Pro, macOS 27.2, Apple clang 21, x86-64 Release under Rosetta 2, main 801d5b9bc1 plus the open macOS build PRs, this PR's diff on top, three runs per row; GuestCopyIn_nid_no_patch and GuestCopyOut_nid_no_patch go through mach_vm_read_overwrite and mach_vm_write there): guest_output_pointer_fault passes with this PR and crashes with a segmentation fault when General.hpp, General.cpp, Signals.cpp and Time.cpp are restored from the base; guest_getitimer, guest_itimer, guest_itimer_pending_default, guest_time_conversion and guest_time_extras pass either way, on head 78cb208c0c (comment).
  • Run by others on Windows (Windows 11 Home 10.0.26200, WinLibs GCC 15.2.0 r7 (MinGW-w64 UCRT), Release, BUILD_TESTING=ON) on the current head 78cb208c0c merged onto main c547deaacb: guest_output_pointer_fault_tests builds without errors and guest_output_pointer_fault passes both runs of ctest --repeat until-fail:2; with main's General.hpp, General.cpp, Signals.cpp and Time.cpp and the rest of this head it crashes with 0xc0000005. The other tests of this description's set, macOS and a title were not run there (comment).

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

AI-assisted (Claude Code).

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5004444240 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10975). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-25T11:46:20Z. --- ### What The six functions compute into a local and copy out with the checked write from #9618 (`GuestCopyOut_nid_no_patch`); `setitimer` reads its value with a new checked read, `GuestCopyIn_nid_no_patch`. They fail with EFAULT (guest 14, or `0x8002000E` from the sceKernel forms). The order of the existing error checks is unchanged. `sceKernelGettimeofday` now returns `0x8002000E` instead of -1 when the copy-out fails. Fixes: #10969 ### Tested New `guest_output_pointer_fault`: bad pointers `1` and `0xfffffffffffff000` through `gettimeofday` (both pointers), `getitimer`, `setitimer` (value and previous), `sceKernelGettimeofday` and `sceKernelGettimezone` expect -1/EFAULT and `0x8002000E`; a valid pointer still succeeds. Head `c8430e739c` on `main` `66e6772ca2`; `git merge-tree` against current `main` `a5a780eaaa` is clean: - Windows 10, MinGW-w64 GCC 15.2, Release: the build succeeds and 8 of 8 tests pass: `guest_output_pointer_fault`, `guest_fstat_fault`, `guest_freebsd_clocks`, `guest_getitimer`, `guest_itimer`, `guest_itimer_pending_default`, `guest_system_configuration` and the `public_headers` audit. With `General.hpp`, `General.cpp`, `Signals.cpp` and `Time.cpp` taken from `main` and the test kept, `guest_output_pointer_fault` fails with a SegFault. - Ubuntu 24.04 under WSL2 (a virtualised kernel, not bare-metal), GCC 13.3, Release: the build succeeds and the same 8 of 8 pass; with the same four files from `main`, `guest_output_pointer_fault` fails with a SegFault. - `check_conventions --base upstream/main` passes. - Run by others on macOS (Apple M5 Pro, macOS 27.2, Apple clang 21, x86-64 Release under Rosetta 2, `main` `801d5b9bc1` plus the open macOS build PRs, this PR's diff on top, three runs per row; `GuestCopyIn_nid_no_patch` and `GuestCopyOut_nid_no_patch` go through `mach_vm_read_overwrite` and `mach_vm_write` there): `guest_output_pointer_fault` passes with this PR and crashes with a segmentation fault when `General.hpp`, `General.cpp`, `Signals.cpp` and `Time.cpp` are restored from the base; `guest_getitimer`, `guest_itimer`, `guest_itimer_pending_default`, `guest_time_conversion` and `guest_time_extras` pass either way, on head `78cb208c0c` ([comment](https://github.com/boykopovar/AnyPS5/pull/10975#issuecomment-6444203330)). - Run by others on Windows (Windows 11 Home 10.0.26200, WinLibs GCC 15.2.0 r7 (MinGW-w64 UCRT), Release, `BUILD_TESTING=ON`) on the current head `78cb208c0c` merged onto `main` `c547deaacb`: `guest_output_pointer_fault_tests` builds without errors and `guest_output_pointer_fault` passes both runs of `ctest --repeat until-fail:2`; with `main`'s `General.hpp`, `General.cpp`, `Signals.cpp` and `Time.cpp` and the rest of this head it crashes with `0xc0000005`. The other tests of this description's set, macOS and a title were not run there ([comment](https://github.com/boykopovar/AnyPS5/pull/10975#issuecomment-6447656339)). ### Checklist - [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 AI-assisted (Claude Code). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
MarcZX10 commented 2026-10-25 11:48:49 +00:00 (Migrated from github.com)

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

Review: CHANGES_REQUESTED


Requesting changes: GuestCopyIn_nid_no_patch has checked-copy implementations for Windows and Linux, but on macOS it falls through to the unconditional std::memcpy at core/libs/prx/libc/src/General.cpp:865-867. The new setitimer path calls this helper for the guest value pointer. Therefore the PR's setitimer_nid_postfix(0, badTimer, ...) regression case will dereference the deliberately unmapped pointer and fault the host on macOS instead of returning -1/EFAULT. GuestCopyOut_nid_no_patch already has a macOS mach_vm_write path, but the read helper does not have the corresponding checked read.

Please add a checked macOS read (for example using the appropriate Mach VM read API and validating that the full requested byte count was copied), or use an existing cross-platform guest-memory copy primitive. Then run guest_output_pointer_fault on macOS or provide a focused result showing both invalid source addresses return EFAULT without terminating the process. The current Windows and WSL2 results do not cover this host-specific branch.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5643066205 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10975#pullrequestreview-5643066205). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-25T11:48:49Z. **Review:** CHANGES_REQUESTED --- Requesting changes: `GuestCopyIn_nid_no_patch` has checked-copy implementations for Windows and Linux, but on macOS it falls through to the unconditional `std::memcpy` at `core/libs/prx/libc/src/General.cpp:865-867`. The new `setitimer` path calls this helper for the guest `value` pointer. Therefore the PR's `setitimer_nid_postfix(0, badTimer, ...)` regression case will dereference the deliberately unmapped pointer and fault the host on macOS instead of returning `-1`/`EFAULT`. `GuestCopyOut_nid_no_patch` already has a macOS `mach_vm_write` path, but the read helper does not have the corresponding checked read. Please add a checked macOS read (for example using the appropriate Mach VM read API and validating that the full requested byte count was copied), or use an existing cross-platform guest-memory copy primitive. Then run `guest_output_pointer_fault` on macOS or provide a focused result showing both invalid source addresses return EFAULT without terminating the process. The current Windows and WSL2 results do not cover this host-specific branch.
MarcZX10 commented 2026-10-25 12:36:57 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T12:36:57Z.

Review: CHANGES_REQUESTED


Requesting one change in the new GuestCopyIn_nid_no_patch helper. On Linux, if process_vm_readv fails with anything other than EFAULT, the helper falls back to std::memcpy(source, bytes). For an invalid source pointer, an EPERM/ENOSYS result (for example, if the syscall is blocked or unavailable) therefore dereferences the untrusted pointer and recreates the host crash this PR is meant to prevent. The existing GuestCopyOut_nid_no_patch treats non-EFAULT syscall failures as infrastructure errors instead of using an unchecked copy. Please use a similarly safe failure path here (or return failure if that is the intended guest-visible behavior) and cover the non-EFAULT syscall failure path.

I reviewed the exact diff and verified that the existing null-output getitimer guard remains in GetitimerInto; this finding is only about the Linux copy-in fallback. The PR's Windows and WSL2 runtime results are author-reported; I did not run the full CMake tests locally.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5643223795 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10975#pullrequestreview-5643223795). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-25T12:36:57Z. **Review:** CHANGES_REQUESTED --- Requesting one change in the new `GuestCopyIn_nid_no_patch` helper. On Linux, if `process_vm_readv` fails with anything other than `EFAULT`, the helper falls back to `std::memcpy(source, bytes)`. For an invalid source pointer, an `EPERM`/`ENOSYS` result (for example, if the syscall is blocked or unavailable) therefore dereferences the untrusted pointer and recreates the host crash this PR is meant to prevent. The existing `GuestCopyOut_nid_no_patch` treats non-`EFAULT` syscall failures as infrastructure errors instead of using an unchecked copy. Please use a similarly safe failure path here (or return failure if that is the intended guest-visible behavior) and cover the non-`EFAULT` syscall failure path. I reviewed the exact diff and verified that the existing null-output `getitimer` guard remains in `GetitimerInto`; this finding is only about the Linux copy-in fallback. The PR's Windows and WSL2 runtime results are author-reported; I did not run the full CMake tests locally.
ahmadmuj commented 2026-10-25 13:16:16 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ahmadmuj on 2026-10-25T13:16:16Z.

Review: COMMENTED


Reviewed head d69520c794feeaaddcd5cbd409dd738fb6ae4504 (base 66e6772ca2094b665488d6ca5cbae3f6fb0c5034). git merge-tree onto current main 4017310678562c63594d99b8f45db2d68b9aaa6c is clean.

What I ran, WSL2 Ubuntu 24.04, GCC 13.3, Release:

  • Built only the focused targets. guest_output_pointer_fault, guest_fstat_fault, guest_freebsd_clocks, guest_getitimer, guest_itimer, guest_itimer_pending_default, guest_system_configuration, guest_time_extras, guest_kernel_sys_ktimer and public_headers pass 10/10. The four timer/fault tests also pass 20/20 with --repeat until-fail:20. check_conventions.py passes.
  • Red check 1: Signals.cpp and Time.cpp back to base, test kept. guest_output_pointer_fault dies with SIGSEGV.
  • Red check 2: General.cpp from 4ab1636 (the memcpy fallback on a non-EFAULT process_vm_readv error). The seccomp child fails at line 59, so that test does catch the EPERM case.
  • Compared against FreeBSD releng/11.4 sys/kern/kern_time.c. gettimeofday copies tp first, then tzp only if that worked (L644-652). getitimer checks which before the copyout (L754, L745). setitimer with itv == NULL forwards to getitimer (L797-800), and copies oitv out after the timer is armed (L805-808). Your code matches all of that, and the test pins the armed-then-EFAULT case.

One suggestion:

GuestCopyIn_nid_no_patch re-implements CopyGuestBytes from the same file (General.cpp:86-104), which is already a checked read on every host. The copies differ in two places. In #else, GuestCopyIn does a raw memcpy and returns true, while CopyGuestBytes and GuestCopyOut both throw there (CONTRIBUTING: does what it should or throws). On Windows it does VirtualQuery then memcpy, while CopyGuestBytes uses ReadProcessMemory, which can't race with an unmap between the check and the copy. Keeping your null/overflow guard and delegating works:

extern "C" bool GuestCopyIn_nid_no_patch(void* destination, const void* source, std::size_t bytes) {
    if (bytes == 0) return true;
    const auto start = reinterpret_cast<std::uintptr_t>(source);
    if (start == 0 || bytes > UINTPTR_MAX - start) return false;
    return CopyGuestBytes(destination, source, bytes);
}

I tried that locally: same 4 timer/fault tests pass 5/5, including the seccomp child (CopyGuestBytes throws std::runtime_error on non-EFAULT too). It also drops about 28 lines.

Small notes, not blocking:

  • setitimer(3, (GuestItimerval*)1, &ok) gives EINVAL here. On FreeBSD the copyin (L803) runs before the which check in kern_setitimer (L822), so it gives EFAULT. That order is old code, and you said you kept it, so this is just a note. It's now reachable because the bad-pointer path exists.
  • No test hits the which != 0 copyout of previous (Signals.cpp:442-445), e.g. setitimer(1, zero, bad) should be EFAULT.
  • GuestOutputPointerFault.cpp:75-77 sets *__error_nid_postfix() = 0 three times in a row.

Limits: Linux only, no Windows or macOS run, no dump.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5643351345 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10975#pullrequestreview-5643351345). Originally posted by [ahmadmuj](https://github.com/ahmadmuj) on 2026-10-25T13:16:16Z. **Review:** COMMENTED --- Reviewed head `d69520c794feeaaddcd5cbd409dd738fb6ae4504` (base `66e6772ca2094b665488d6ca5cbae3f6fb0c5034`). `git merge-tree` onto current main `4017310678562c63594d99b8f45db2d68b9aaa6c` is clean. What I ran, WSL2 Ubuntu 24.04, GCC 13.3, Release: - Built only the focused targets. `guest_output_pointer_fault`, `guest_fstat_fault`, `guest_freebsd_clocks`, `guest_getitimer`, `guest_itimer`, `guest_itimer_pending_default`, `guest_system_configuration`, `guest_time_extras`, `guest_kernel_sys_ktimer` and `public_headers` pass 10/10. The four timer/fault tests also pass 20/20 with `--repeat until-fail:20`. `check_conventions.py` passes. - Red check 1: `Signals.cpp` and `Time.cpp` back to base, test kept. `guest_output_pointer_fault` dies with SIGSEGV. - Red check 2: `General.cpp` from 4ab1636 (the `memcpy` fallback on a non-EFAULT `process_vm_readv` error). The seccomp child fails at line 59, so that test does catch the EPERM case. - Compared against FreeBSD `releng/11.4` `sys/kern/kern_time.c`. `gettimeofday` copies `tp` first, then `tzp` only if that worked (L644-652). `getitimer` checks `which` before the copyout (L754, L745). `setitimer` with `itv == NULL` forwards to getitimer (L797-800), and copies `oitv` out after the timer is armed (L805-808). Your code matches all of that, and the test pins the armed-then-EFAULT case. One suggestion: `GuestCopyIn_nid_no_patch` re-implements `CopyGuestBytes` from the same file (General.cpp:86-104), which is already a checked read on every host. The copies differ in two places. In `#else`, `GuestCopyIn` does a raw `memcpy` and returns true, while `CopyGuestBytes` and `GuestCopyOut` both throw there (CONTRIBUTING: does what it should or throws). On Windows it does `VirtualQuery` then `memcpy`, while `CopyGuestBytes` uses `ReadProcessMemory`, which can't race with an unmap between the check and the copy. Keeping your null/overflow guard and delegating works: ```cpp extern "C" bool GuestCopyIn_nid_no_patch(void* destination, const void* source, std::size_t bytes) { if (bytes == 0) return true; const auto start = reinterpret_cast<std::uintptr_t>(source); if (start == 0 || bytes > UINTPTR_MAX - start) return false; return CopyGuestBytes(destination, source, bytes); } ``` I tried that locally: same 4 timer/fault tests pass 5/5, including the seccomp child (`CopyGuestBytes` throws `std::runtime_error` on non-EFAULT too). It also drops about 28 lines. Small notes, not blocking: - `setitimer(3, (GuestItimerval*)1, &ok)` gives EINVAL here. On FreeBSD the copyin (L803) runs before the `which` check in `kern_setitimer` (L822), so it gives EFAULT. That order is old code, and you said you kept it, so this is just a note. It's now reachable because the bad-pointer path exists. - No test hits the `which != 0` copyout of `previous` (Signals.cpp:442-445), e.g. `setitimer(1, zero, bad)` should be EFAULT. - GuestOutputPointerFault.cpp:75-77 sets `*__error_nid_postfix() = 0` three times in a row. Limits: Linux only, no Windows or macOS run, no dump.
MarcZX10 commented 2026-10-25 13:18:58 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T13:18:58Z.

Review: CHANGES_REQUESTED


I reviewed the exact head d69520c794feeaaddcd5cbd409dd738fb6ae4504 and the focused test report. The Linux non-EFAULT fallback and macOS unchecked read issues are addressed, and the added seccomp regression covers the former.

One remaining correctness issue is the final #else in GuestCopyIn_nid_no_patch: it uses std::memcpy and returns success on every host without a platform-specific checked-copy path. An invalid guest source can still terminate the host there. The repository already has the cross-platform checked CopyGuestBytes helper; please keep the zero/null/overflow guard and use that helper (or make unsupported hosts fail safely) instead of falling through to raw memcpy.

Please also add the focused setitimer previous-value copyout fault case noted in review (valid value, invalid previous) if feasible, since it exercises the GuestCopyOut branch after the timer update. Then rerun the focused test and report which host(s) ran it. I have not run the full CMake suite locally.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5643359609 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10975#pullrequestreview-5643359609). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-25T13:18:58Z. **Review:** CHANGES_REQUESTED --- I reviewed the exact head `d69520c794feeaaddcd5cbd409dd738fb6ae4504` and the focused test report. The Linux non-`EFAULT` fallback and macOS unchecked read issues are addressed, and the added seccomp regression covers the former. One remaining correctness issue is the final `#else` in `GuestCopyIn_nid_no_patch`: it uses `std::memcpy` and returns success on every host without a platform-specific checked-copy path. An invalid guest source can still terminate the host there. The repository already has the cross-platform checked `CopyGuestBytes` helper; please keep the zero/null/overflow guard and use that helper (or make unsupported hosts fail safely) instead of falling through to raw `memcpy`. Please also add the focused `setitimer` previous-value copyout fault case noted in review (valid `value`, invalid `previous`) if feasible, since it exercises the `GuestCopyOut` branch after the timer update. Then rerun the focused test and report which host(s) ran it. I have not run the full CMake suite locally.
MarcZX10 commented 2026-10-25 13:36:27 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T13:36:27Z.

Review: CHANGES_REQUESTED


Thanks for the macOS checked-copy addition and the Linux seccomp regression; the reviewed current diff now has safe host-copy implementations for those cases. One part of the reported issue still appears uncovered: the getitimer and setitimer bodies do not change in this PR, and Time.cpp only routes gettimeofday/sceKernelGettimeofday and sceKernelGettimezone through GuestCopyOut. Could you confirm how the bad getitimer output and setitimer value/previous pointers are made safe on this head, or add the checked copies and regression cases if they remain direct dereferences? The issue specifically lists those pointers; I do not see them covered by guest_output_pointer_fault in the changed test diff.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5643426821 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10975#pullrequestreview-5643426821). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-25T13:36:27Z. **Review:** CHANGES_REQUESTED --- Thanks for the macOS checked-copy addition and the Linux seccomp regression; the reviewed current diff now has safe host-copy implementations for those cases. One part of the reported issue still appears uncovered: the `getitimer` and `setitimer` bodies do not change in this PR, and `Time.cpp` only routes `gettimeofday`/`sceKernelGettimeofday` and `sceKernelGettimezone` through `GuestCopyOut`. Could you confirm how the bad `getitimer` output and `setitimer` value/previous pointers are made safe on this head, or add the checked copies and regression cases if they remain direct dereferences? The issue specifically lists those pointers; I do not see them covered by `guest_output_pointer_fault` in the changed test diff.
AdnanKhan-ak47 commented 2026-10-25 13:49:58 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by AdnanKhan-ak47 on 2026-10-25T13:49:58Z.

Review: APPROVED


Reviewed head d9e8185cc1 on macOS 27.0.1 (Apple silicon), the host nobody else in the thread has.

The macOS run everyone asked for is not possible on main. core/libs does not build on macOS at all: GuestAllocations.cpp:26 includes the Linux-only <link.h> under a guard that does not exclude Apple, and docs/dev/BUILD.md:17 states the libraries ship for Linux and Windows only. So guest_output_pointer_fault cannot run here for this or any PR until the libraries are ported; that is out of scope for this fix and should not hold it.

What can be verified is the macOS branch itself. GuestCopyIn_nid_no_patch now delegates to CopyGuestBytes, whose Apple path is mach_vm_read_overwrite(..., &copied) == KERN_SUCCESS && copied == bytes (General.cpp:98-100), the same code as GuestCopyOut's mach_vm_write counterpart. A standalone x86_64 binary with that exact function, run under Rosetta, on the issue's two addresses plus null and a valid one:

source 0x0000000000000001 -> rejected, destination untouched
source 0xfffffffffffff000 -> rejected, destination untouched
source 0x0000000000000000 -> rejected, destination untouched
source 0x0000000308b44ba8 -> copied, destination holds 12/34

No fault, no partial write. The surrounding setitimer logic is host-independent, so this is the host-specific part of the behaviour that the Linux and Windows runs do not cover.

On the 13:36 request: on this head the bodies do change. getitimer_nid_postfix fills a local through GetitimerInto and copies out with GuestCopyOut (Signals.cpp), setitimer reads value through GuestCopyIn and copies previous out through GuestCopyOut on both the which != 0 and ITIMER_REAL branches, and Time.cpp routes the three time getters the same way. ahmadmuj's red check 1 (bodies reverted, test kept, SIGSEGV) covers that these are the lines that matter.

Approving. The behaviour and ordering match what I had in the closed #10978, and delegating to CopyGuestBytes is the better shape; the two small gaps ahmadmuj noted (setitimer(1, zero, bad) for the which != 0 copy-out, and the copyin-before-which order on FreeBSD) are in AdnanKhan-ak47:fix/libkernel-time-efault (GuestItimer.cpp) if you want to lift them, but neither should block this.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5643509087 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10975#pullrequestreview-5643509087). Originally posted by [AdnanKhan-ak47](https://github.com/AdnanKhan-ak47) on 2026-10-25T13:49:58Z. **Review:** APPROVED --- Reviewed head `d9e8185cc1` on macOS 27.0.1 (Apple silicon), the host nobody else in the thread has. **The macOS run everyone asked for is not possible on `main`.** `core/libs` does not build on macOS at all: `GuestAllocations.cpp:26` includes the Linux-only `<link.h>` under a guard that does not exclude Apple, and `docs/dev/BUILD.md:17` states the libraries ship for Linux and Windows only. So `guest_output_pointer_fault` cannot run here for this or any PR until the libraries are ported; that is out of scope for this fix and should not hold it. **What can be verified is the macOS branch itself.** `GuestCopyIn_nid_no_patch` now delegates to `CopyGuestBytes`, whose Apple path is `mach_vm_read_overwrite(..., &copied) == KERN_SUCCESS && copied == bytes` (`General.cpp:98-100`), the same code as `GuestCopyOut`'s `mach_vm_write` counterpart. A standalone x86_64 binary with that exact function, run under Rosetta, on the issue's two addresses plus null and a valid one: ``` source 0x0000000000000001 -> rejected, destination untouched source 0xfffffffffffff000 -> rejected, destination untouched source 0x0000000000000000 -> rejected, destination untouched source 0x0000000308b44ba8 -> copied, destination holds 12/34 ``` No fault, no partial write. The surrounding `setitimer` logic is host-independent, so this is the host-specific part of the behaviour that the Linux and Windows runs do not cover. **On the 13:36 request:** on this head the bodies do change. `getitimer_nid_postfix` fills a local through `GetitimerInto` and copies out with `GuestCopyOut` (`Signals.cpp`), `setitimer` reads `value` through `GuestCopyIn` and copies `previous` out through `GuestCopyOut` on both the `which != 0` and `ITIMER_REAL` branches, and `Time.cpp` routes the three time getters the same way. ahmadmuj's red check 1 (bodies reverted, test kept, SIGSEGV) covers that these are the lines that matter. Approving. The behaviour and ordering match what I had in the closed #10978, and delegating to `CopyGuestBytes` is the better shape; the two small gaps ahmadmuj noted (`setitimer(1, zero, bad)` for the `which != 0` copy-out, and the copyin-before-`which` order on FreeBSD) are in `AdnanKhan-ak47:fix/libkernel-time-efault` (`GuestItimer.cpp`) if you want to lift them, but neither should block this.
MarcZX10 commented 2026-10-25 14:27:03 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T14:27:03Z.

Review: APPROVED


Re-reviewed exact head c67997b99b. The new test cases cover getitimer(1, bad) and setitimer(1, zero, bad), including successful calls with valid pointers, closing the previous non-ITIMER_REAL coverage gap. The checked guest read delegates to CopyGuestBytes; the Linux non-EFAULT syscall failure no longer falls through to raw memcpy, and the new seccomp case covers that failure.

Exact-head local checks: git diff --check, tools/check_conventions.py, and a C++20 syntax check of GuestOutputPointerFault.cpp pass. The PR reports the focused tests passing on Windows and WSL2 Linux; hosted product jobs are skipped, and I did not run the linked suite locally. The macOS library test cannot run because core/libs is not currently buildable on macOS; the standalone checked-read result on macOS is author-reported by another reviewer. With those limits stated, the requested correctness and test changes are addressed.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5643661946 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10975#pullrequestreview-5643661946). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-25T14:27:03Z. **Review:** APPROVED --- Re-reviewed exact head c67997b99bf14ef79e702457f87f732ba62d3e7d. The new test cases cover `getitimer(1, bad)` and `setitimer(1, zero, bad)`, including successful calls with valid pointers, closing the previous non-ITIMER_REAL coverage gap. The checked guest read delegates to `CopyGuestBytes`; the Linux non-EFAULT syscall failure no longer falls through to raw `memcpy`, and the new seccomp case covers that failure. Exact-head local checks: `git diff --check`, `tools/check_conventions.py`, and a C++20 syntax check of `GuestOutputPointerFault.cpp` pass. The PR reports the focused tests passing on Windows and WSL2 Linux; hosted product jobs are skipped, and I did not run the linked suite locally. The macOS library test cannot run because `core/libs` is not currently buildable on macOS; the standalone checked-read result on macOS is author-reported by another reviewer. With those limits stated, the requested correctness and test changes are addressed.
ahmadmuj commented 2026-10-25 15:31:00 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ahmadmuj on 2026-10-25T15:31:00Z.

Review: APPROVED


Follow-up on my earlier review. Re-checked head c67997b99bf14ef79e702457f87f732ba62d3e7d (base 66e6772ca2094b665488d6ca5cbae3f6fb0c5034); git merge-tree onto current main d2b3ee3bcc8b3724ab953ea7d1b9419e07a38346 is clean.

What I ran, WSL2 Ubuntu 24.04, GCC 13.3, Release:

  • GuestCopyIn_nid_no_patch now keeps the null/overflow guard and returns CopyGuestBytes(...). That's byte-for-byte the version I tried locally last time.
  • The same 10 focused tests (guest_output_pointer_fault, guest_fstat_fault, guest_freebsd_clocks, guest_getitimer, guest_itimer, guest_itimer_pending_default, guest_system_configuration, guest_time_extras, guest_kernel_sys_ktimer, public_headers) with --repeat until-fail:20: 200/200 pass, seccomp child included. check_conventions.py passes.
  • Red checks on guest_output_pointer_fault, one mutant at a time:
    • setitimer which != 0 branch back to *previous = {}: SIGSEGV, so the new setitimer(1, zero, bad) line catches it.
    • getitimer writing *output = {} directly for which 1/2: SIGSEGV, so the new getitimer(1, bad) line catches it.
    • GuestCopyIn back to a raw memcpy: SIGSEGV on setitimer(0, bad, ok).

Approving. The setitimer(3, bad) EINVAL-vs-EFAULT order from my last review is still only a note.

Limits: Linux only, no Windows or macOS run, no dump.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5643872203 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10975#pullrequestreview-5643872203). Originally posted by [ahmadmuj](https://github.com/ahmadmuj) on 2026-10-25T15:31:00Z. **Review:** APPROVED --- Follow-up on my earlier review. Re-checked head `c67997b99bf14ef79e702457f87f732ba62d3e7d` (base `66e6772ca2094b665488d6ca5cbae3f6fb0c5034`); `git merge-tree` onto current main `d2b3ee3bcc8b3724ab953ea7d1b9419e07a38346` is clean. What I ran, WSL2 Ubuntu 24.04, GCC 13.3, Release: - `GuestCopyIn_nid_no_patch` now keeps the null/overflow guard and returns `CopyGuestBytes(...)`. That's byte-for-byte the version I tried locally last time. - The same 10 focused tests (`guest_output_pointer_fault`, `guest_fstat_fault`, `guest_freebsd_clocks`, `guest_getitimer`, `guest_itimer`, `guest_itimer_pending_default`, `guest_system_configuration`, `guest_time_extras`, `guest_kernel_sys_ktimer`, `public_headers`) with `--repeat until-fail:20`: 200/200 pass, seccomp child included. `check_conventions.py` passes. - Red checks on `guest_output_pointer_fault`, one mutant at a time: - `setitimer` `which != 0` branch back to `*previous = {}`: SIGSEGV, so the new `setitimer(1, zero, bad)` line catches it. - `getitimer` writing `*output = {}` directly for `which` 1/2: SIGSEGV, so the new `getitimer(1, bad)` line catches it. - `GuestCopyIn` back to a raw `memcpy`: SIGSEGV on `setitimer(0, bad, ok)`. Approving. The `setitimer(3, bad)` EINVAL-vs-EFAULT order from my last review is still only a note. Limits: Linux only, no Windows or macOS run, no dump.
AdnanKhan-ak47 commented 2026-10-26 01:01:42 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by AdnanKhan-ak47 on 2026-10-26T01:01:42Z.

Review: APPROVED


Re-reviewed 080c77547c. git merge-tree of main 49d1f9b07e with the previously approved d9e8185cc1 produces a tree byte-identical to this head, so the merge commit adds nothing beyond resolving #9682's timezone store: gettimeofday fills current and zone as before and copies each out with GuestCopyOut, clock_gettime still maps the errno 14 path to SceKernelErrorEfault, and settimeofday's tz write goes through the checked copy. Against 49d1f9b07e the PR is the same 6 files (+163/-10) as before. Approval stands.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5646310954 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10975#pullrequestreview-5646310954). Originally posted by [AdnanKhan-ak47](https://github.com/AdnanKhan-ak47) on 2026-10-26T01:01:42Z. **Review:** APPROVED --- Re-reviewed `080c77547c`. `git merge-tree` of `main` `49d1f9b07e` with the previously approved `d9e8185cc1` produces a tree byte-identical to this head, so the merge commit adds nothing beyond resolving #9682's timezone store: `gettimeofday` fills `current` and `zone` as before and copies each out with `GuestCopyOut`, `clock_gettime` still maps the `errno` 14 path to `SceKernelErrorEfault`, and `settimeofday`'s `tz` write goes through the checked copy. Against `49d1f9b07e` the PR is the same 6 files (+163/-10) as before. Approval stands.
MarcZX10 commented 2026-10-26 05:43:22 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-26T05:43:22Z.

Review: CHANGES_REQUESTED


Rechecked merge head 080c77547cf1; the reviewed checked-copy implementation remains sound and the Windows/WSL results are useful. Current upstream main has advanced: this branch is 6 ahead /225 behind 14c99b52ac, with main-side changes in General.cpp, libkernel CMake and Signals.cpp since its merge base. The reported focused run is against older 14eb2cda22d2. Please refresh onto current main and rerun the focused time/pointer tests on the resulting exact head before merge. This is a current-head integration/validation request, not a reopened code finding.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5647846532 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10975#pullrequestreview-5647846532). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-26T05:43:22Z. **Review:** CHANGES_REQUESTED --- Rechecked merge head `080c77547cf1`; the reviewed checked-copy implementation remains sound and the Windows/WSL results are useful. Current upstream main has advanced: this branch is 6 ahead /225 behind `14c99b52ac`, with main-side changes in `General.cpp`, libkernel CMake and `Signals.cpp` since its merge base. The reported focused run is against older `14eb2cda22d2`. Please refresh onto current main and rerun the focused time/pointer tests on the resulting exact head before merge. This is a current-head integration/validation request, not a reopened code finding.
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!10975
No description provided.