lkml.org 
[lkml]   [2015]   [Mar]   [5]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
Subject[PATCH 1/1] x86/fpu: math_state_restore() should not blindly disable irqs
math_state_restore() assumes it is called with irqs disabled, but
this is not true if the caller is __restore_xstate_sig().

This means that if ia32_fxstate == T and __copy_from_user() fails
__restore_xstate_sig() returns with irqs disabled too. This trgiggers

BUG: sleeping function called from invalid context at kernel/locking/rwsem.c:41
[<ffffffff81381499>] dump_stack+0x59/0xa0
[<ffffffff8106bd05>] ___might_sleep+0x105/0x110
[<ffffffff8138786d>] ? _raw_spin_unlock_irqrestore+0x3d/0x70
[<ffffffff8106bd8d>] __might_sleep+0x7d/0xb0
[<ffffffff81385426>] down_read+0x26/0xa0
[<ffffffff8138788a>] ? _raw_spin_unlock_irqrestore+0x5a/0x70
[<ffffffff81136038>] print_vma_addr+0x58/0x130
[<ffffffff8100239e>] signal_fault+0xbe/0xf0
[<ffffffff810419aa>] sys32_rt_sigreturn+0xba/0xd0

Change math_state_restore() to check irqs_disabled().

Note: this is the minimal fix for -stable, it is horrible but simple.
We need to rewrite math_state_restore(), init_fpu(), and cleanup their
users.

Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Cc: <stable@vger.kernel.org>
---
arch/x86/kernel/traps.c | 9 +++++++--
1 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
index 51c4658..7310e0e 100644
--- a/arch/x86/kernel/traps.c
+++ b/arch/x86/kernel/traps.c
@@ -774,7 +774,10 @@ void math_state_restore(void)
struct task_struct *tsk = current;

if (!tsk_used_math(tsk)) {
- local_irq_enable();
+ bool disabled = irqs_disabled();
+
+ if (disabled)
+ local_irq_enable();
/*
* does a slab alloc which can sleep
*/
@@ -785,7 +788,9 @@ void math_state_restore(void)
do_group_exit(SIGKILL);
return;
}
- local_irq_disable();
+
+ if (disabled)
+ local_irq_disable();
}

/* Avoid __kernel_fpu_begin() right after __thread_fpu_begin() */
--
1.5.5.1



\
 
 \ /
  Last update: 2015-03-05 21:01    [W:1.052 / U:0.036 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site