fix(libkernel): check settimeofday and clock_settime pointers #11402
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/11402"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by 00xDisaster on 2026-10-26T10:56:58Z.
What
clock_settimeread the caller'stimespecin place, andsettimeofdayread itstimevalandtimezonein 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'ssys_clock_settimeandsys_settimeofdaydo, and returnEFAULTbefore validation when a non-null pointer is unreadable.clock_settimestill returnsEFAULTfor a null time, andsettimeofdaystill treats a null argument as omitted. This keepsEFAULTahead ofEINVALand keeps an unreadable time zone from being stored.The checked read is independent of #10975, which adds a shared
GuestCopyInhelper for the getters andsetitimerbut not these setters.clock_settimeoverlaps #11042, which replaces the valid-time descriptive throw withNotImplemented_nid_no_patchand changes the same clock test. The merged function keeps this PR's copy,EFAULTandEINVALorder, then #11042'sNotImplementedpath for a valid request; neither change replaces the other. #9677 adds aGuestTime.hppinclude inTime.cpp; #9713 adds includes andThreadAndSessionTestsinGuestKernelSys.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/main4b1a9a3b2f; head78571ca2fb.guest_freebsd_clocksandguest_kernel_syspass 2/2 with new cases that pass1as the time, time zone, or both pointers:clock_settimereturns-1/EFAULTfor an unreadable time with both a valid and an invalid clock.settimeofdayreturns-1/EFAULTfor an unreadable time, an unreadable zone, both, and a valid time with an unreadable zone.EFAULTbefore invalid time values returnEINVAL.Negative control with
upstream/main4b1a9a3b2fTime.cppand the tests from this head:guest_freebsd_clocksandguest_kernel_sysboth fail withException: SegFaultat the first unreadable pointer. Tests were not run on Windows, macOS, the console, or a title.Checklist
main; no other open PR adds the checked reads; #11042 changes the validclock_settimetail and is preserved on rebaseNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)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.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-26T11:37:25Z.
Review: APPROVED
Re-reviewed exact head
78571ca2fbagainst current main4b1a9a3b2f. 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.