fix(libkernel_sys): fail settimeofday and clock_settime with EPERM for a jailed caller #15035
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/15035"
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 Gruzzberry on 2026-11-02T11:22:35Z.
What
settimeofdayandclock_settimenow fail withEPERMafter copying their arguments in, for every time, zone and clock. Before, a valid time threw (settimeofday) or went throughNotImplemented_nid_no_patch(clock_settime), invalid values gaveEINVAL, andsettimeofdaywith only a time zone stored it forgettimeofday.Ground truth is FreeBSD 11.4 (release/11.4.0):
sys_settimeofdaycopies in the time, then the zone, andkern_settimeofdaycallspriv_check(td, PRIV_SETTIMEOFDAY)before it validates the time or stores the zone (kern_time.c L660-L707);sys_clock_settimecopies in andkern_clock_settimecallspriv_check(td, PRIV_CLOCK_SETTIME)before the clock id and range checks (L385-L412).prison_priv_checkhas no case for either privilege, so a jailed process reaches itsdefault: return (EPERM). The credential model is the one maintainers agreed on #11216: a title runs jailed with uid 0.EFAULTfor an unreadable pointer keeps its place before the check, so null and0x10giveEFAULTwhere FreeBSD'scopyinwould. The time zone is no longer kept, sogettimeofdayalways reports 0 and 0, and thesceKernelSettimeofdaywrapper returns0x80020001.adjtimeis left to #14257, which implements it.Tested
Windows 11, WinLibs GCC 15.2.0 r7, Ninja, Release,
-DBUILD_TESTING=ON, on currentmain.guest_kernel_sysandguest_freebsd_clocks: 3/3. WithTime.cppfrommainand the new tests, both abort.EFAULTfor 1 and0x10pointers in every argument combination,EPERMfor valid and invalid times (negative seconds, microseconds out of range) with and without a zone,EPERMfor every clock id including unknown ones, thesceKernelSettimeofdaymapping, and that the wall clock is unchanged afterwards.adjtime): only environmental failures (vulkan_validation_gate_reports,check_compile_test_windows_gcc_response_text_mode_is_not_reinterpreted),annotate_moduletiming out under load, and two tests that pass alone 3/3 (guest_filesystem,agc_driver_job_manager_compute_capacity). After the rebase I reran the focused tests andcheck_conventions.pyonly.prison_priv_checkand is not measured on a console; the debt entries say so.Overlaps
GuestFreebsdClocks.cppnext to theclock_settimetest block; #13127 and #14085 edit neighbouring lines ofdocs/dev/debt/libkernel_sys.md. I proposed on each that they go first and this PR rebases.adjtime) does not overlap now; a non-null delta there could returnEPERMthe same way (kern_adjtimechecksPRIV_ADJTIMEfirst).Checklist
main; no other open PR implements the same functionNotImplemented_nid_no_patch); no silent stubs added.mdfiles or images added to the repositoryAI-assisted (Claude Code).
🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by mashingaan on 2026-11-02T11:37:50Z.
Review: DISMISSED
The diff removes the only write to zoneOutput in gettimeofday_nid_postfix, so a caller passing a non-null timezone now keeps its old contents. The existing GuestFreebsdClocks test KernelTimezoneIsUtc still initializes KernelTimezone zone{-1, -1} and requires gettimeofday_nid_postfix(nullptr, &zone) to write both fields as zero. The current implementation therefore contradicts an existing regression assertion and drops previously working behavior. Please preserve the timezone output with GuestCopyOut_nid_no_patch (mapping a bad destination to EFAULT), and keep the test on the Hosted Windows run. That run is still pending on this head.