Skip to content

fix(libkernel): fail settimeofday and clock_settime with EFAULT on an… - #11476

Closed
Sr-0w wants to merge 1 commit into
boykopovar:mainfrom
Sr-0w:claude/loving-turing-6o94gl
Closed

Sr-0w wants to merge 1 commit into
boykopovar:mainfrom
Sr-0w:claude/loving-turing-6o94gl

Conversation

@Sr-0w

@Sr-0w Sr-0w commented Oct 26, 2026 •

Copy link
Copy Markdown

What

settimeofday and clock_settime read the guest's timeval, timespec and timezone directly, so a pointer into unmapped memory crashed the host process (#11370).

Both now copy each non-null argument in with a checked read before any validation, as FreeBSD 11.4's sys_settimeofday and sys_clock_settime copyin first (kern_time.c lines 390, 671 and 678):

  • clock_settime with an unreadable time returns EFAULT, also for a clock other than CLOCK_REALTIME, where it returned EINVAL before reading the time.
  • settimeofday with an unreadable time or time zone returns EFAULT ahead of the EINVAL value checks and ahead of the throw for a valid time. A failed copy stores no time zone.
  • A null time zone still leaves the zone alone, and a null time still sets the zone only, as before.

The checked read is local to Time.cpp, as in Process.cpp. #10975 and #10978 each add a shared GuestCopyIn_nid_no_patch to libc; whichever lands first, this read can move onto it in a follow-up. This PR does not add a third copy, so it does not conflict with either.

The settimeofday and clock_settime debt entries now say EFAULT for an unreadable argument instead of only a null one.

Tested

