]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/4.4.103/s390-runtime-instrumention-fix-possible-memory-corruption.patch
4.14-stable patches
[thirdparty/kernel/stable-queue.git] / releases / 4.4.103 / s390-runtime-instrumention-fix-possible-memory-corruption.patch
1 From d6e646ad7cfa7034d280459b2b2546288f247144 Mon Sep 17 00:00:00 2001
2 From: Heiko Carstens <heiko.carstens@de.ibm.com>
3 Date: Mon, 11 Sep 2017 11:24:22 +0200
4 Subject: s390/runtime instrumention: fix possible memory corruption
5
6 From: Heiko Carstens <heiko.carstens@de.ibm.com>
7
8 commit d6e646ad7cfa7034d280459b2b2546288f247144 upstream.
9
10 For PREEMPT enabled kernels the runtime instrumentation (RI) code
11 contains a possible use-after-free bug. If a task that makes use of RI
12 exits, it will execute do_exit() while still enabled for preemption.
13
14 That function will call exit_thread_runtime_instr() via
15 exit_thread(). If exit_thread_runtime_instr() gets preempted after the
16 RI control block of the task has been freed but before the pointer to
17 it is set to NULL, then save_ri_cb(), called from switch_to(), will
18 write to already freed memory.
19
20 Avoid this and simply disable preemption while freeing the control
21 block and setting the pointer to NULL.
22
23 Fixes: e4b8b3f33fca ("s390: add support for runtime instrumentation")
24 Reviewed-by: Christian Borntraeger <borntraeger@de.ibm.com>
25 Signed-off-by: Heiko Carstens <heiko.carstens@de.ibm.com>
26 Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
27 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
28
29 ---
30 arch/s390/kernel/runtime_instr.c | 4 ++--
31 1 file changed, 2 insertions(+), 2 deletions(-)
32
33 --- a/arch/s390/kernel/runtime_instr.c
34 +++ b/arch/s390/kernel/runtime_instr.c
35 @@ -47,11 +47,13 @@ void exit_thread_runtime_instr(void)
36 {
37 struct task_struct *task = current;
38
39 + preempt_disable();
40 if (!task->thread.ri_cb)
41 return;
42 disable_runtime_instr();
43 kfree(task->thread.ri_cb);
44 task->thread.ri_cb = NULL;
45 + preempt_enable();
46 }
47
48 SYSCALL_DEFINE1(s390_runtime_instr, int, command)
49 @@ -62,9 +64,7 @@ SYSCALL_DEFINE1(s390_runtime_instr, int,
50 return -EOPNOTSUPP;
51
52 if (command == S390_RUNTIME_INSTR_STOP) {
53 - preempt_disable();
54 exit_thread_runtime_instr();
55 - preempt_enable();
56 return 0;
57 }
58