From: Suresh Siddha <suresh.b.siddha@intel.com>
To: x86@kernel.org, andi@firstfloor.org, torvalds@linux-foundation.org
Cc: linux-kernel@vger.kernel.org, stable@kernel.org
Subject: [patch] x64, fpu: fix possible FPU leakage in error conditions
Date: Thu, 24 Jul 2008 11:04:29 -0700 [thread overview]
Message-ID: <20080724180429.GI14380@linux-os.sc.intel.com> (raw)
restore_fpu_checking() calls init_fpu() in error conditions. init_fpu()
just touches the FPU state in the thread struct and doesn't do anything
with the live FPU registers. While this is wrong(as our main intention is
to init the live FPU registers aswell), this was benign
before the commit 92d140e21f1ce8cf99320afbbcad73879128e6dc.
Post commit 92d140e21f1ce8cf99320afbbcad73879128e6dc, 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.
Remove the unlazy_fpu() from the init_fpu(). init_fpu() will now always
init the FPU data in the thread struct. For the error conditions in
restore_fpu_checking(), restore the initialized FPU data from the thread
struct.
Signed-off-by: Suresh Siddha <suresh.b.siddha@intel.com>
---
diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
index eb9ddd8..f5c2161 100644
--- a/arch/x86/kernel/i387.c
+++ b/arch/x86/kernel/i387.c
@@ -98,12 +98,6 @@ void __cpuinit fpu_init(void)
*/
int init_fpu(struct task_struct *tsk)
{
- if (tsk_used_math(tsk)) {
- if (HAVE_HWFP && tsk == current)
- unlazy_fpu(tsk);
- return 0;
- }
-
/*
* Memory allocation at the first usage of the FPU and other state.
*/
diff --git a/include/asm-x86/i387.h b/include/asm-x86/i387.h
index 37672f7..38af0ed 100644
--- a/include/asm-x86/i387.h
+++ b/include/asm-x86/i387.h
@@ -45,6 +45,12 @@ static inline void tolerant_fwait(void)
_ASM_EXTABLE(1b, 2b));
}
+static inline void restore_fpu(struct i387_fxsave_struct *fx)
+{
+ __asm__ __volatile__("rex64/fxrstor (%[fx])"
+ :: [fx] "cdaSDb" (fx), "m" (*fx));
+}
+
static inline int restore_fpu_checking(struct i387_fxsave_struct *fx)
{
int err;
@@ -62,8 +68,10 @@ static inline int restore_fpu_checking(struct i387_fxsave_struct *fx)
#else
: [fx] "cdaSDb" (fx), "m" (*fx), "0" (0));
#endif
- if (unlikely(err))
+ if (unlikely(err)) {
init_fpu(current);
+ restore_fpu(¤t->thread.xstate->fxsave);
+ }
return err;
}
next reply other threads:[~2008-07-24 18:05 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-07-24 18:04 Suresh Siddha [this message]
2008-07-24 18:31 ` [patch] x64, fpu: fix possible FPU leakage in error conditions Linus Torvalds
2008-07-24 18:50 ` Suresh Siddha
2008-07-24 18:59 ` Linus Torvalds
2008-07-24 20:27 ` Suresh Siddha
2008-07-24 20:30 ` Linus Torvalds
2008-07-24 21:23 ` Suresh Siddha
2008-07-24 21:54 ` Linus Torvalds
2008-07-24 22:25 ` Suresh Siddha
2008-07-24 22:43 ` Linus Torvalds
2008-07-24 23:02 ` Suresh Siddha
2008-07-24 23:06 ` Suresh Siddha
2008-07-24 23:16 ` Linus Torvalds
2008-07-25 1:07 ` Suresh Siddha
2008-07-26 14:37 ` Ingo Molnar
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20080724180429.GI14380@linux-os.sc.intel.com \
--to=suresh.b.siddha@intel.com \
--cc=andi@firstfloor.org \
--cc=linux-kernel@vger.kernel.org \
--cc=stable@kernel.org \
--cc=torvalds@linux-foundation.org \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox