]> rtime.felk.cvut.cz Git - hercules2020/nv-tegra/linux-4.4.git/commit
x86/fpu: Avoid math_state_restore() without used_math() in __restore_xstate_sig()
authorOleg Nesterov <oleg@redhat.com>
Fri, 13 Mar 2015 08:53:09 +0000 (09:53 +0100)
committerSasha Levin <sasha.levin@oracle.com>
Sat, 28 Mar 2015 14:03:51 +0000 (10:03 -0400)
commit1a29c27a0feda99289ddc41cb5dfbe010d37d374
treee77893a8094176430996beb44db585dc0b793ce7
parent3b389956156c23d7936f5a863cf7ac18a92dfee1
x86/fpu: Avoid math_state_restore() without used_math() in __restore_xstate_sig()

[ Upstream commit a7c80ebcac3068b1c3cb27d538d29558c30010c8 ]

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 triggers:

  BUG: sleeping function called from invalid context at kernel/locking/rwsem.c:41
   dump_stack
   ___might_sleep
   ? _raw_spin_unlock_irqrestore
   __might_sleep
   down_read
   ? _raw_spin_unlock_irqrestore
   print_vma_addr
   signal_fault
   sys32_rt_sigreturn

Change __restore_xstate_sig() to call set_used_math()
unconditionally. This avoids enabling and disabling interrupts
in math_state_restore(). If copy_from_user() fails, we can
simply do fpu_finit() by hand.

[ Note: this is only the first step. math_state_restore() should
        not check used_math(), it should set this flag. While
init_fpu() should simply die. ]

Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Signed-off-by: Borislav Petkov <bp@suse.de>
Cc: <stable@vger.kernel.org>
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Dave Hansen <dave.hansen@intel.com>
Cc: Fenghua Yu <fenghua.yu@intel.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Pekka Riikonen <priikone@iki.fi>
Cc: Quentin Casasnovas <quentin.casasnovas@oracle.com>
Cc: Rik van Riel <riel@redhat.com>
Cc: Suresh Siddha <sbsiddha@gmail.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/20150307153844.GB25954@redhat.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
arch/x86/kernel/xsave.c