Linux (Ubuntu 24.04, GCC 13.3, Release, full build with BUILD_TESTING=ON, libs rebuilt). No Windows or macOS run; the Windows and macOS branches of the checked read follow ReadGuest in Process.cpp.

  • New cases in guest_kernel_sys (CheckSettimeofdayUnreadable) and guest_freebsd_clocks (SettimeFaultsBeforeValidation): an unreadable page and an argument that crosses from a readable page into it, for the time and the time zone, with valid and invalid values and with clocks other than CLOCK_REALTIME. They also check that the time zone set before the faulting calls is still reported.
  • Red on main's Time.cpp with the new tests: both guest_kernel_sys and guest_freebsd_clocks end with SegFault. Green with this change.
  • Full ctest (2335 tests): 2323 passed, 766 of them skipped for lack of a Vulkan device. 12 failed: agc_submit_progress, agc_submit_progress_no_timeline, agc_driver_pipelined_metadata_pass, agc_driver_pipelined_metadata_pass_draw_pipeline (no GPU), and guest_net_protocol, guest_net_buffer_validation, guest_sce_net_keepalive, guest_net_nodelay_readback, guest_socket_options, guest_socket_stream_options, guest_socket_address_length, guest_tcp (the sandbox has no IPv6, errno 47). The same 12 fail with main's Time.cpp on the same machine.
  • After rebasing on main 84ffc1a: the 93 tests matching guest_freebsd_clocks|guest_kernel_sys|itimer|time|clock|guest_fstat_fault pass except agc_submit_progress_no_timeline, which also fails on main.
  • python3 tools/check_conventions.py --base origin/main: all checks passed. tools/pr_overlap.py could not run (no gh GraphQL access here). By hand: the other open PRs that touch Time.cpp (fix(libkernel): fail gettimeofday, getitimer, setitimer and the sceKernel time getters with EFAULT on an unusable pointer #10975, fix(libkernel): fail the time getters and setitimer with EFAULT on an unmapped pointer #10978) change the getters and libc, not these two setters.

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: Fixes fix(libkernel): settimeofday and clock_settime crash the host on a pointer into unmapped memory #11370
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

🤖 Generated with Claude Code

… unreadable pointer

Both setters dereferenced the guest's timeval, timespec and timezone
directly, so a pointer into unmapped memory crashed the host. Copy each
non-null argument in with a checked read before any validation, as
FreeBSD 11.4's sys_settimeofday and sys_clock_settime copyin first: an
unreadable argument returns EFAULT ahead of EINVAL for a bad clock or
value, and settimeofday stores no time zone when either copy fails.

Fixes boykopovar#11370

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013tsQ2RPv2nbDiPMpehiedc

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR appears to duplicate open #11402 (78571ca2fb9f), which already changes these same clock_settime/settimeofday input paths, addresses #11370, and adds EFAULT-before-EINVAL and timezone non-mutation coverage. Please coordinate with that PR’s author/maintainers before keeping parallel implementations; the cross-page fault cases here are useful additional coverage that could be incorporated into the existing fix if appropriate.

The current head also fails Conventions because What and Tested are empty and all required checklist items are unchecked. The branch merge base is 84ffc1ae2d96, while live main is 518d36eaec0a; main has since changed GuestKernelSys.cpp and docs/dev/debt/libkernel.md, both touched here. Please reconcile those changes, complete the required template and dependency/merge-order fields, then rerun the focused clock/kernel tests and conventions on the resulting head. I have not found a distinct behavior change that justifies a second implementation while #11402 remains open.

@github-actions

github-actions Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

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 4630 docs/dev/debt/libkernel.md
PR 5021 core/libs/prx/libkernel/Time/Time.cpp
docs/dev/debt/libkernel.md
PR 6149 docs/dev/debt/libkernel.md
PR 6740 docs/dev/debt/libkernel.md
PR 6936 docs/dev/debt/libkernel.md
PR 7088 docs/dev/debt/libkernel.md
PR 7090 docs/dev/debt/libkernel.md
PR 7105 docs/dev/debt/libkernel.md
PR 7121 docs/dev/debt/libkernel.md
PR 7135 docs/dev/debt/libkernel.md
PR 7149 docs/dev/debt/libkernel.md
PR 7156 core/libs/prx/libkernel/Time/Time.cpp
PR 7192 docs/dev/debt/libkernel.md
PR 7447 docs/dev/debt/libkernel.md
PR 7464 docs/dev/debt/libkernel.md
PR 7509 docs/dev/debt/libkernel.md
PR 7532 docs/dev/debt/libkernel.md
PR 7565 docs/dev/debt/libkernel.md
PR 7804 core/libs/prx/libkernel/Time/Time.cpp
docs/dev/debt/libkernel.md
PR 8497 docs/dev/debt/libkernel.md
PR 8605 docs/dev/debt/libkernel.md
PR 8916 core/libs/prx/libkernel/Time/Time.cpp
docs/dev/debt/libkernel.md
PR 9097 core/libs/tests/GuestKernelSys.cpp
PR 9156 docs/dev/debt/libkernel.md
PR 9199 docs/dev/debt/libkernel.md
PR 9242 docs/dev/debt/libkernel.md
PR 9284 docs/dev/debt/libkernel.md
PR 9293 docs/dev/debt/libkernel.md
PR 9297 docs/dev/debt/libkernel.md
PR 9302 docs/dev/debt/libkernel.md
PR 9326 docs/dev/debt/libkernel.md
PR 9389 docs/dev/debt/libkernel.md
PR 9442 core/libs/tests/GuestKernelSys.cpp
docs/dev/debt/libkernel.md
PR 9491 docs/dev/debt/libkernel.md
PR 9515 docs/dev/debt/libkernel.md
PR 9557 docs/dev/debt/libkernel.md
PR 9566 docs/dev/debt/libkernel.md
PR 9575 docs/dev/debt/libkernel.md
PR 9578 docs/dev/debt/libkernel.md
PR 9658 core/libs/tests/GuestFreebsdClocks.cpp
PR 9677 core/libs/prx/libkernel/Time/Time.cpp
PR 9684 docs/dev/debt/libkernel.md
PR 9713 core/libs/tests/GuestKernelSys.cpp
PR 9843 docs/dev/debt/libkernel.md
PR 9882 docs/dev/debt/libkernel.md
PR 9938 docs/dev/debt/libkernel.md
PR 9947 docs/dev/debt/libkernel.md
PR 9994 core/libs/tests/GuestKernelSys.cpp
PR 10016 core/libs/tests/GuestKernelSys.cpp
PR 10025 docs/dev/debt/libkernel.md
PR 10192 docs/dev/debt/libkernel.md
PR 10319 docs/dev/debt/libkernel.md
PR 10332 core/libs/tests/GuestKernelSys.cpp
PR 10421 core/libs/tests/GuestKernelSys.cpp
PR 10427 core/libs/tests/GuestKernelSys.cpp
PR 10442 docs/dev/debt/libkernel.md
PR 10552 docs/dev/debt/libkernel.md
PR 10558 docs/dev/debt/libkernel.md
PR 10625 core/libs/tests/GuestKernelSys.cpp
PR 10645 docs/dev/debt/libkernel.md
PR 10725 docs/dev/debt/libkernel.md
PR 10749 docs/dev/debt/libkernel.md
PR 10789 docs/dev/debt/libkernel.md
PR 10809 docs/dev/debt/libkernel.md
PR 10810 docs/dev/debt/libkernel.md
PR 10816 docs/dev/debt/libkernel.md
PR 10817 docs/dev/debt/libkernel.md
PR 10838 core/libs/tests/GuestKernelSys.cpp
PR 10855 docs/dev/debt/libkernel.md
PR 10856 docs/dev/debt/libkernel.md
PR 10898 docs/dev/debt/libkernel.md
PR 10975 core/libs/prx/libkernel/Time/Time.cpp
PR 11002 docs/dev/debt/libkernel.md
PR 11005 docs/dev/debt/libkernel.md
PR 11031 core/libs/tests/GuestKernelSys.cpp
PR 11032 core/libs/tests/GuestKernelSys.cpp
PR 11034 core/libs/tests/GuestKernelSys.cpp
PR 11039 docs/dev/debt/libkernel.md
PR 11042 core/libs/prx/libkernel/Time/Time.cpp
core/libs/tests/GuestFreebsdClocks.cpp
docs/dev/debt/libkernel.md
PR 11047 docs/dev/debt/libkernel.md
PR 11085 docs/dev/debt/libkernel.md
PR 11215 docs/dev/debt/libkernel.md
PR 11216 core/libs/tests/GuestKernelSys.cpp
PR 11219 docs/dev/debt/libkernel.md
PR 11223 docs/dev/debt/libkernel.md
PR 11231 core/libs/tests/GuestKernelSys.cpp
PR 11236 docs/dev/debt/libkernel.md
PR 11247 docs/dev/debt/libkernel.md
PR 11264 docs/dev/debt/libkernel.md
PR 11267 docs/dev/debt/libkernel.md
PR 11296 core/libs/tests/GuestKernelSys.cpp
PR 11298 core/libs/tests/GuestKernelSys.cpp
PR 11341 docs/dev/debt/libkernel.md
PR 11403 docs/dev/debt/libkernel.md
PR 11431 docs/dev/debt/libkernel.md
PR 11546 core/libs/tests/GuestFreebsdClocks.cpp
PR 11579 core/libs/prx/libkernel/Time/Time.cpp
PR 11592 docs/dev/debt/libkernel.md
PR 11595 core/libs/tests/GuestKernelSys.cpp
PR 11624 docs/dev/debt/libkernel.md
PR 11625 docs/dev/debt/libkernel.md
PR 11628 docs/dev/debt/libkernel.md
PR 11661 docs/dev/debt/libkernel.md
PR 11689 docs/dev/debt/libkernel.md
PR 11698 docs/dev/debt/libkernel.md
PR 11732 docs/dev/debt/libkernel.md
PR 11827 docs/dev/debt/libkernel.md
PR 11849 docs/dev/debt/libkernel.md
PR 11858 docs/dev/debt/libkernel.md
PR 11861 docs/dev/debt/libkernel.md
PR 11862 docs/dev/debt/libkernel.md
PR 11863 docs/dev/debt/libkernel.md
PR 11864 docs/dev/debt/libkernel.md
PR 11865 docs/dev/debt/libkernel.md

@github-actions github-actions Bot added the fix error Closes an issue (Fixes #N) label Oct 26, 2026

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for filling the PR template; the current conventions check passes, so that earlier note no longer applies.

The remaining blocker is overlap with still-open #11402. I compared both heads: each adds the same platform-specific checked guest read to Time.cpp, copies the clock_settime/settimeofday arguments before validation, and returns EFAULT before EINVAL for the unreadable pointers. Both address #11370. This PR's distinct value is its cross-page boundary cases and broader error-order checks, which are useful, but they currently live beside a second implementation of the same setters.

Please coordinate with #11402's author/maintainers and consolidate the extra regression cases into one implementation, or document an agreed merge order and make this PR a non-duplicative follow-up. The current head is also 154 commits behind main; since GuestKernelSys.cpp and docs/dev/debt/libkernel.md changed on both sides, sync and resolve those files before the final focused test/conventions run. The required policy checks currently pass; product jobs are skipped by path policy. The Linux test results in the description are author-reported; I did not run them independently on this head.

@ycbuzi

ycbuzi commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Windows run of 5ee57652b5 merged onto main 88795ed448 (7444f6c195, clean), since the description has no Windows run. Windows 11 Home 10.0.26200, WinLibs GCC 15.2.0 r7 (MinGW-w64 UCRT), Release, BUILD_TESTING=ON.

  • Built guest_freebsd_clocks_tests and guest_kernel_sys_tests with no errors or warnings. guest_freebsd_clocks and guest_kernel_sys pass both runs of ctest --repeat until-fail:2.
  • Negative control: with main's Time/Time.cpp and the rest of this head, both tests crash with FATAL: unhandled exception 0xc0000005 (reads of 0x…1008 addresses from libkernel.prx) and exit as Exception. So the Windows branch of the checked read covers what the new cases test.
  • Not covered: this session isn't elevated, so guest_kernel_sys printed symbolic links unavailable: the link cases not tested. Those cases are unrelated to this change. Also not run: macOS, a title.

AI-assisted: yes (Claude Code)

@github-actions github-actions Bot added libkernel docs needs rebase Conflicts with main, rebase needed labels Oct 26, 2026
@adriadam10 adriadam10 self-assigned this Oct 27, 2026
@adriadam10

Copy link
Copy Markdown
Collaborator

Closing as a duplicate: #11402 was merged this morning and already covers this issue (#11370). It adds the same checked guest read to Time.cpp for clock_settime and settimeofday, returns EFAULT before the EINVAL checks, and leaves the time zone untouched on a failed copy. This branch now conflicts with main, and its docs/dev/debt/libkernel.md change adds new settimeofday/clock_settime entries beside the old ones instead of replacing them.

The part that is not on main is the cross-page cases (an argument that starts on a readable page and runs into an unreadable one). If you want them in, a small PR with only those tests on top of current main is welcome, with the Tested section showing them pass on top of #11402's implementation. Feel free to reopen with that.

@adriadam10 adriadam10 closed this Oct 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs fix error Closes an issue (Fixes #N) libkernel needs rebase Conflicts with main, rebase needed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(libkernel): settimeofday and clock_settime crash the host on a pointer into unmapped memory

5 participants