Skip to content

Commit 394db20

Browse files
yyu-intel-comIngo Molnar
authored andcommitted
x86/fpu: Disable AVX when eagerfpu is off
When "eagerfpu=off" is given as a command-line input, the kernel should disable AVX support. The Task Switched bit used for lazy context switching does not support AVX. If AVX is enabled without eagerfpu context switching, one task's AVX state could become corrupted or leak to other tasks. This is a bug and has bad security implications. This only affects systems that have AVX/AVX2/AVX512 and this issue will be found only when one actually uses AVX/AVX2/AVX512 _AND_ does eagerfpu=off. Reference: Intel Software Developer's Manual Vol. 3A Sec. 2.5 Control Registers: TS Task Switched bit (bit 3 of CR0) -- Allows the saving of the x87 FPU/ MMX/SSE/SSE2/SSE3/SSSE3/SSE4 context on a task switch to be delayed until an x87 FPU/MMX/SSE/SSE2/SSE3/SSSE3/SSE4 instruction is actually executed by the new task. Sec. 13.4.1 Using the TS Flag to Control the Saving of the X87 FPU and SSE State When the TS flag is set, the processor monitors the instruction stream for x87 FPU, MMX, SSE instructions. When the processor detects one of these instructions, it raises a device-not-available exeception (#NM) prior to executing the instruction. Signed-off-by: Yu-cheng Yu <yu-cheng.yu@intel.com> Cc: Andy Lutomirski <luto@amacapital.net> Cc: Borislav Petkov <bp@alien8.de> Cc: Borislav Petkov <bp@suse.de> Cc: Dave Hansen <dave.hansen@linux.intel.com> Cc: Fenghua Yu <fenghua.yu@intel.com> Cc: H. Peter Anvin <hpa@zytor.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Oleg Nesterov <oleg@redhat.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Quentin Casasnovas <quentin.casasnovas@oracle.com> Cc: Ravi V. Shankar <ravi.v.shankar@intel.com> Cc: Sai Praneeth Prakhya <sai.praneeth.prakhya@intel.com> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: yu-cheng yu <yu-cheng.yu@intel.com> Link: http://lkml.kernel.org/r/1452119094-7252-5-git-send-email-yu-cheng.yu@intel.com Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent a5fe93a commit 394db20

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

arch/x86/include/asm/fpu/xstate.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,16 @@
2020

2121
/* Supported features which support lazy state saving */
2222
#define XFEATURE_MASK_LAZY (XFEATURE_MASK_FP | \
23-
XFEATURE_MASK_SSE | \
23+
XFEATURE_MASK_SSE)
24+
25+
/* Supported features which require eager state saving */
26+
#define XFEATURE_MASK_EAGER (XFEATURE_MASK_BNDREGS | \
27+
XFEATURE_MASK_BNDCSR | \
2428
XFEATURE_MASK_YMM | \
25-
XFEATURE_MASK_OPMASK | \
29+
XFEATURE_MASK_OPMASK | \
2630
XFEATURE_MASK_ZMM_Hi256 | \
2731
XFEATURE_MASK_Hi16_ZMM)
2832

29-
/* Supported features which require eager state saving */
30-
#define XFEATURE_MASK_EAGER (XFEATURE_MASK_BNDREGS | XFEATURE_MASK_BNDCSR)
31-
3233
/* All currently supported features */
3334
#define XCNTXT_MASK (XFEATURE_MASK_LAZY | XFEATURE_MASK_EAGER)
3435

arch/x86/kernel/fpu/init.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,12 @@ u64 __init fpu__get_supported_xfeatures_mask(void)
300300
static void __init fpu__clear_eager_fpu_features(void)
301301
{
302302
setup_clear_cpu_cap(X86_FEATURE_MPX);
303+
setup_clear_cpu_cap(X86_FEATURE_AVX);
304+
setup_clear_cpu_cap(X86_FEATURE_AVX2);
305+
setup_clear_cpu_cap(X86_FEATURE_AVX512F);
306+
setup_clear_cpu_cap(X86_FEATURE_AVX512PF);
307+
setup_clear_cpu_cap(X86_FEATURE_AVX512ER);
308+
setup_clear_cpu_cap(X86_FEATURE_AVX512CD);
303309
}
304310

305311
/*

0 commit comments

Comments
 (0)