The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Andi Kleen <andi@firstfloor.org>
To: x86@kernel.org
Cc: linux-kernel@vger.kernel.org, Andi Kleen <ak@linux.intel.com>
Subject: [PATCH] x86: Reset FPU on exec
Date: Fri, 17 Apr 2015 18:06:54 -0700	[thread overview]
Message-ID: <1429319214-27418-1-git-send-email-andi@firstfloor.org> (raw)

From: Andi Kleen <ak@linux.intel.com>

Currently we don't reset FPU state on exec. This can be seen as a
(minor) security issue. The bigger issue however is that the
AVX state also does not get reset. So a program that uses SSE
without VZEROUPPER may get a large penalty.

Always set the FPU to the init state at exec time.

For the eager FPU case this restores the init state,
for non eager it forces an init on the next FPU use.

Signed-off-by: Andi Kleen <ak@linux.intel.com>
---
 arch/x86/include/asm/elf.h | 4 ++++
 arch/x86/kernel/xsave.c    | 5 +++++
 2 files changed, 9 insertions(+)

diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
index ca3347a..56ab629 100644
--- a/arch/x86/include/asm/elf.h
+++ b/arch/x86/include/asm/elf.h
@@ -90,6 +90,8 @@ extern unsigned int vdso32_enabled;
 
 #include <asm/processor.h>
 
+extern void reset_fpu(void);
+
 #ifdef CONFIG_X86_32
 #include <asm/desc.h>
 
@@ -110,6 +112,7 @@ extern unsigned int vdso32_enabled;
 	_r->bx = 0; _r->cx = 0; _r->dx = 0;	\
 	_r->si = 0; _r->di = 0; _r->bp = 0;	\
 	_r->ax = 0;				\
+	reset_fpu();				\
 } while (0)
 
 /*
@@ -178,6 +181,7 @@ static inline void elf_common_init(struct thread_struct *t,
 	t->fs = t->gs = 0;
 	t->fsindex = t->gsindex = 0;
 	t->ds = t->es = ds;
+	reset_fpu();
 }
 
 #define ELF_PLAT_INIT(_r, load_addr)			\
diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
index cdc6cf9..520e505 100644
--- a/arch/x86/kernel/xsave.c
+++ b/arch/x86/kernel/xsave.c
@@ -741,3 +741,8 @@ void *get_xsave_addr(struct xsave_struct *xsave, int xstate)
 	return (void *)xsave + xstate_comp_offsets[feature];
 }
 EXPORT_SYMBOL_GPL(get_xsave_addr);
+
+void reset_fpu(void)
+{
+	drop_init_fpu(current);
+}
-- 
1.9.3


             reply	other threads:[~2015-04-18  1:06 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-18  1:06 Andi Kleen [this message]
2015-04-21  9:35 ` [PATCH] x86: Reset FPU on exec Thomas Gleixner
2015-04-21 13:51   ` Andi Kleen
2015-04-21 14:23     ` Thomas Gleixner

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=1429319214-27418-1-git-send-email-andi@firstfloor.org \
    --to=andi@firstfloor.org \
    --cc=ak@linux.intel.com \
    --cc=linux-kernel@vger.kernel.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