time: Respect COMPAT_32BIT_TIME for old time type functions

The "old" time types use 32-bit seconds which are not y2038-safe.
Respect COMPAT_32BIT_TIME for functions using those types.
time(), stime() and gettimeofday() are disabled completely.

settimeofday() is kept as it is required to do the initial timewarping
after boot. However the 'tv' argument will be rejected.

Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
Signed-off-by: Thomas Gleixner <tglx@kernel.org>
Reviewed-by: Arnd Bergmann <arnd@arndb.de>
Link: https://lore.kernel.org/lkml/e9487ebe-3730-438a-9c23-e45f75986ecc@app.fastmail.com/
Link: https://patch.msgid.link/20260702-vdso-compat_32bit_time-v3-1-db9f36d8d432@linutronix.de
This commit is contained in:
Thomas Weißschuh
2026-07-07 23:52:53 +02:00
committed by Thomas Gleixner
parent 0b50763e84
commit dce21fb3d5
2 changed files with 24 additions and 4 deletions
+4
View File
@@ -351,6 +351,10 @@ COND_SYSCALL(ppoll_time32);
COND_SYSCALL_COMPAT(ppoll_time32); COND_SYSCALL_COMPAT(ppoll_time32);
COND_SYSCALL(utimensat_time32); COND_SYSCALL(utimensat_time32);
COND_SYSCALL(clock_adjtime32); COND_SYSCALL(clock_adjtime32);
COND_SYSCALL(gettimeofday);
COND_SYSCALL_COMPAT(gettimeofday);
COND_SYSCALL(time);
COND_SYSCALL(stime);
/* /*
* The syscalls below are not found in include/uapi/asm-generic/unistd.h * The syscalls below are not found in include/uapi/asm-generic/unistd.h
+20 -4
View File
@@ -43,6 +43,12 @@
#include <generated/timeconst.h> #include <generated/timeconst.h>
#include "timekeeping.h" #include "timekeeping.h"
#if defined(CONFIG_64BIT) || defined(CONFIG_COMPAT_32BIT_TIME)
#define __WANT_OLD_TIME_TYPE_SYSCALL 1
#endif
static_assert(sizeof(__kernel_old_time_t) == 8 ? IS_ENABLED(__WANT_OLD_TIME_TYPE_SYSCALL) : true);
/* /*
* The timezone where the local system is located. Used as a default by some * The timezone where the local system is located. Used as a default by some
* programs who obtain this value by using gettimeofday. * programs who obtain this value by using gettimeofday.
@@ -51,7 +57,7 @@ struct timezone sys_tz;
EXPORT_SYMBOL(sys_tz); EXPORT_SYMBOL(sys_tz);
#ifdef __ARCH_WANT_SYS_TIME #if defined(__ARCH_WANT_SYS_TIME) && defined(__WANT_OLD_TIME_TYPE_SYSCALL)
/* /*
* sys_time() can be implemented in user-level using * sys_time() can be implemented in user-level using
@@ -96,7 +102,7 @@ SYSCALL_DEFINE1(stime, __kernel_old_time_t __user *, tptr)
return 0; return 0;
} }
#endif /* __ARCH_WANT_SYS_TIME */ #endif /* __ARCH_WANT_SYS_TIME && __WANT_OLD_TIME_TYPE_SYSCALL */
#ifdef CONFIG_COMPAT_32BIT_TIME #ifdef CONFIG_COMPAT_32BIT_TIME
#ifdef __ARCH_WANT_SYS_TIME32 #ifdef __ARCH_WANT_SYS_TIME32
@@ -137,6 +143,7 @@ SYSCALL_DEFINE1(stime32, old_time32_t __user *, tptr)
#endif /* __ARCH_WANT_SYS_TIME32 */ #endif /* __ARCH_WANT_SYS_TIME32 */
#endif #endif
#ifdef __WANT_OLD_TIME_TYPE_SYSCALL
SYSCALL_DEFINE2(gettimeofday, struct __kernel_old_timeval __user *, tv, SYSCALL_DEFINE2(gettimeofday, struct __kernel_old_timeval __user *, tv,
struct timezone __user *, tz) struct timezone __user *, tz)
{ {
@@ -154,6 +161,7 @@ SYSCALL_DEFINE2(gettimeofday, struct __kernel_old_timeval __user *, tv,
} }
return 0; return 0;
} }
#endif /* __WANT_OLD_TIME_TYPE_SYSCALL */
/* /*
* In case for some reason the CMOS clock has not already been running * In case for some reason the CMOS clock has not already been running
@@ -203,6 +211,9 @@ SYSCALL_DEFINE2(settimeofday, struct __kernel_old_timeval __user *, tv,
struct timezone new_tz; struct timezone new_tz;
if (tv) { if (tv) {
if (!IS_ENABLED(__WANT_OLD_TIME_TYPE_SYSCALL))
return -EINVAL;
if (get_user(new_ts.tv_sec, &tv->tv_sec) || if (get_user(new_ts.tv_sec, &tv->tv_sec) ||
get_user(new_ts.tv_nsec, &tv->tv_usec)) get_user(new_ts.tv_nsec, &tv->tv_usec))
return -EFAULT; return -EFAULT;
@@ -220,7 +231,7 @@ SYSCALL_DEFINE2(settimeofday, struct __kernel_old_timeval __user *, tv,
return do_sys_settimeofday64(tv ? &new_ts : NULL, tz ? &new_tz : NULL); return do_sys_settimeofday64(tv ? &new_ts : NULL, tz ? &new_tz : NULL);
} }
#ifdef CONFIG_COMPAT #ifdef CONFIG_COMPAT_32BIT_TIME
COMPAT_SYSCALL_DEFINE2(gettimeofday, struct old_timeval32 __user *, tv, COMPAT_SYSCALL_DEFINE2(gettimeofday, struct old_timeval32 __user *, tv,
struct timezone __user *, tz) struct timezone __user *, tz)
{ {
@@ -239,7 +250,9 @@ COMPAT_SYSCALL_DEFINE2(gettimeofday, struct old_timeval32 __user *, tv,
return 0; return 0;
} }
#endif /* CONFIG_COMPAT_32BIT_TIME */
#ifdef CONFIG_COMPAT
COMPAT_SYSCALL_DEFINE2(settimeofday, struct old_timeval32 __user *, tv, COMPAT_SYSCALL_DEFINE2(settimeofday, struct old_timeval32 __user *, tv,
struct timezone __user *, tz) struct timezone __user *, tz)
{ {
@@ -247,6 +260,9 @@ COMPAT_SYSCALL_DEFINE2(settimeofday, struct old_timeval32 __user *, tv,
struct timezone new_tz; struct timezone new_tz;
if (tv) { if (tv) {
if (!IS_ENABLED(CONFIG_COMPAT_32BIT_TIME))
return -EINVAL;
if (get_user(new_ts.tv_sec, &tv->tv_sec) || if (get_user(new_ts.tv_sec, &tv->tv_sec) ||
get_user(new_ts.tv_nsec, &tv->tv_usec)) get_user(new_ts.tv_nsec, &tv->tv_usec))
return -EFAULT; return -EFAULT;
@@ -263,7 +279,7 @@ COMPAT_SYSCALL_DEFINE2(settimeofday, struct old_timeval32 __user *, tv,
return do_sys_settimeofday64(tv ? &new_ts : NULL, tz ? &new_tz : NULL); return do_sys_settimeofday64(tv ? &new_ts : NULL, tz ? &new_tz : NULL);
} }
#endif #endif /* CONFIG_COMPAT */
#ifdef CONFIG_64BIT #ifdef CONFIG_64BIT
SYSCALL_DEFINE1(adjtimex, struct __kernel_timex __user *, txc_p) SYSCALL_DEFINE1(adjtimex, struct __kernel_timex __user *, txc_p)