]> git.hungrycats.org Git - linux/commitdiff
s390/runtime instrumention: fix possible memory corruption
authorHeiko Carstens <heiko.carstens@de.ibm.com>
Mon, 11 Sep 2017 09:24:22 +0000 (11:24 +0200)
committerSasha Levin <alexander.levin@verizon.com>
Fri, 8 Dec 2017 23:00:59 +0000 (18:00 -0500)
[ Upstream commit d6e646ad7cfa7034d280459b2b2546288f247144 ]

For PREEMPT enabled kernels the runtime instrumentation (RI) code
contains a possible use-after-free bug. If a task that makes use of RI
exits, it will execute do_exit() while still enabled for preemption.

That function will call exit_thread_runtime_instr() via
exit_thread(). If exit_thread_runtime_instr() gets preempted after the
RI control block of the task has been freed but before the pointer to
it is set to NULL, then save_ri_cb(), called from switch_to(), will
write to already freed memory.

Avoid this and simply disable preemption while freeing the control
block and setting the pointer to NULL.

Fixes: e4b8b3f33fca ("s390: add support for runtime instrumentation")
Cc: <stable@vger.kernel.org> # v3.7+
Reviewed-by: Christian Borntraeger <borntraeger@de.ibm.com>
Signed-off-by: Heiko Carstens <heiko.carstens@de.ibm.com>
Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
Signed-off-by: Sasha Levin <alexander.levin@verizon.com>
arch/s390/kernel/runtime_instr.c

index 26b4ae96fdd731b3e5cb82d6bb23a8799e9af80f..ddbec1054f75d022c8222b37fcf8eb40dfe6dce5 100644 (file)
@@ -53,12 +53,14 @@ void exit_thread_runtime_instr(void)
 {
        struct task_struct *task = current;
 
+       preempt_disable();
        if (!task->thread.ri_cb)
                return;
        disable_runtime_instr();
        kfree(task->thread.ri_cb);
        task->thread.ri_signum = 0;
        task->thread.ri_cb = NULL;
+       preempt_enable();
 }
 
 static void runtime_instr_int_handler(struct ext_code ext_code,
@@ -100,9 +102,7 @@ SYSCALL_DEFINE2(s390_runtime_instr, int, command, int, signum)
                return -EOPNOTSUPP;
 
        if (command == S390_RUNTIME_INSTR_STOP) {
-               preempt_disable();
                exit_thread_runtime_instr();
-               preempt_enable();
                return 0;
        }