• Sebastian Andrzej Siewior's avatar
    x86/fpu: Remove fpu->initialized usage in __fpu__restore_sig() · 39ea9baf
    Sebastian Andrzej Siewior authored
    This is a preparation for the removal of the ->initialized member in the
    fpu struct.
    
    __fpu__restore_sig() is deactivating the FPU via fpu__drop() and then
    setting manually ->initialized followed by fpu__restore(). The result is
    that it is possible to manipulate fpu->state and the state of registers
    won't be saved/restored on a context switch which would overwrite
    fpu->state:
    
    fpu__drop(fpu):
      ...
      fpu->initialized = 0;
      preempt_enable();
    
      <--- context switch
    
    Don't access the fpu->state while the content is read from user space
    and examined/sanitized. Use a temporary kmalloc() buffer for the
    preparation of the FPU registers and once the state is considered okay,
    load it. Should something go wrong, return with an error and without
    altering the original FPU registers.
    
    The removal of fpu__initialize() is a nop because fpu->initialized is
    already set for the user task.
    
     [ bp: Massage a bit. ]
    Signed-off-by: default avatarSebastian Andrzej Siewior <bigeasy@linutronix.de>
    Signed-off-by: default avatarBorislav Petkov <bp@suse.de>
    Reviewed-by: default avatarDave Hansen <dave.hansen@intel.com>
    Reviewed-by: default avatarThomas Gleixner <tglx@linutronix.de>
    Acked-by: default avatarBorislav Petkov <bp@suse.de>
    Cc: Andy Lutomirski <luto@kernel.org>
    Cc: "H. Peter Anvin" <hpa@zytor.com>
    Cc: Ingo Molnar <mingo@redhat.com>
    Cc: Jann Horn <jannh@google.com>
    Cc: "Jason A. Donenfeld" <Jason@zx2c4.com>
    Cc: kvm ML <kvm@vger.kernel.org>
    Cc: Paolo Bonzini <pbonzini@redhat.com>
    Cc: Radim Krčmář <rkrcmar@redhat.com>
    Cc: Rik van Riel <riel@surriel.com>
    Cc: x86-ml <x86@kernel.org>
    Link: https://lkml.kernel.org/r/20190403164156.19645-2-bigeasy@linutronix.de
    39ea9baf
signal.h 1.03 KB