Skip to content

Commit dffba9a

Browse files
yyu-intel-comIngo Molnar
authored andcommitted
x86/fpu/xstate: Fix xcomp_bv in XSAVES header
The compacted-format XSAVES area is determined at boot time and never changed after. The field xsave.header.xcomp_bv indicates which components are in the fixed XSAVES format. In fpstate_init() we did not set xcomp_bv to reflect the XSAVES format since at the time there is no valid data. However, after we do copy_init_fpstate_to_fpregs() in fpu__clear(), as in commit: b22cbe4 x86/fpu: Fix invalid FPU ptrace state after execve() and when __fpu_restore_sig() does fpu__restore() for a COMPAT-mode app, a #GP occurs. This can be easily triggered by doing valgrind on a COMPAT-mode "Hello World," as reported by Joakim Tjernlund and others: https://bugzilla.kernel.org/show_bug.cgi?id=190061 Fix it by setting xcomp_bv correctly. This patch also moves the xcomp_bv initialization to the proper place, which was in copyin_to_xsaves() as of: 4c83336 x86/fpu: Set the xcomp_bv when we fake up a XSAVES area which fixed the bug too, but it's more efficient and cleaner to initialize things once per boot, not for every signal handling operation. Reported-by: Kevin Hao <[email protected]> Reported-by: Joakim Tjernlund <[email protected]> Signed-off-by: Yu-cheng Yu <[email protected]> Cc: Andy Lutomirski <[email protected]> Cc: Borislav Petkov <[email protected]> Cc: Dave Hansen <[email protected]> Cc: Fenghua Yu <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Ravi V. Shankar <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: [email protected] Link: http://lkml.kernel.org/r/[email protected] [ Combined it with 4c83336. ] Signed-off-by: Ingo Molnar <[email protected]>
1 parent 4c83336 commit dffba9a

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

arch/x86/kernel/fpu/core.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <asm/fpu/regset.h>
1010
#include <asm/fpu/signal.h>
1111
#include <asm/fpu/types.h>
12+
#include <asm/fpu/xstate.h>
1213
#include <asm/traps.h>
1314

1415
#include <linux/hardirq.h>
@@ -183,7 +184,8 @@ void fpstate_init(union fpregs_state *state)
183184
* it will #GP. Make sure it is replaced after the memset().
184185
*/
185186
if (static_cpu_has(X86_FEATURE_XSAVES))
186-
state->xsave.header.xcomp_bv = XCOMP_BV_COMPACTED_FORMAT;
187+
state->xsave.header.xcomp_bv = XCOMP_BV_COMPACTED_FORMAT |
188+
xfeatures_mask;
187189

188190
if (static_cpu_has(X86_FEATURE_FXSR))
189191
fpstate_init_fxstate(&state->fxsave);

arch/x86/kernel/fpu/xstate.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1070,7 +1070,6 @@ int copyin_to_xsaves(const void *kbuf, const void __user *ubuf,
10701070
* Add back in the features that came in from userspace:
10711071
*/
10721072
xsave->header.xfeatures |= xfeatures;
1073-
xsave->header.xcomp_bv = XCOMP_BV_COMPACTED_FORMAT | xsave->header.xfeatures;
10741073

10751074
return 0;
10761075
}

0 commit comments

Comments
 (0)