]> git.hungrycats.org Git - linux/commitdiff
timekeeping: Require permission to set auxiliary clocks
authorDaehyeon Ko <4ncienth@gmail.com>
Mon, 19 Oct 2026 08:03:24 +0000 (17:03 +0900)
committerThomas Gleixner <tglx@kernel.org>
Fri, 23 Oct 2026 19:49:57 +0000 (21:49 +0200)
The generic clock_settime() entry point delegates permission checks to
each clock-specific callback. aux_clock_set() does not perform one. Once
an administrator enables an auxiliary clock, any local process can
therefore change the global clock offset.

A test process running as UID and GID 65534 with no effective, permitted,
inheritable, or ambient capabilities set CLOCK_AUX0 successfully, and a
separate process observed the new value. The same process was denied by
clock_adjtime(). An AppArmor profile denying sys_time also blocked
CLOCK_REALTIME changes but did not see the auxiliary clock operation.

Call security_settime64() before mutating the auxiliary timekeeper. This
matches CLOCK_REALTIME's permission model, enforces initial-user-namespace
CAP_SYS_TIME, and gives LSMs the settime hook while preserving authorized
clock changes.

Fixes: 60ecc26ec5af ("timekeeping: Provide time setter for auxiliary clocks")
Signed-off-by: Daehyeon Ko <4ncienth@gmail.com>
Signed-off-by: Thomas Gleixner <tglx@kernel.org>
Tested-by: shaos <shawnq1@163.com>
Acked-by: John Stultz <jstultz@google.com>
Cc: stable@vger.kernel.org
Link: https://patch.msgid.link/20261019080324.4147815-1-4ncienth@gmail.com
kernel/time/timekeeping.c

index ea2e6e55f37bfdc0f317ca93bb7113c7eef5ddec..1b342825bd8f1e188d35c3c5742a3ab9382d726a 100644 (file)
@@ -14,6 +14,7 @@
 #include <linux/random.h>
 #include <linux/sched/clock.h>
 #include <linux/sched/loadavg.h>
+#include <linux/security.h>
 #include <linux/static_key.h>
 #include <linux/stop_machine.h>
 #include <linux/syscore_ops.h>
@@ -3215,11 +3216,15 @@ static int aux_clock_set(const clockid_t id, const struct timespec64 *tnew)
        struct tk_data *aux_tkd = aux_get_tk_data(id);
        struct timekeeper *aux_tks;
        ktime_t tnow, nsecs;
+       int ret;
 
        if (!timespec64_valid_settod(tnew))
                return -EINVAL;
        if (!aux_tkd)
                return -ENODEV;
+       ret = security_settime64(tnew, NULL);
+       if (ret)
+               return ret;
 
        aux_tks = &aux_tkd->shadow_timekeeper;