Commit 54ad9c46 authored by Al Viro's avatar Al Viro Committed by Thomas Gleixner

itimers: Move compat itimer syscalls to native ones

get rid of set_fs(), sanitize compat copyin/copyout.
Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
Signed-off-by: default avatarThomas 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-12-viro@ZenIV.linux.org.uk
parent b0dc1242
...@@ -94,6 +94,10 @@ struct compat_itimerval { ...@@ -94,6 +94,10 @@ struct compat_itimerval {
struct compat_timeval it_value; struct compat_timeval it_value;
}; };
struct itimerval;
int get_compat_itimerval(struct itimerval *, const struct compat_itimerval __user *);
int put_compat_itimerval(struct compat_itimerval __user *, const struct itimerval *);
struct compat_tms { struct compat_tms {
compat_clock_t tms_utime; compat_clock_t tms_utime;
compat_clock_t tms_stime; compat_clock_t tms_stime;
......
...@@ -217,65 +217,28 @@ int compat_convert_timespec(struct timespec __user **kts, ...@@ -217,65 +217,28 @@ int compat_convert_timespec(struct timespec __user **kts,
return 0; return 0;
} }
static inline long get_compat_itimerval(struct itimerval *o, int get_compat_itimerval(struct itimerval *o, const struct compat_itimerval __user *i)
struct compat_itimerval __user *i)
{ {
return (!access_ok(VERIFY_READ, i, sizeof(*i)) || struct compat_itimerval v32;
(__get_user(o->it_interval.tv_sec, &i->it_interval.tv_sec) |
__get_user(o->it_interval.tv_usec, &i->it_interval.tv_usec) |
__get_user(o->it_value.tv_sec, &i->it_value.tv_sec) |
__get_user(o->it_value.tv_usec, &i->it_value.tv_usec)));
}
static inline long put_compat_itimerval(struct compat_itimerval __user *o,
struct itimerval *i)
{
return (!access_ok(VERIFY_WRITE, o, sizeof(*o)) ||
(__put_user(i->it_interval.tv_sec, &o->it_interval.tv_sec) |
__put_user(i->it_interval.tv_usec, &o->it_interval.tv_usec) |
__put_user(i->it_value.tv_sec, &o->it_value.tv_sec) |
__put_user(i->it_value.tv_usec, &o->it_value.tv_usec)));
}
asmlinkage long sys_ni_posix_timers(void);
COMPAT_SYSCALL_DEFINE2(getitimer, int, which,
struct compat_itimerval __user *, it)
{
struct itimerval kit;
int error;
if (!IS_ENABLED(CONFIG_POSIX_TIMERS))
return sys_ni_posix_timers();
error = do_getitimer(which, &kit); if (copy_from_user(&v32, i, sizeof(struct compat_itimerval)))
if (!error && put_compat_itimerval(it, &kit)) return -EFAULT;
error = -EFAULT; o->it_interval.tv_sec = v32.it_interval.tv_sec;
return error; o->it_interval.tv_usec = v32.it_interval.tv_usec;
o->it_value.tv_sec = v32.it_value.tv_sec;
o->it_value.tv_usec = v32.it_value.tv_usec;
return 0;
} }
COMPAT_SYSCALL_DEFINE3(setitimer, int, which, int put_compat_itimerval(struct compat_itimerval __user *o, const struct itimerval *i)
struct compat_itimerval __user *, in,
struct compat_itimerval __user *, out)
{ {
struct itimerval kin, kout; struct compat_itimerval v32;
int error;
if (!IS_ENABLED(CONFIG_POSIX_TIMERS)) v32.it_interval.tv_sec = i->it_interval.tv_sec;
return sys_ni_posix_timers(); v32.it_interval.tv_usec = i->it_interval.tv_usec;
v32.it_value.tv_sec = i->it_value.tv_sec;
if (in) { v32.it_value.tv_usec = i->it_value.tv_usec;
if (get_compat_itimerval(&kin, in)) return copy_to_user(o, &v32, sizeof(struct compat_itimerval)) ? -EFAULT : 0;
return -EFAULT;
} else
memset(&kin, 0, sizeof(kin));
error = do_setitimer(which, &kin, out ? &kout : NULL);
if (error || !out)
return error;
if (put_compat_itimerval(out, &kout))
return -EFAULT;
return 0;
} }
static compat_clock_t clock_t_to_compat_clock_t(clock_t x) static compat_clock_t clock_t_to_compat_clock_t(clock_t x)
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include <linux/posix-timers.h> #include <linux/posix-timers.h>
#include <linux/hrtimer.h> #include <linux/hrtimer.h>
#include <trace/events/timer.h> #include <trace/events/timer.h>
#include <linux/compat.h>
#include <linux/uaccess.h> #include <linux/uaccess.h>
...@@ -116,6 +117,19 @@ SYSCALL_DEFINE2(getitimer, int, which, struct itimerval __user *, value) ...@@ -116,6 +117,19 @@ SYSCALL_DEFINE2(getitimer, int, which, struct itimerval __user *, value)
return error; return error;
} }
#ifdef CONFIG_COMPAT
COMPAT_SYSCALL_DEFINE2(getitimer, int, which,
struct compat_itimerval __user *, it)
{
struct itimerval kit;
int error = do_getitimer(which, &kit);
if (!error && put_compat_itimerval(it, &kit))
error = -EFAULT;
return error;
}
#endif
/* /*
* The timer is automagically restarted, when interval != 0 * The timer is automagically restarted, when interval != 0
...@@ -294,3 +308,27 @@ SYSCALL_DEFINE3(setitimer, int, which, struct itimerval __user *, value, ...@@ -294,3 +308,27 @@ SYSCALL_DEFINE3(setitimer, int, which, struct itimerval __user *, value,
return -EFAULT; return -EFAULT;
return 0; return 0;
} }
#ifdef CONFIG_COMPAT
COMPAT_SYSCALL_DEFINE3(setitimer, int, which,
struct compat_itimerval __user *, in,
struct compat_itimerval __user *, out)
{
struct itimerval kin, kout;
int error;
if (in) {
if (get_compat_itimerval(&kin, in))
return -EFAULT;
} else {
memset(&kin, 0, sizeof(kin));
}
error = do_setitimer(which, &kin, out ? &kout : NULL);
if (error || !out)
return error;
if (put_compat_itimerval(out, &kout))
return -EFAULT;
return 0;
}
#endif
...@@ -44,6 +44,8 @@ SYS_NI(alarm); ...@@ -44,6 +44,8 @@ SYS_NI(alarm);
COMPAT_SYS_NI(clock_adjtime); COMPAT_SYS_NI(clock_adjtime);
COMPAT_SYS_NI(timer_settime); COMPAT_SYS_NI(timer_settime);
COMPAT_SYS_NI(timer_gettime); COMPAT_SYS_NI(timer_gettime);
COMPAT_SYS_NI(getitimer);
COMPAT_SYS_NI(setitimer);
/* /*
* We preserve minimal support for CLOCK_REALTIME and CLOCK_MONOTONIC * We preserve minimal support for CLOCK_REALTIME and CLOCK_MONOTONIC
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment