summaryrefslogtreecommitdiff
path: root/arch/s390/kernel/guarded_storage.c
diff options
context:
space:
mode:
authorHeiko Carstens <heiko.carstens@de.ibm.com>2017-09-11 12:24:22 +0300
committerMartin Schwidefsky <schwidefsky@de.ibm.com>2017-09-28 08:29:39 +0300
commitfa1edf3f63c05ca8eacafcd7048ed91e5360f1a8 (patch)
treedbbc2aeb26cff7505785b136cc947f7a2b2eb529 /arch/s390/kernel/guarded_storage.c
parent8d9047f8b967ce6181fd824ae922978e1b055cc0 (diff)
downloadlinux-fa1edf3f63c05ca8eacafcd7048ed91e5360f1a8.tar.xz
s390/guarded storage: fix possible memory corruption
For PREEMPT enabled kernels the guarded storage (GS) code contains a possible use-after-free bug. If a task that makes use of GS 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_gs() gets preempted after the GS control block of the task has been freed but before the pointer to it is set to NULL, then save_gs_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: 916cda1aa1b4 ("s390: add a system call for guarded storage") Cc: <stable@vger.kernel.org> # v4.12+ 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>
Diffstat (limited to 'arch/s390/kernel/guarded_storage.c')
-rw-r--r--arch/s390/kernel/guarded_storage.c2
1 files changed, 2 insertions, 0 deletions
diff --git a/arch/s390/kernel/guarded_storage.c b/arch/s390/kernel/guarded_storage.c
index 6f064745c3b1..4920cf6ffa00 100644
--- a/arch/s390/kernel/guarded_storage.c
+++ b/arch/s390/kernel/guarded_storage.c
@@ -13,9 +13,11 @@
void exit_thread_gs(void)
{
+ preempt_disable();
kfree(current->thread.gs_cb);
kfree(current->thread.gs_bc_cb);
current->thread.gs_cb = current->thread.gs_bc_cb = NULL;
+ preempt_enable();
}
static int gs_enable(void)