Commit 6ffac1e9 authored by Suresh Siddha's avatar Suresh Siddha Committed by Ingo Molnar

x64, fpu: fix possible FPU leakage in error conditions

On Thu, Jul 24, 2008 at 03:43:44PM -0700, Linus Torvalds wrote:
> So how about this patch as a starting point? This is the RightThing(tm) to
> do regardless, and if it then makes it easier to do some other cleanups,
> we should do it first. What do you think?

restore_fpu_checking() calls init_fpu() in error conditions.

While this is wrong(as our main intention is to clear the fpu state of
the thread), this was benign before commit 92d140e2 ("x86: fix taking
DNA during 64bit sigreturn").

Post commit 92d140e2, live FPU registers may not belong to this
process at this error scenario.

In the error condition for restore_fpu_checking() (especially during the
64bit signal return), we are doing init_fpu(), which saves the live FPU
register state (possibly belonging to some other process context) into
the thread struct (through unlazy_fpu() in init_fpu()). This is wrong
and can leak the FPU data.

For the signal handler restore error condition in restore_i387(), clear
the fpu state present in the thread struct(before ultimately sending a
SIGSEGV for badframe).

For the paranoid error condition check in math_state_restore(), send a
SIGSEGV, if we fail to restore the state.
Signed-off-by: default avatarSuresh Siddha <suresh.b.siddha@intel.com>
Cc: <stable@kernel.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: default avatarIngo Molnar <mingo@elte.hu>
parent 024e8ac0
...@@ -104,7 +104,16 @@ static inline int restore_i387(struct _fpstate __user *buf) ...@@ -104,7 +104,16 @@ static inline int restore_i387(struct _fpstate __user *buf)
clts(); clts();
task_thread_info(current)->status |= TS_USEDFPU; task_thread_info(current)->status |= TS_USEDFPU;
} }
return restore_fpu_checking((__force struct i387_fxsave_struct *)buf); err = restore_fpu_checking((__force struct i387_fxsave_struct *)buf);
if (unlikely(err)) {
/*
* Encountered an error while doing the restore from the
* user buffer, clear the fpu state.
*/
clear_fpu(tsk);
clear_used_math();
}
return err;
} }
/* /*
......
...@@ -1131,7 +1131,14 @@ asmlinkage void math_state_restore(void) ...@@ -1131,7 +1131,14 @@ asmlinkage void math_state_restore(void)
} }
clts(); /* Allow maths ops (or we recurse) */ clts(); /* Allow maths ops (or we recurse) */
restore_fpu_checking(&me->thread.xstate->fxsave); /*
* Paranoid restore. send a SIGSEGV if we fail to restore the state.
*/
if (unlikely(restore_fpu_checking(&me->thread.xstate->fxsave))) {
stts();
force_sig(SIGSEGV, me);
return;
}
task_thread_info(me)->status |= TS_USEDFPU; task_thread_info(me)->status |= TS_USEDFPU;
me->fpu_counter++; me->fpu_counter++;
} }
......
...@@ -62,8 +62,6 @@ static inline int restore_fpu_checking(struct i387_fxsave_struct *fx) ...@@ -62,8 +62,6 @@ static inline int restore_fpu_checking(struct i387_fxsave_struct *fx)
#else #else
: [fx] "cdaSDb" (fx), "m" (*fx), "0" (0)); : [fx] "cdaSDb" (fx), "m" (*fx), "0" (0));
#endif #endif
if (unlikely(err))
init_fpu(current);
return err; return err;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment