Commit 3a4d44b6 authored by Al Viro's avatar Al Viro Committed by Thomas Gleixner

ntp: Move adjtimex related compat syscalls to native counterparts

Get rid of set_fs() mess and sanitize compat_{get,put}_timex(),
while we are at it.
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-9-viro@ZenIV.linux.org.uk
parent fb923c4a
...@@ -128,6 +128,10 @@ struct compat_timex { ...@@ -128,6 +128,10 @@ struct compat_timex {
compat_int_t:32; compat_int_t:32; compat_int_t:32; compat_int_t:32; compat_int_t:32; compat_int_t:32;
}; };
struct timex;
int compat_get_timex(struct timex *, const struct compat_timex __user *);
int compat_put_timex(struct compat_timex __user *, const struct timex *);
#define _COMPAT_NSIG_WORDS (_COMPAT_NSIG / _COMPAT_NSIG_BPW) #define _COMPAT_NSIG_WORDS (_COMPAT_NSIG / _COMPAT_NSIG_BPW)
typedef struct { typedef struct {
......
...@@ -30,60 +30,64 @@ ...@@ -30,60 +30,64 @@
#include <linux/uaccess.h> #include <linux/uaccess.h>
static int compat_get_timex(struct timex *txc, struct compat_timex __user *utp) int compat_get_timex(struct timex *txc, const struct compat_timex __user *utp)
{ {
memset(txc, 0, sizeof(struct timex)); struct compat_timex tx32;
if (!access_ok(VERIFY_READ, utp, sizeof(struct compat_timex)) || if (copy_from_user(&tx32, utp, sizeof(struct compat_timex)))
__get_user(txc->modes, &utp->modes) ||
__get_user(txc->offset, &utp->offset) ||
__get_user(txc->freq, &utp->freq) ||
__get_user(txc->maxerror, &utp->maxerror) ||
__get_user(txc->esterror, &utp->esterror) ||
__get_user(txc->status, &utp->status) ||
__get_user(txc->constant, &utp->constant) ||
__get_user(txc->precision, &utp->precision) ||
__get_user(txc->tolerance, &utp->tolerance) ||
__get_user(txc->time.tv_sec, &utp->time.tv_sec) ||
__get_user(txc->time.tv_usec, &utp->time.tv_usec) ||
__get_user(txc->tick, &utp->tick) ||
__get_user(txc->ppsfreq, &utp->ppsfreq) ||
__get_user(txc->jitter, &utp->jitter) ||
__get_user(txc->shift, &utp->shift) ||
__get_user(txc->stabil, &utp->stabil) ||
__get_user(txc->jitcnt, &utp->jitcnt) ||
__get_user(txc->calcnt, &utp->calcnt) ||
__get_user(txc->errcnt, &utp->errcnt) ||
__get_user(txc->stbcnt, &utp->stbcnt))
return -EFAULT; return -EFAULT;
txc->modes = tx32.modes;
txc->offset = tx32.offset;
txc->freq = tx32.freq;
txc->maxerror = tx32.maxerror;
txc->esterror = tx32.esterror;
txc->status = tx32.status;
txc->constant = tx32.constant;
txc->precision = tx32.precision;
txc->tolerance = tx32.tolerance;
txc->time.tv_sec = tx32.time.tv_sec;
txc->time.tv_usec = tx32.time.tv_usec;
txc->tick = tx32.tick;
txc->ppsfreq = tx32.ppsfreq;
txc->jitter = tx32.jitter;
txc->shift = tx32.shift;
txc->stabil = tx32.stabil;
txc->jitcnt = tx32.jitcnt;
txc->calcnt = tx32.calcnt;
txc->errcnt = tx32.errcnt;
txc->stbcnt = tx32.stbcnt;
return 0; return 0;
} }
static int compat_put_timex(struct compat_timex __user *utp, struct timex *txc) int compat_put_timex(struct compat_timex __user *utp, const struct timex *txc)
{ {
if (!access_ok(VERIFY_WRITE, utp, sizeof(struct compat_timex)) || struct compat_timex tx32;
__put_user(txc->modes, &utp->modes) ||
__put_user(txc->offset, &utp->offset) || memset(&tx32, 0, sizeof(struct compat_timex));
__put_user(txc->freq, &utp->freq) || tx32.modes = txc->modes;
__put_user(txc->maxerror, &utp->maxerror) || tx32.offset = txc->offset;
__put_user(txc->esterror, &utp->esterror) || tx32.freq = txc->freq;
__put_user(txc->status, &utp->status) || tx32.maxerror = txc->maxerror;
__put_user(txc->constant, &utp->constant) || tx32.esterror = txc->esterror;
__put_user(txc->precision, &utp->precision) || tx32.status = txc->status;
__put_user(txc->tolerance, &utp->tolerance) || tx32.constant = txc->constant;
__put_user(txc->time.tv_sec, &utp->time.tv_sec) || tx32.precision = txc->precision;
__put_user(txc->time.tv_usec, &utp->time.tv_usec) || tx32.tolerance = txc->tolerance;
__put_user(txc->tick, &utp->tick) || tx32.time.tv_sec = txc->time.tv_sec;
__put_user(txc->ppsfreq, &utp->ppsfreq) || tx32.time.tv_usec = txc->time.tv_usec;
__put_user(txc->jitter, &utp->jitter) || tx32.tick = txc->tick;
__put_user(txc->shift, &utp->shift) || tx32.ppsfreq = txc->ppsfreq;
__put_user(txc->stabil, &utp->stabil) || tx32.jitter = txc->jitter;
__put_user(txc->jitcnt, &utp->jitcnt) || tx32.shift = txc->shift;
__put_user(txc->calcnt, &utp->calcnt) || tx32.stabil = txc->stabil;
__put_user(txc->errcnt, &utp->errcnt) || tx32.jitcnt = txc->jitcnt;
__put_user(txc->stbcnt, &utp->stbcnt) || tx32.calcnt = txc->calcnt;
__put_user(txc->tai, &utp->tai)) tx32.errcnt = txc->errcnt;
tx32.stbcnt = txc->stbcnt;
tx32.tai = txc->tai;
if (copy_to_user(utp, &tx32, sizeof(struct compat_timex)))
return -EFAULT; return -EFAULT;
return 0; return 0;
} }
...@@ -705,29 +709,6 @@ COMPAT_SYSCALL_DEFINE2(clock_gettime, clockid_t, which_clock, ...@@ -705,29 +709,6 @@ COMPAT_SYSCALL_DEFINE2(clock_gettime, clockid_t, which_clock,
return err; return err;
} }
COMPAT_SYSCALL_DEFINE2(clock_adjtime, clockid_t, which_clock,
struct compat_timex __user *, utp)
{
struct timex txc;
mm_segment_t oldfs;
int err, ret;
err = compat_get_timex(&txc, utp);
if (err)
return err;
oldfs = get_fs();
set_fs(KERNEL_DS);
ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
set_fs(oldfs);
err = compat_put_timex(utp, &txc);
if (err)
return err;
return ret;
}
COMPAT_SYSCALL_DEFINE2(clock_getres, clockid_t, which_clock, COMPAT_SYSCALL_DEFINE2(clock_getres, clockid_t, which_clock,
struct compat_timespec __user *, tp) struct compat_timespec __user *, tp)
{ {
...@@ -944,24 +925,6 @@ COMPAT_SYSCALL_DEFINE1(stime, compat_time_t __user *, tptr) ...@@ -944,24 +925,6 @@ COMPAT_SYSCALL_DEFINE1(stime, compat_time_t __user *, tptr)
#endif /* __ARCH_WANT_COMPAT_SYS_TIME */ #endif /* __ARCH_WANT_COMPAT_SYS_TIME */
COMPAT_SYSCALL_DEFINE1(adjtimex, struct compat_timex __user *, utp)
{
struct timex txc;
int err, ret;
err = compat_get_timex(&txc, utp);
if (err)
return err;
ret = do_adjtimex(&txc);
err = compat_put_timex(utp, &txc);
if (err)
return err;
return ret;
}
#ifdef CONFIG_NUMA #ifdef CONFIG_NUMA
COMPAT_SYSCALL_DEFINE6(move_pages, pid_t, pid, compat_ulong_t, nr_pages, COMPAT_SYSCALL_DEFINE6(move_pages, pid_t, pid, compat_ulong_t, nr_pages,
compat_uptr_t __user *, pages32, compat_uptr_t __user *, pages32,
......
...@@ -28,6 +28,7 @@ asmlinkage long sys_ni_posix_timers(void) ...@@ -28,6 +28,7 @@ asmlinkage long sys_ni_posix_timers(void)
} }
#define SYS_NI(name) SYSCALL_ALIAS(sys_##name, sys_ni_posix_timers) #define SYS_NI(name) SYSCALL_ALIAS(sys_##name, sys_ni_posix_timers)
#define COMPAT_SYS_NI(name) SYSCALL_ALIAS(compat_sys_##name, sys_ni_posix_timers)
SYS_NI(timer_create); SYS_NI(timer_create);
SYS_NI(timer_gettime); SYS_NI(timer_gettime);
...@@ -40,6 +41,7 @@ SYS_NI(setitimer); ...@@ -40,6 +41,7 @@ SYS_NI(setitimer);
#ifdef __ARCH_WANT_SYS_ALARM #ifdef __ARCH_WANT_SYS_ALARM
SYS_NI(alarm); SYS_NI(alarm);
#endif #endif
COMPAT_SYS_NI(clock_adjtime);
/* /*
* We preserve minimal support for CLOCK_REALTIME and CLOCK_MONOTONIC * We preserve minimal support for CLOCK_REALTIME and CLOCK_MONOTONIC
......
...@@ -1018,6 +1018,33 @@ SYSCALL_DEFINE2(clock_adjtime, const clockid_t, which_clock, ...@@ -1018,6 +1018,33 @@ SYSCALL_DEFINE2(clock_adjtime, const clockid_t, which_clock,
return err; return err;
} }
#ifdef CONFIG_COMPAT
COMPAT_SYSCALL_DEFINE2(clock_adjtime, clockid_t, which_clock,
struct compat_timex __user *, utp)
{
const struct k_clock *kc = clockid_to_kclock(which_clock);
struct timex ktx;
int err;
if (!kc)
return -EINVAL;
if (!kc->clock_adj)
return -EOPNOTSUPP;
err = compat_get_timex(&ktx, utp);
if (err)
return err;
err = kc->clock_adj(which_clock, &ktx);
if (err >= 0)
err = compat_put_timex(utp, &ktx);
return err;
}
#endif
SYSCALL_DEFINE2(clock_getres, const clockid_t, which_clock, SYSCALL_DEFINE2(clock_getres, const clockid_t, which_clock,
struct timespec __user *, tp) struct timespec __user *, tp)
{ {
......
...@@ -39,6 +39,7 @@ ...@@ -39,6 +39,7 @@
#include <linux/ptrace.h> #include <linux/ptrace.h>
#include <linux/uaccess.h> #include <linux/uaccess.h>
#include <linux/compat.h>
#include <asm/unistd.h> #include <asm/unistd.h>
#include <generated/timeconst.h> #include <generated/timeconst.h>
...@@ -224,12 +225,33 @@ SYSCALL_DEFINE1(adjtimex, struct timex __user *, txc_p) ...@@ -224,12 +225,33 @@ SYSCALL_DEFINE1(adjtimex, struct timex __user *, txc_p)
* structure. But bear in mind that the structures * structure. But bear in mind that the structures
* may change * may change
*/ */
if(copy_from_user(&txc, txc_p, sizeof(struct timex))) if (copy_from_user(&txc, txc_p, sizeof(struct timex)))
return -EFAULT; return -EFAULT;
ret = do_adjtimex(&txc); ret = do_adjtimex(&txc);
return copy_to_user(txc_p, &txc, sizeof(struct timex)) ? -EFAULT : ret; return copy_to_user(txc_p, &txc, sizeof(struct timex)) ? -EFAULT : ret;
} }
#ifdef CONFIG_COMPAT
COMPAT_SYSCALL_DEFINE1(adjtimex, struct compat_timex __user *, utp)
{
struct timex txc;
int err, ret;
err = compat_get_timex(&txc, utp);
if (err)
return err;
ret = do_adjtimex(&txc);
err = compat_put_timex(utp, &txc);
if (err)
return err;
return ret;
}
#endif
/* /*
* Convert jiffies to milliseconds and back. * Convert jiffies to milliseconds and back.
* *
......
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