diff options
author | Suresh Siddha <suresh.b.siddha@intel.com> | 2008-07-24 21:07:56 -0400 |
---|---|---|
committer | Ingo Molnar <mingo@elte.hu> | 2008-07-26 10:37:04 -0400 |
commit | 6ffac1e90a17ea0aded5c581204397421eec91b6 (patch) | |
tree | c5ae5b695f1306f5415b5bf3968b4fcf69e823a1 /arch | |
parent | 024e8ac04453b3525448c31ef39848cf675ba6db (diff) |
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 92d140e21f1 ("x86: fix taking
DNA during 64bit sigreturn").
Post commit 92d140e21f1, 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: Suresh Siddha <suresh.b.siddha@intel.com>
Cc: <stable@kernel.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'arch')
-rw-r--r-- | arch/x86/kernel/signal_64.c | 11 | ||||
-rw-r--r-- | arch/x86/kernel/traps_64.c | 9 |
2 files changed, 18 insertions, 2 deletions
diff --git a/arch/x86/kernel/signal_64.c b/arch/x86/kernel/signal_64.c index b45ef8ddd651..ca316b5b742c 100644 --- a/arch/x86/kernel/signal_64.c +++ b/arch/x86/kernel/signal_64.c | |||
@@ -104,7 +104,16 @@ static inline int restore_i387(struct _fpstate __user *buf) | |||
104 | clts(); | 104 | clts(); |
105 | task_thread_info(current)->status |= TS_USEDFPU; | 105 | task_thread_info(current)->status |= TS_USEDFPU; |
106 | } | 106 | } |
107 | return restore_fpu_checking((__force struct i387_fxsave_struct *)buf); | 107 | err = restore_fpu_checking((__force struct i387_fxsave_struct *)buf); |
108 | if (unlikely(err)) { | ||
109 | /* | ||
110 | * Encountered an error while doing the restore from the | ||
111 | * user buffer, clear the fpu state. | ||
112 | */ | ||
113 | clear_fpu(tsk); | ||
114 | clear_used_math(); | ||
115 | } | ||
116 | return err; | ||
108 | } | 117 | } |
109 | 118 | ||
110 | /* | 119 | /* |
diff --git a/arch/x86/kernel/traps_64.c b/arch/x86/kernel/traps_64.c index 3f18d73f420c..513caaca7115 100644 --- a/arch/x86/kernel/traps_64.c +++ b/arch/x86/kernel/traps_64.c | |||
@@ -1131,7 +1131,14 @@ asmlinkage void math_state_restore(void) | |||
1131 | } | 1131 | } |
1132 | 1132 | ||
1133 | clts(); /* Allow maths ops (or we recurse) */ | 1133 | clts(); /* Allow maths ops (or we recurse) */ |
1134 | restore_fpu_checking(&me->thread.xstate->fxsave); | 1134 | /* |
1135 | * Paranoid restore. send a SIGSEGV if we fail to restore the state. | ||
1136 | */ | ||
1137 | if (unlikely(restore_fpu_checking(&me->thread.xstate->fxsave))) { | ||
1138 | stts(); | ||
1139 | force_sig(SIGSEGV, me); | ||
1140 | return; | ||
1141 | } | ||
1135 | task_thread_info(me)->status |= TS_USEDFPU; | 1142 | task_thread_info(me)->status |= TS_USEDFPU; |
1136 | me->fpu_counter++; | 1143 | me->fpu_counter++; |
1137 | } | 1144 | } |