Isolate time_t data types for clock/timer syscalls
v2 cover Isolate time_t data types for clock/timer syscalls
The series aims at isolating data conversions of time_t based structures:
struct timespec and struct itimerspec at user space boundaries. This helps to later change the underlying types to handle y2038 changes to these.
The series is an update to Arnd Bergmann's previous series:
http://sourceware.org/ml/libc-alpha/2015-05/msg00070.html
Changes since v1:
* Rebased and removed common code paths on the tip linux-next.
Deepa Dinamani (7):
time: add get_timespec64 and put_timespec64
time: introduce {get,put}_itimerspec64
posix-stubs: Conditionally include COMPAT_SYS_NI defines
posix-timers: Use get_timepsec64() and put_timespec64()
nanosleep: Use get_timepsec64() and put_timespec64()
timerfd: Use get_itimerspec64() and put_itimerspec64()
posix_clocks: Use get_itimerspec64() and put_itimerspec64()
fs/timerfd.c | 43 +++++++------ include/linux/compat.h | 6 ++ include/linux/hrtimer.h | 2 +- include/linux/posix-timers.h | 1 - include/linux/time.h | 18 ++++++ kernel/compat.c | 65 ++++++++++++++++++++ kernel/time/alarmtimer.c | 4 +- kernel/time/hrtimer.c | 30 ++++------ kernel/time/posix-cpu-timers.c | 8 +-- kernel/time/posix-stubs.c | 99 ++++++++++++++++-------------- kernel/time/posix-timers.c | 133 +++++++++++++++-------------------------- kernel/time/time.c | 58 ++++++++++++++++++ 12 files changed, 289 insertions(+), 178 deletions(-)
Signature · 1 line
2.11.0
PATCH v2 1/7 time: add get_timespec64 and put_timespec64
Add helper functions to convert between struct timespec64 and struct timespec at userspace boundaries.
This is a preparatory patch to use timespec64 as the basic type internally in the kernel as timespec is not y2038 safe on 32 bit systems. The patch helps the cause by containing all data conversions at the userspace boundaries within these functions.
--- include/linux/compat.h | 2 ++ include/linux/time.h | 5 +++++ kernel/compat.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ kernel/time/time.c | 28 ++++++++++++++++++++++++++++ 4 files changed, 79 insertions(+)
include/linux/compat.h +2 -0
@@ -164,6 +164,8 @@ extern int compat_get_timespec(struct timespec *, const void __user *);extern int compat_put_timespec (const struct timespec *,void __user *);extern int compat_get_timeval (struct timeval *,const void __user *);extern int compat_put_timeval (const struct timeval *,void __user *); +extern int compat_get_timespec64 (struct timespec64 *,const void __user *); +extern int compat_put_timespec64 (const struct timespec64 *,void __user *);/* * This function convert a timespec if necessary and returns a *user
include/linux/time.h +5 -0
@@ -8,6 +8,11 @@extern struct timezone sys_tz; +int get_timespec64 (struct timespec64 *ts, +const struct timespec __user *uts); +int put_timespec64 (const struct timespec64 *ts, +struct timespec __user *uts); +#define TIME_T_MAX (time_t)((1UL << ((sizeof(time_t) << 3) - 1)) - 1) static inline int timespec_equal(const struct timespec *a,
kernel/compat.c +44 -0
50 lines not on this page · raw message
kernel/time/time.c +28 -0
@@ -890,3 +890,31 @@ struct timespec64 timespec64_add_safe(const struct timespec64 lhs,return res; } + +int get_timespec64 (struct timespec64 *ts, +const struct timespec __user *uts) +{ +struct timespec kts; +int ret; + + ret =copy_from_user (&kts, uts,sizeof (kts)); +if (ret) +return -EFAULT ; + + ts->tv_sec = kts.tv_sec; + ts->tv_nsec = kts.tv_nsec; + +return 0 ; +} +EXPORT_SYMBOL_GPL (get_timespec64); + +int put_timespec64 (const struct timespec64 *ts, +struct timespec __user *uts) +{ +struct timespec kts = { + .tv_sec = ts->tv_sec, + .tv_nsec = ts->tv_nsec + }; +return copy_to_user (uts, &kts,sizeof (kts)) ? -EFAULT :0 ; +} +EXPORT_SYMBOL_GPL (put_timespec64);
Signature · 1 line
2.11.0
PATCH v2 2/7 time: introduce {get,put}_itimerspec64
In reply to Deepa DinamaniAs we change the user space type for the timerfd and posix timer functions to newer data types, we need some form of conversion helpers to avoid duplicating that logic.
--- include/linux/compat.h | 4 ++++ include/linux/posix-timers.h | 1 - include/linux/time.h | 13 +++++++++++++ kernel/compat.c | 21 +++++++++++++++++++++ kernel/time/time.c | 30 ++++++++++++++++++++++++++++++ 5 files changed, 68 insertions(+), 1 deletion(-)
include/linux/compat.h +4 -0
@@ -166,6 +166,10 @@ extern int compat_get_timeval(struct timeval *, const void __user *);extern int compat_put_timeval (const struct timeval *,void __user *);extern int compat_get_timespec64 (struct timespec64 *,const void __user *);extern int compat_put_timespec64 (const struct timespec64 *,void __user *); +extern int get_compat_itimerspec64 (struct itimerspec64 *its, +const struct compat_itimerspec __user *uits); +extern int put_compat_itimerspec64 (const struct itimerspec64 *its, +struct compat_itimerspec __user *uits);/* * This function convert a timespec if necessary and returns a *user
include/linux/posix-timers.h +0 -1
@@ -113,5 +113,4 @@ void set_process_cpu_timer(struct task_struct *task, unsigned int clock_idx,void update_rlimit_cpu (struct task_struct *task,unsigned long rlim_new);void posixtimer_rearm (struct siginfo *info); -#endif
include/linux/time.h +13 -0
@@ -12,6 +12,10 @@ int get_timespec64(struct timespec64 *ts, const struct timespec __user *uts);int put_timespec64 (const struct timespec64 *ts,struct timespec __user *uts); +int get_itimerspec64 (struct itimerspec64 *it, +const struct itimerspec __user *uit); +int put_itimerspec64 (const struct itimerspec64 *it, +struct itimerspec __user *uit);#define TIME_T_MAX (time_t)((1UL << ((sizeof(time_t) << 3) - 1)) - 1)
@@ -275,4 +279,13 @@ static __always_inline void timespec_add_ns(struct timespec *a, u64 ns) a->tv_nsec = ns; } +static inline bool itimerspec64_valid (const struct itimerspec64 *its) +{ +if (!timespec64_valid (&(its->it_interval)) || + !timespec64_valid (&(its->it_value))) +return false; + +return true; +} +#endif
kernel/compat.c +21 -0
@@ -586,6 +586,27 @@ int put_compat_itimerspec(struct compat_itimerspec __user *dst,return 0 ; } +int get_compat_itimerspec64 (struct itimerspec64 *its, +const struct compat_itimerspec __user *uits) +{ + +if (__compat_get_timespec64 (&its->it_interval, &uits->it_interval) || +__compat_get_timespec64 (&its->it_value, &uits->it_value)) +return -EFAULT ; +return 0 ; +} +EXPORT_SYMBOL_GPL (get_compat_itimerspec64); + +int put_compat_itimerspec64 (const struct itimerspec64 *its, +struct compat_itimerspec __user *uits) +{ +if (__compat_put_timespec64 (&its->it_interval, &uits->it_interval) || +__compat_put_timespec64 (&its->it_value, &uits->it_value)) +return -EFAULT ; +return 0 ; +} +EXPORT_SYMBOL_GPL (put_compat_itimerspec64); +/* * We currently only need the following fields from the sigevent * structure: sigev_value, sigev_signo, sig_notify and (sometimes
kernel/time/time.c +30 -0
@@ -918,3 +918,33 @@ int put_timespec64(const struct timespec64 *ts,return copy_to_user (uts, &kts,sizeof (kts)) ? -EFAULT :0 ; }EXPORT_SYMBOL_GPL (put_timespec64); + +int get_itimerspec64 (struct itimerspec64 *it, +const struct itimerspec __user *uit) +{ +int ret; + + ret =get_timespec64 (&it->it_interval, &uit->it_interval); +if (ret) +return ret; + + ret =get_timespec64 (&it->it_value, &uit->it_value); + +return ret; +} +EXPORT_SYMBOL_GPL (get_itimerspec64); + +int put_itimerspec64 (const struct itimerspec64 *it, +struct itimerspec __user *uit) +{ +int ret; + + ret =put_timespec64 (&it->it_interval, &uit->it_interval); +if (ret) +return ret; + + ret =put_timespec64 (&it->it_value, &uit->it_value); + +return ret; +} +EXPORT_SYMBOL_GPL (put_itimerspec64);
Signature · 1 line
2.11.0
PATCH v2 3/7 posix-stubs: Conditionally include COMPAT_SYS_NI defines
In reply to Deepa DinamaniThese apis are only to be defined if CONFIG_COMPAT is enabled.
--- kernel/time/posix-stubs.c | 6 ------ 1 file changed, 6 deletions(-)
kernel/time/posix-stubs.c +0 -6
@@ -41,12 +41,6 @@ SYS_NI(setitimer);#ifdef __ARCH_WANT_SYS_ALARMSYS_NI (alarm);#endif -COMPAT_SYS_NI (timer_create); -COMPAT_SYS_NI (clock_adjtime); -COMPAT_SYS_NI (timer_settime); -COMPAT_SYS_NI (timer_gettime); -COMPAT_SYS_NI (getitimer); -COMPAT_SYS_NI (setitimer);/* * We preserve minimal support for CLOCK_REALTIME and CLOCK_MONOTONIC
Signature · 1 line
2.11.0