]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blame - releases/4.9.11/x86-fpu-xstate-fix-xcomp_bv-in-xsaves-header.patch
4.14-stable patches
[thirdparty/kernel/stable-queue.git] / releases / 4.9.11 / x86-fpu-xstate-fix-xcomp_bv-in-xsaves-header.patch
CommitLineData
459fa4a7
GKH
1From dffba9a31c7769be3231c420d4b364c92ba3f1ac Mon Sep 17 00:00:00 2001
2From: Yu-cheng Yu <yu-cheng.yu@intel.com>
3Date: Mon, 23 Jan 2017 14:54:44 -0800
4Subject: x86/fpu/xstate: Fix xcomp_bv in XSAVES header
5
6From: Yu-cheng Yu <yu-cheng.yu@intel.com>
7
8commit dffba9a31c7769be3231c420d4b364c92ba3f1ac upstream.
9
10The compacted-format XSAVES area is determined at boot time and
11never changed after. The field xsave.header.xcomp_bv indicates
12which components are in the fixed XSAVES format.
13
14In fpstate_init() we did not set xcomp_bv to reflect the XSAVES
15format since at the time there is no valid data.
16
17However, after we do copy_init_fpstate_to_fpregs() in fpu__clear(),
18as in commit:
19
20 b22cbe404a9c x86/fpu: Fix invalid FPU ptrace state after execve()
21
22and when __fpu_restore_sig() does fpu__restore() for a COMPAT-mode
23app, a #GP occurs. This can be easily triggered by doing valgrind on
24a COMPAT-mode "Hello World," as reported by Joakim Tjernlund and
25others:
26
27 https://bugzilla.kernel.org/show_bug.cgi?id=190061
28
29Fix it by setting xcomp_bv correctly.
30
31This patch also moves the xcomp_bv initialization to the proper
32place, which was in copyin_to_xsaves() as of:
33
34 4c833368f0bf x86/fpu: Set the xcomp_bv when we fake up a XSAVES area
35
36which fixed the bug too, but it's more efficient and cleaner to
37initialize things once per boot, not for every signal handling
38operation.
39
40Reported-by: Kevin Hao <haokexin@gmail.com>
41Reported-by: Joakim Tjernlund <Joakim.Tjernlund@infinera.com>
42Signed-off-by: Yu-cheng Yu <yu-cheng.yu@intel.com>
43Cc: Andy Lutomirski <luto@kernel.org>
44Cc: Borislav Petkov <bp@suse.de>
45Cc: Dave Hansen <dave.hansen@linux.intel.com>
46Cc: Fenghua Yu <fenghua.yu@intel.com>
47Cc: Linus Torvalds <torvalds@linux-foundation.org>
48Cc: Peter Zijlstra <peterz@infradead.org>
49Cc: Ravi V. Shankar <ravi.v.shankar@intel.com>
50Cc: Thomas Gleixner <tglx@linutronix.de>
51Cc: haokexin@gmail.com
52Link: http://lkml.kernel.org/r/1485212084-4418-1-git-send-email-yu-cheng.yu@intel.com
53[ Combined it with 4c833368f0bf. ]
54Signed-off-by: Ingo Molnar <mingo@kernel.org>
55Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
56
57---
58 arch/x86/kernel/fpu/core.c | 3 ++-
59 1 file changed, 2 insertions(+), 1 deletion(-)
60
61--- a/arch/x86/kernel/fpu/core.c
62+++ b/arch/x86/kernel/fpu/core.c
63@@ -236,7 +236,8 @@ void fpstate_init(union fpregs_state *st
64 * it will #GP. Make sure it is replaced after the memset().
65 */
66 if (static_cpu_has(X86_FEATURE_XSAVES))
67- state->xsave.header.xcomp_bv = XCOMP_BV_COMPACTED_FORMAT;
68+ state->xsave.header.xcomp_bv = XCOMP_BV_COMPACTED_FORMAT |
69+ xfeatures_mask;
70
71 if (static_cpu_has(X86_FEATURE_FXSR))
72 fpstate_init_fxstate(&state->fxsave);