Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1659538
| From | Al Viro <viro@ZenIV.linux.org.uk> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | [PATCH 12/16] move compat itimer syscalls to native ones |
| Date | 2017-06-07 10:50 +0200 |
| Message-ID | <tPEP8-4gO-29@gated-at.bofh.it> (permalink) |
| References | <tPEP7-4gO-5@gated-at.bofh.it> <tPEP7-4gO-7@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
From: Al Viro <viro@zeniv.linux.org.uk>
get rid of set_fs(), sanitize compat copyin/copyout.
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
---
include/linux/compat.h | 4 +++
kernel/compat.c | 71 +++++++++++------------------------------------
kernel/time/itimer.c | 36 ++++++++++++++++++++++++
kernel/time/posix-stubs.c | 2 ++
4 files changed, 58 insertions(+), 55 deletions(-)
diff --git a/include/linux/compat.h b/include/linux/compat.h
index ecb8dd261d36..425563c7647b 100644
--- a/include/linux/compat.h
+++ b/include/linux/compat.h
@@ -94,6 +94,10 @@ struct compat_itimerval {
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 {
compat_clock_t tms_utime;
compat_clock_t tms_stime;
diff --git a/kernel/compat.c b/kernel/compat.c
index 1fb8cf7e691e..61e3be4cbd2a 100644
--- a/kernel/compat.c
+++ b/kernel/compat.c
@@ -217,65 +217,26 @@ int compat_convert_timespec(struct timespec __user **kts,
return 0;
}
-static inline long get_compat_itimerval(struct itimerval *o,
- struct compat_itimerval __user *i)
+int get_compat_itimerval(struct itimerval *o, const struct compat_itimerval __user *i)
{
- return (!access_ok(VERIFY_READ, i, sizeof(*i)) ||
- (__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 (!error && put_compat_itimerval(it, &kit))
- error = -EFAULT;
- return error;
+ struct compat_itimerval v32;
+ if (copy_from_user(&v32, i, sizeof(struct compat_itimerval)))
+ return -EFAULT;
+ o->it_interval.tv_sec = v32.it_interval.tv_sec;
+ 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,
- struct compat_itimerval __user *, in,
- struct compat_itimerval __user *, out)
+int put_compat_itimerval(struct compat_itimerval __user *o, const struct itimerval *i)
{
- struct itimerval kin, kout;
- int error;
-
- if (!IS_ENABLED(CONFIG_POSIX_TIMERS))
- return sys_ni_posix_timers();
-
- 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;
+ struct compat_itimerval v32;
+ v32.it_interval.tv_sec = i->it_interval.tv_sec;
+ v32.it_interval.tv_usec = i->it_interval.tv_usec;
+ v32.it_value.tv_sec = i->it_value.tv_sec;
+ v32.it_value.tv_usec = i->it_value.tv_usec;
+ return copy_to_user(o, &v32, sizeof(struct compat_itimerval)) ? -EFAULT : 0;
}
static compat_clock_t clock_t_to_compat_clock_t(clock_t x)
diff --git a/kernel/time/itimer.c b/kernel/time/itimer.c
index 087d6a1279b8..b23c48dde3da 100644
--- a/kernel/time/itimer.c
+++ b/kernel/time/itimer.c
@@ -15,6 +15,7 @@
#include <linux/posix-timers.h>
#include <linux/hrtimer.h>
#include <trace/events/timer.h>
+#include <linux/compat.h>
#include <linux/uaccess.h>
@@ -116,6 +117,18 @@ SYSCALL_DEFINE2(getitimer, int, which, struct itimerval __user *, value)
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
@@ -294,3 +307,26 @@ SYSCALL_DEFINE3(setitimer, int, which, struct itimerval __user *, value,
return -EFAULT;
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
diff --git a/kernel/time/posix-stubs.c b/kernel/time/posix-stubs.c
index c6d3cde2edc6..369df2f9a9ff 100644
--- a/kernel/time/posix-stubs.c
+++ b/kernel/time/posix-stubs.c
@@ -44,6 +44,8 @@ SYS_NI(alarm);
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
--
2.11.0
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[PATCH 01/16] move copyout of timespec into do_cpu_nanosleep() Al Viro <viro@ZenIV.linux.org.uk> - 2017-06-07 10:50 +0200
[PATCH 06/16] nanosleep/clock_nanosleep: teach to do compat copyouts Al Viro <viro@ZenIV.linux.org.uk> - 2017-06-07 10:50 +0200
Re: [PATCH 06/16] nanosleep/clock_nanosleep: teach to do compat copyouts Peter Zijlstra <peterz@infradead.org> - 2017-06-07 12:10 +0200
[tip:timers/core] time/posix-timers: Move the compat copyouts to the nanosleep implementations tip-bot for Al Viro <tipbot@zytor.com> - 2017-06-14 00:20 +0200
[PATCH 15/16] time()/stime(): move compat to native Al Viro <viro@ZenIV.linux.org.uk> - 2017-06-07 10:50 +0200
[tip:timers/core] time: Move compat_time()/stime() to native tip-bot for Al Viro <tipbot@zytor.com> - 2017-06-14 00:20 +0200
[PATCH 12/16] move compat itimer syscalls to native ones Al Viro <viro@ZenIV.linux.org.uk> - 2017-06-07 10:50 +0200
[tip:timers/core] itimers: Move compat itimer syscalls to native ones tip-bot for Al Viro <tipbot@zytor.com> - 2017-06-14 00:20 +0200
[PATCH 04/16] move copyout to do_nanosleel() Al Viro <viro@ZenIV.linux.org.uk> - 2017-06-07 10:50 +0200
[tip:timers/core] hrtimer: Move copyout of remaining time to do_nanosleep() tip-bot for Al Viro <tipbot@zytor.com> - 2017-06-14 00:10 +0200
[PATCH 14/16] timer_create(): move compat to native, get rid of set_fs() Al Viro <viro@ZenIV.linux.org.uk> - 2017-06-07 10:50 +0200
[tip:timers/core] posix-timers: Move compat_timer_create() to native, get rid of set_fs() tip-bot for Al Viro <tipbot@zytor.com> - 2017-06-14 00:20 +0200
[PATCH 09/16] move adjtimex-related compat syscalls to native counterparts Al Viro <viro@ZenIV.linux.org.uk> - 2017-06-07 10:50 +0200
[tip:timers/core] ntp: Move adjtimex related compat syscalls to native counterparts tip-bot for Al Viro <tipbot@zytor.com> - 2017-06-14 00:20 +0200
[PATCH 03/16] hrtimer_nanosleep(): pass rmtp in restart_block Al Viro <viro@ZenIV.linux.org.uk> - 2017-06-07 10:50 +0200
[tip:timers/core] hrtimer_nanosleep(): Pass rmtp in restart_block tip-bot for Al Viro <tipbot@zytor.com> - 2017-06-14 00:10 +0200
[PATCH 08/16] kill ->nsleep_restart() Al Viro <viro@ZenIV.linux.org.uk> - 2017-06-07 10:50 +0200
[tip:timers/core] posix-timers: Kill ->nsleep_restart() tip-bot for Al Viro <tipbot@zytor.com> - 2017-06-14 00:20 +0200
[PATCH 10/16] take compat timer_settime(2) to native one Al Viro <viro@ZenIV.linux.org.uk> - 2017-06-07 10:50 +0200
[tip:timers/core] posix-timers: Take compat timer_settime(2) to native one tip-bot for Al Viro <tipbot@zytor.com> - 2017-06-14 00:20 +0200
Re: [PATCH 01/16] move copyout of timespec into do_cpu_nanosleep() Thomas Gleixner <tglx@linutronix.de> - 2017-06-13 01:10 +0200
Re: [PATCH 01/16] move copyout of timespec into do_cpu_nanosleep() Thomas Gleixner <tglx@linutronix.de> - 2017-06-13 09:50 +0200
[tip:timers/core] posix-cpu-timers: Move copyout of timespec into do_cpu_nanosleep() tip-bot for Al Viro <tipbot@zytor.com> - 2017-06-14 00:10 +0200
csiph-web