aboutsummaryrefslogtreecommitdiffstats
path: root/arch/x86_64
diff options
context:
space:
mode:
authorAndi Kleen <ak@suse.de>2006-04-19 20:36:45 -0400
committerLinus Torvalds <torvalds@g5.osdl.org>2006-04-20 10:58:11 -0400
commit18bd057b1408cd110ed23281533430cfc2d52091 (patch)
tree09d8c44ebdb45763173fe54f6962921f4268cf9f /arch/x86_64
parent5dc5cf7dd2723430b6df3d91c5b22af49e063622 (diff)
[PATCH] i386/x86-64: Fix x87 information leak between processes
AMD K7/K8 CPUs only save/restore the FOP/FIP/FDP x87 registers in FXSAVE when an exception is pending. This means the value leak through context switches and allow processes to observe some x87 instruction state of other processes. This was actually documented by AMD, but nobody recognized it as being different from Intel before. The fix first adds an optimization: instead of unconditionally calling FNCLEX after each FXSAVE test if ES is pending and skip it when not needed. Then do a x87 load from a kernel variable to clear FOP/FIP/FDP. This means other processes always will only see a constant value defined by the kernel in their FP state. I took some pain to make sure to chose a variable that's already in L1 during context switch to make the overhead of this low. Also alternative() is used to patch away the new code on CPUs who don't need it. Patch for both i386/x86-64. The problem was discovered originally by Jan Beulich. Richard Brunner provided the basic code for the workarounds, with contribution from Jan. This is CVE-2006-1056 Cc: richard.brunner@amd.com Cc: jbeulich@novell.com Signed-off-by: Andi Kleen <ak@suse.de> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'arch/x86_64')
-rw-r--r--arch/x86_64/kernel/process.c4
-rw-r--r--arch/x86_64/kernel/setup.c4
2 files changed, 7 insertions, 1 deletions
diff --git a/arch/x86_64/kernel/process.c b/arch/x86_64/kernel/process.c
index 1c44b53cb15b..fb903e65e079 100644
--- a/arch/x86_64/kernel/process.c
+++ b/arch/x86_64/kernel/process.c
@@ -575,8 +575,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
575 prev->userrsp = read_pda(oldrsp); 575 prev->userrsp = read_pda(oldrsp);
576 write_pda(oldrsp, next->userrsp); 576 write_pda(oldrsp, next->userrsp);
577 write_pda(pcurrent, next_p); 577 write_pda(pcurrent, next_p);
578
578 /* This must be here to ensure both math_state_restore() and 579 /* This must be here to ensure both math_state_restore() and
579 kernel_fpu_begin() work consistently. */ 580 kernel_fpu_begin() work consistently.
581 And the AMD workaround requires it to be after DS reload. */
580 unlazy_fpu(prev_p); 582 unlazy_fpu(prev_p);
581 write_pda(kernelstack, 583 write_pda(kernelstack,
582 task_stack_page(next_p) + THREAD_SIZE - PDA_STACKOFFSET); 584 task_stack_page(next_p) + THREAD_SIZE - PDA_STACKOFFSET);
diff --git a/arch/x86_64/kernel/setup.c b/arch/x86_64/kernel/setup.c
index c50b06765a80..759070c82751 100644
--- a/arch/x86_64/kernel/setup.c
+++ b/arch/x86_64/kernel/setup.c
@@ -930,6 +930,10 @@ static int __init init_amd(struct cpuinfo_x86 *c)
930 if (c->x86 == 15 && ((level >= 0x0f48 && level < 0x0f50) || level >= 0x0f58)) 930 if (c->x86 == 15 && ((level >= 0x0f48 && level < 0x0f50) || level >= 0x0f58))
931 set_bit(X86_FEATURE_REP_GOOD, &c->x86_capability); 931 set_bit(X86_FEATURE_REP_GOOD, &c->x86_capability);
932 932
933 /* Enable workaround for FXSAVE leak */
934 if (c->x86 >= 6)
935 set_bit(X86_FEATURE_FXSAVE_LEAK, &c->x86_capability);
936
933 r = get_model_name(c); 937 r = get_model_name(c);
934 if (!r) { 938 if (!r) {
935 switch (c->x86) { 939 switch (c->x86) {