posix-timers: Take compat timer_gettime(2) to native one
authorAl Viro <viro@zeniv.linux.org.uk>
Wed, 7 Jun 2017 08:42:36 +0000 (09:42 +0100)
committerThomas Gleixner <tglx@linutronix.de>
Tue, 13 Jun 2017 22:00:43 +0000 (00:00 +0200)
... and get rid of set_fs() in there

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: John Stultz <john.stultz@linaro.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/20170607084241.28657-11-viro@ZenIV.linux.org.uk
kernel/compat.c
kernel/time/posix-stubs.c
kernel/time/posix-timers.c

index df39e2e00c47c0ef2cea176f92113ce5cadb583d..1fb8cf7e691ebb3cd06b113ffb068a861b00ecb0 100644 (file)
@@ -635,23 +635,6 @@ COMPAT_SYSCALL_DEFINE3(timer_create, clockid_t, which_clock,
        return sys_timer_create(which_clock, event, created_timer_id);
 }
 
-COMPAT_SYSCALL_DEFINE2(timer_gettime, timer_t, timer_id,
-                      struct compat_itimerspec __user *, setting)
-{
-       long err;
-       mm_segment_t oldfs;
-       struct itimerspec ts;
-
-       oldfs = get_fs();
-       set_fs(KERNEL_DS);
-       err = sys_timer_gettime(timer_id,
-                               (struct itimerspec __user *) &ts);
-       set_fs(oldfs);
-       if (!err && put_compat_itimerspec(setting, &ts))
-               return -EFAULT;
-       return err;
-}
-
 COMPAT_SYSCALL_DEFINE2(clock_settime, clockid_t, which_clock,
                       struct compat_timespec __user *, tp)
 {
index ad263df132d697006e2633b5be467b4b6d02e32f..f4a1962d1729072a59e2a52f7a6da4d8df04cabd 100644 (file)
@@ -43,6 +43,7 @@ SYS_NI(alarm);
 #endif
 COMPAT_SYS_NI(clock_adjtime);
 COMPAT_SYS_NI(timer_settime);
+COMPAT_SYS_NI(timer_gettime);
 
 /*
  * We preserve minimal support for CLOCK_REALTIME and CLOCK_MONOTONIC
index a73feac191f986d7f276095cc724f3b8f3da649b..e82bb1fd614e6151801a10bbc77eb82d4344b02c 100644 (file)
@@ -690,11 +690,8 @@ void common_timer_get(struct k_itimer *timr, struct itimerspec64 *cur_setting)
 }
 
 /* Get the time remaining on a POSIX.1b interval timer. */
-SYSCALL_DEFINE2(timer_gettime, timer_t, timer_id,
-               struct itimerspec __user *, setting)
+static int do_timer_gettime(timer_t timer_id,  struct itimerspec64 *setting)
 {
-       struct itimerspec64 cur_setting64;
-       struct itimerspec cur_setting;
        struct k_itimer *timr;
        const struct k_clock *kc;
        unsigned long flags;
@@ -704,21 +701,49 @@ SYSCALL_DEFINE2(timer_gettime, timer_t, timer_id,
        if (!timr)
                return -EINVAL;
 
-       memset(&cur_setting64, 0, sizeof(cur_setting64));
+       memset(setting, 0, sizeof(*setting));
        kc = timr->kclock;
        if (WARN_ON_ONCE(!kc || !kc->timer_get))
                ret = -EINVAL;
        else
-               kc->timer_get(timr, &cur_setting64);
+               kc->timer_get(timr, setting);
 
        unlock_timer(timr, flags);
+       return ret;
+}
 
-       cur_setting = itimerspec64_to_itimerspec(&cur_setting64);
-       if (!ret && copy_to_user(setting, &cur_setting, sizeof (cur_setting)))
-               return -EFAULT;
+/* Get the time remaining on a POSIX.1b interval timer. */
+SYSCALL_DEFINE2(timer_gettime, timer_t, timer_id,
+               struct itimerspec __user *, setting)
+{
+       struct itimerspec64 cur_setting64;
 
+       int ret = do_timer_gettime(timer_id, &cur_setting64);
+       if (!ret) {
+               struct itimerspec cur_setting;
+               cur_setting = itimerspec64_to_itimerspec(&cur_setting64);
+               if (copy_to_user(setting, &cur_setting, sizeof (cur_setting)))
+                       ret = -EFAULT;
+       }
+       return ret;
+}
+
+#ifdef CONFIG_COMPAT
+COMPAT_SYSCALL_DEFINE2(timer_gettime, timer_t, timer_id,
+                      struct compat_itimerspec __user *, setting)
+{
+       struct itimerspec64 cur_setting64;
+
+       int ret = do_timer_gettime(timer_id, &cur_setting64);
+       if (!ret) {
+               struct itimerspec cur_setting;
+               cur_setting = itimerspec64_to_itimerspec(&cur_setting64);
+               if (put_compat_itimerspec(setting, &cur_setting))
+                       ret = -EFAULT;
+       }
        return ret;
 }
+#endif
 
 /*
  * Get the number of overruns of a POSIX.1b interval timer.  This is to