• Andi Kleen's avatar
    [PATCH] x86_64: Fix signal FPU leak on i386 and x86-64 · a3e64936
    Andi Kleen authored
    Found by Bodo Stroesser. Description from Bodo:
    
    >>
    On i386, if a signal handler is started, the kernel saves the fpu-state
    of the interrupted routine in the sigcontext on the stack. Calling
    unlazy_fpu() and setting current->used_math=0, the kernel supplies the
    signal-handler with a cleared virtual fpu.
    On sigreturn(), the old fpu-state of the interrupted routine is
    restored.
    
    If a process never used the fpu, it virtually has a cleared fpu.
    If such a process is interrupted by a signal handler, no fpu-context is
    saved and sigcontext->fpstate is set to NULL.
    
    Assume, that the signal handler uses the fpu. Then, AFAICS, on sigreturn
    current->used_math will be 1. Since sigcontext->fpstate still is NULL,
    restore_sigcontext() doesn't call restore_i387(). Thus, no
    clear_fpu() is done, current->used_math is not reset.
    
    Now, the interrupted processes fpu no longer is cleared!
    <<
    
    Fix by AK. Just clear the FPU again when this happens.
    
    patch for i386 and x86-64.
    Signed-off-by: default avatarAndi Kleen <ak@suse.de>
    Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
    Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
    a3e64936
signal.c 16.6 KB