diff options
author | Andy Lutomirski <luto@amacapital.net> | 2015-02-12 18:01:14 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2015-02-12 21:54:12 -0500 |
commit | f56141e3e2d9aabf7e6b89680ab572c2cdbb2a24 (patch) | |
tree | 481e3d99bc1121ce75d505d340153b9d158e60c5 /kernel | |
parent | edc924e023ae2022fc29f1246e115c610c9abf38 (diff) |
all arches, signal: move restart_block to struct task_struct
If an attacker can cause a controlled kernel stack overflow, overwriting
the restart block is a very juicy exploit target. This is because the
restart_block is held in the same memory allocation as the kernel stack.
Moving the restart block to struct task_struct prevents this exploit by
making the restart_block harder to locate.
Note that there are other fields in thread_info that are also easy
targets, at least on some architectures.
It's also a decent simplification, since the restart code is more or less
identical on all architectures.
[james.hogan@imgtec.com: metag: align thread_info::supervisor_stack]
Signed-off-by: Andy Lutomirski <luto@amacapital.net>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Kees Cook <keescook@chromium.org>
Cc: David Miller <davem@davemloft.net>
Acked-by: Richard Weinberger <richard@nod.at>
Cc: Richard Henderson <rth@twiddle.net>
Cc: Ivan Kokshaysky <ink@jurassic.park.msu.ru>
Cc: Matt Turner <mattst88@gmail.com>
Cc: Vineet Gupta <vgupta@synopsys.com>
Cc: Russell King <rmk@arm.linux.org.uk>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Will Deacon <will.deacon@arm.com>
Cc: Haavard Skinnemoen <hskinnemoen@gmail.com>
Cc: Hans-Christian Egtvedt <egtvedt@samfundet.no>
Cc: Steven Miao <realmz6@gmail.com>
Cc: Mark Salter <msalter@redhat.com>
Cc: Aurelien Jacquiot <a-jacquiot@ti.com>
Cc: Mikael Starvik <starvik@axis.com>
Cc: Jesper Nilsson <jesper.nilsson@axis.com>
Cc: David Howells <dhowells@redhat.com>
Cc: Richard Kuo <rkuo@codeaurora.org>
Cc: "Luck, Tony" <tony.luck@intel.com>
Cc: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: Michal Simek <monstr@monstr.eu>
Cc: Ralf Baechle <ralf@linux-mips.org>
Cc: Jonas Bonn <jonas@southpole.se>
Cc: "James E.J. Bottomley" <jejb@parisc-linux.org>
Cc: Helge Deller <deller@gmx.de>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Paul Mackerras <paulus@samba.org>
Acked-by: Michael Ellerman <mpe@ellerman.id.au> (powerpc)
Tested-by: Michael Ellerman <mpe@ellerman.id.au> (powerpc)
Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
Cc: Chen Liqin <liqin.linux@gmail.com>
Cc: Lennox Wu <lennox.wu@gmail.com>
Cc: Chris Metcalf <cmetcalf@ezchip.com>
Cc: Guan Xuetao <gxt@mprc.pku.edu.cn>
Cc: Chris Zankel <chris@zankel.net>
Cc: Max Filippov <jcmvbkbc@gmail.com>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: James Hogan <james.hogan@imgtec.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'kernel')
-rw-r--r-- | kernel/compat.c | 5 | ||||
-rw-r--r-- | kernel/futex.c | 2 | ||||
-rw-r--r-- | kernel/signal.c | 2 | ||||
-rw-r--r-- | kernel/time/alarmtimer.c | 2 | ||||
-rw-r--r-- | kernel/time/hrtimer.c | 2 | ||||
-rw-r--r-- | kernel/time/posix-cpu-timers.c | 3 |
6 files changed, 7 insertions, 9 deletions
diff --git a/kernel/compat.c b/kernel/compat.c index ebb3c369d03d..24f00610c575 100644 --- a/kernel/compat.c +++ b/kernel/compat.c | |||
@@ -276,8 +276,7 @@ COMPAT_SYSCALL_DEFINE2(nanosleep, struct compat_timespec __user *, rqtp, | |||
276 | * core implementation decides to return random nonsense. | 276 | * core implementation decides to return random nonsense. |
277 | */ | 277 | */ |
278 | if (ret == -ERESTART_RESTARTBLOCK) { | 278 | if (ret == -ERESTART_RESTARTBLOCK) { |
279 | struct restart_block *restart | 279 | struct restart_block *restart = ¤t->restart_block; |
280 | = ¤t_thread_info()->restart_block; | ||
281 | 280 | ||
282 | restart->fn = compat_nanosleep_restart; | 281 | restart->fn = compat_nanosleep_restart; |
283 | restart->nanosleep.compat_rmtp = rmtp; | 282 | restart->nanosleep.compat_rmtp = rmtp; |
@@ -860,7 +859,7 @@ COMPAT_SYSCALL_DEFINE4(clock_nanosleep, clockid_t, which_clock, int, flags, | |||
860 | return -EFAULT; | 859 | return -EFAULT; |
861 | 860 | ||
862 | if (err == -ERESTART_RESTARTBLOCK) { | 861 | if (err == -ERESTART_RESTARTBLOCK) { |
863 | restart = ¤t_thread_info()->restart_block; | 862 | restart = ¤t->restart_block; |
864 | restart->fn = compat_clock_nanosleep_restart; | 863 | restart->fn = compat_clock_nanosleep_restart; |
865 | restart->nanosleep.compat_rmtp = rmtp; | 864 | restart->nanosleep.compat_rmtp = rmtp; |
866 | } | 865 | } |
diff --git a/kernel/futex.c b/kernel/futex.c index 4eeb63de7e54..2a5e3830e953 100644 --- a/kernel/futex.c +++ b/kernel/futex.c | |||
@@ -2217,7 +2217,7 @@ retry: | |||
2217 | if (!abs_time) | 2217 | if (!abs_time) |
2218 | goto out; | 2218 | goto out; |
2219 | 2219 | ||
2220 | restart = ¤t_thread_info()->restart_block; | 2220 | restart = ¤t->restart_block; |
2221 | restart->fn = futex_wait_restart; | 2221 | restart->fn = futex_wait_restart; |
2222 | restart->futex.uaddr = uaddr; | 2222 | restart->futex.uaddr = uaddr; |
2223 | restart->futex.val = val; | 2223 | restart->futex.val = val; |
diff --git a/kernel/signal.c b/kernel/signal.c index 16a305295256..33a52759cc0e 100644 --- a/kernel/signal.c +++ b/kernel/signal.c | |||
@@ -2501,7 +2501,7 @@ EXPORT_SYMBOL(unblock_all_signals); | |||
2501 | */ | 2501 | */ |
2502 | SYSCALL_DEFINE0(restart_syscall) | 2502 | SYSCALL_DEFINE0(restart_syscall) |
2503 | { | 2503 | { |
2504 | struct restart_block *restart = ¤t_thread_info()->restart_block; | 2504 | struct restart_block *restart = ¤t->restart_block; |
2505 | return restart->fn(restart); | 2505 | return restart->fn(restart); |
2506 | } | 2506 | } |
2507 | 2507 | ||
diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c index a7077d3ae52f..1b001ed1edb9 100644 --- a/kernel/time/alarmtimer.c +++ b/kernel/time/alarmtimer.c | |||
@@ -788,7 +788,7 @@ static int alarm_timer_nsleep(const clockid_t which_clock, int flags, | |||
788 | goto out; | 788 | goto out; |
789 | } | 789 | } |
790 | 790 | ||
791 | restart = ¤t_thread_info()->restart_block; | 791 | restart = ¤t->restart_block; |
792 | restart->fn = alarm_timer_nsleep_restart; | 792 | restart->fn = alarm_timer_nsleep_restart; |
793 | restart->nanosleep.clockid = type; | 793 | restart->nanosleep.clockid = type; |
794 | restart->nanosleep.expires = exp.tv64; | 794 | restart->nanosleep.expires = exp.tv64; |
diff --git a/kernel/time/hrtimer.c b/kernel/time/hrtimer.c index 3f5e183c3d97..bee0c1f78091 100644 --- a/kernel/time/hrtimer.c +++ b/kernel/time/hrtimer.c | |||
@@ -1583,7 +1583,7 @@ long hrtimer_nanosleep(struct timespec *rqtp, struct timespec __user *rmtp, | |||
1583 | goto out; | 1583 | goto out; |
1584 | } | 1584 | } |
1585 | 1585 | ||
1586 | restart = ¤t_thread_info()->restart_block; | 1586 | restart = ¤t->restart_block; |
1587 | restart->fn = hrtimer_nanosleep_restart; | 1587 | restart->fn = hrtimer_nanosleep_restart; |
1588 | restart->nanosleep.clockid = t.timer.base->clockid; | 1588 | restart->nanosleep.clockid = t.timer.base->clockid; |
1589 | restart->nanosleep.rmtp = rmtp; | 1589 | restart->nanosleep.rmtp = rmtp; |
diff --git a/kernel/time/posix-cpu-timers.c b/kernel/time/posix-cpu-timers.c index a16b67859e2a..0075da74abf0 100644 --- a/kernel/time/posix-cpu-timers.c +++ b/kernel/time/posix-cpu-timers.c | |||
@@ -1334,8 +1334,7 @@ static long posix_cpu_nsleep_restart(struct restart_block *restart_block); | |||
1334 | static int posix_cpu_nsleep(const clockid_t which_clock, int flags, | 1334 | static int posix_cpu_nsleep(const clockid_t which_clock, int flags, |
1335 | struct timespec *rqtp, struct timespec __user *rmtp) | 1335 | struct timespec *rqtp, struct timespec __user *rmtp) |
1336 | { | 1336 | { |
1337 | struct restart_block *restart_block = | 1337 | struct restart_block *restart_block = ¤t->restart_block; |
1338 | ¤t_thread_info()->restart_block; | ||
1339 | struct itimerspec it; | 1338 | struct itimerspec it; |
1340 | int error; | 1339 | int error; |
1341 | 1340 | ||