x86/fpu/xstate: Fix xcomp_bv in XSAVES header
Subsystems (2)
PATCH 1/1 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: b22cbe404a9cc3c7949e380fa1861e31934c8978, 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.
--- arch/x86/kernel/fpu/core.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
arch/x86/kernel/fpu/core.c +3 -1
@@ -9,6 +9,7 @@#include <asm/fpu/regset.h> #include <asm/fpu/signal.h> #include <asm/fpu/types.h> +#include <asm/fpu/xstate.h> #include <asm/traps.h> #include <linux/hardirq.h>
@@ -235,7 +236,8 @@ void fpstate_init(union fpregs_state *state)* it will #GP. Make sure it is replaced after the memset(). */ if (static_cpu_has (X86_FEATURE_XSAVES )) - state->xsave.header.xcomp_bv =XCOMP_BV_COMPACTED_FORMAT ; + state->xsave.header.xcomp_bv =XCOMP_BV_COMPACTED_FORMAT | + xfeatures_mask;if (static_cpu_has (X86_FEATURE_FXSR ))fpstate_init_fxstate (&state->fxsave);
Signature · 1 line
1.9.1
Quoted 37 lines · Yu-cheng Yu
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 setxcomp_bvto reflect the XSAVES format since at the time there is no valid data.However, after we do
copy_init_fpstate_to_fpregs()infpu__clear(), as in commit:b22cbe404a9cc3c7949e380fa1861e31934c8978, and when__fpu_restore_sig()doesfpu__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=190061Fix it by setting
xcomp_bvcorrectly.Signed-off-by Yu-cheng Yu <[email protected]>Reported-by Joakim Tjernlund <[email protected]>--- arch/x86/kernel/fpu/core.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)arch/x86/kernel/fpu/core.c +1
-0@@ -9,6 +9,7 @@#include <asm/fpu/regset.h> #include <asm/fpu/signal.h> #include <asm/fpu/types.h> +#include <asm/fpu/xstate.h> #include <asm/traps.h> #include <linux/hardirq.h>
arch/x86/kernel/fpu/core.c void fpstate_init(union fpregs_state *state) · line 240
Quoted 6 lines
arch/x86/kernel/fpu/core.c +2
-1@@ -235,7 +236,8 @@ void fpstate_init(union fpregs_state *state)* it will #GP. Make sure it is replaced after the memset(). */ if (static_cpu_has (X86_FEATURE_XSAVES )) - state->xsave.header.xcomp_bv =XCOMP_BV_COMPACTED_FORMAT ; + state->xsave.header.xcomp_bv =XCOMP_BV_COMPACTED_FORMAT | + xfeatures_mask;
Ok, I have applied this - but it would be cleaner to go one step further and add a fpstate_init_xstate() method that does this in xstate.c and hides the details from arch/x86/kernel/fpu/core.c.
Similar to how the FX-state initialization is done today:
arch/x86/kernel/fpu/core.c void fpstate_init(union fpregs_state *state) · line 243
Quoted 2 lines
arch/x86/kernel/fpu/core.c +0
-0if (static_cpu_has (X86_FEATURE_FXSR ))fpstate_init_fxstate (&state->fxsave);
Thanks,
Ingo
Quoted 1 line · Ingo Molnar
* Yu-cheng Yu <[email protected]> wrote:
This needs to go to stable too, 4.8 and 4.9
Jocke
Quoted 57 lines
Quoted 38 lines
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 setxcomp_bvto reflect the XSAVES format since at the time there is no valid data.However, after we do
copy_init_fpstate_to_fpregs()infpu__clear(), as in commit:b22cbe404a9cc3c7949e380fa1861e31934c8978, and when__fpu_restore_sig()doesfpu__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=190061Fix it by setting
xcomp_bvcorrectly.Signed-off-by Yu-cheng Yu <[email protected]>Reported-by Joakim Tjernlund <[email protected]>--- arch/x86/kernel/fpu/core.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)arch/x86/kernel/fpu/core.c +1
-0@@ -9,6 +9,7 @@#include <asm/fpu/regset.h> #include <asm/fpu/signal.h> #include <asm/fpu/types.h> +#include <asm/fpu/xstate.h> #include <asm/traps.h> #include <linux/hardirq.h> arch/x86/kernel/fpu/core.c void fpstate_init(union fpregs_state *state) · line 240
Quoted 6 lines
arch/x86/kernel/fpu/core.c +2
-1@@ -235,7 +236,8 @@ void fpstate_init(union fpregs_state *state)* it will #GP. Make sure it is replaced after the memset(). */ if (static_cpu_has (X86_FEATURE_XSAVES )) - state->xsave.header.xcomp_bv =XCOMP_BV_COMPACTED_FORMAT ; + state->xsave.header.xcomp_bv =XCOMP_BV_COMPACTED_FORMAT | + xfeatures_mask;Ok, I have applied this - but it would be cleaner to go one step further and add a
fpstate_init_xstate()method that does this inxstate.cand hides the details fromarch/x86/kernel/fpu/core.c.Similar to how the FX-state initialization is done today:
arch/x86/kernel/fpu/core.c void fpstate_init(union fpregs_state *state) · line 243
Quoted 2 lines
arch/x86/kernel/fpu/core.c +0
-0if (static_cpu_has (X86_FEATURE_FXSR ))fpstate_init_fxstate (&state->fxsave);Thanks,
Ingo
tip-bot for Yu-cheng Yu
merge botx86/fpu/xstate: Fix xcomp_bv in XSAVES header
Commit-ID: dffba9a31c7769be3231c420d4b364c92ba3f1ac Gitweb: http://git.kernel.org/tip/dffba9a31c7769be3231c420d4b364c92ba3f1ac Author: Yu-cheng Yu <[email protected]> AuthorDate: Mon, 23 Jan 2017 14:54:44 -0800 Committer: Ingo Molnar <[email protected]> CommitDate: Tue, 24 Jan 2017 09:04:48 +0100
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:
b22cbe404a9c 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:
4c833368f0bf 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.
--- arch/x86/kernel/fpu/core.c | 4 +++- arch/x86/kernel/fpu/xstate.c | 1 - 2 files changed, 3 insertions(+), 2 deletions(-)
arch/x86/kernel/fpu/core.c +3 -1
@@ -9,6 +9,7 @@#include <asm/fpu/regset.h> #include <asm/fpu/signal.h> #include <asm/fpu/types.h> +#include <asm/fpu/xstate.h> #include <asm/traps.h> #include <linux/hardirq.h>
@@ -183,7 +184,8 @@ void fpstate_init(union fpregs_state *state)* it will #GP. Make sure it is replaced after the memset(). */ if (static_cpu_has (X86_FEATURE_XSAVES )) - state->xsave.header.xcomp_bv =XCOMP_BV_COMPACTED_FORMAT ; + state->xsave.header.xcomp_bv =XCOMP_BV_COMPACTED_FORMAT | + xfeatures_mask;if (static_cpu_has (X86_FEATURE_FXSR ))fpstate_init_fxstate (&state->fxsave);
arch/x86/kernel/fpu/xstate.c +0 -1
@@ -1070,7 +1070,6 @@ int copyin_to_xsaves(const void *kbuf, const void __user *ubuf,* Add back in the features that came in from userspace: */ xsave->header.xfeatures |= xfeatures; - xsave->header.xcomp_bv =XCOMP_BV_COMPACTED_FORMAT | xsave->header.xfeatures;return 0 ; }
Quoted 21 lines · tip-bot for Yu-cheng Yu
Commit-ID: dffba9a31c7769be3231c420d4b364c92ba3f1ac Gitweb: http://git.kernel.org/tip/dffba9a31c7769be3231c420d4b364c92ba3f1ac Author: Yu-cheng Yu <[email protected]> AuthorDate: Mon, 23 Jan 2017 14:54:44 -0800 Committer: Ingo Molnar <[email protected]> CommitDate: Tue, 24 Jan 2017 09:04:48 +0100x86/fpu/xstate: Fix
xcomp_bvin XSAVES headerThe 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 setxcomp_bvto reflect the XSAVES format since at the time there is no valid data.However, after we do
copy_init_fpstate_to_fpregs()infpu__clear(), as in commit:
b22cbe404a9cx86/fpu: Fix invalid FPU ptrace state afterexecve()
Quoted 9 lines
and when
__fpu_restore_sig()doesfpu__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=190061Fix it by setting
xcomp_bvcorrectly.
Please consider pulling this into the stable tree because my previous patch in commit:
b22cbe404a9c x86/fpu: Fix invalid FPU ptrace state after execve()
exposes the same issue in the stable tree.
Thanks,
Yu-cheng
Greg Kroah-Hartman
maintainerQuoted 32 lines · Yu-cheng Yu
Quoted 21 lines · tip-bot for Yu-cheng Yu
Commit-ID: dffba9a31c7769be3231c420d4b364c92ba3f1ac Gitweb: http://git.kernel.org/tip/dffba9a31c7769be3231c420d4b364c92ba3f1ac Author: Yu-cheng Yu <[email protected]> AuthorDate: Mon, 23 Jan 2017 14:54:44 -0800 Committer: Ingo Molnar <[email protected]> CommitDate: Tue, 24 Jan 2017 09:04:48 +0100x86/fpu/xstate: Fix
xcomp_bvin XSAVES headerThe 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 setxcomp_bvto reflect the XSAVES format since at the time there is no valid data.However, after we do
copy_init_fpstate_to_fpregs()infpu__clear(), as in commit:
b22cbe404a9cx86/fpu: Fix invalid FPU ptrace state afterexecve()Quoted 9 lines
and when
__fpu_restore_sig()doesfpu__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=190061Fix it by setting
xcomp_bvcorrectly.
Quoted 6 lines
Please consider pulling this into the stable tree because my previous patch in commit:
b22cbe404a9cx86/fpu: Fix invalid FPU ptrace state afterexecve()exposes the same issue in the stable tree.
Ah, thanks, I'll do that for the next round of stable releases after the ones that happen tomorrow.
greg k-h
Greg Kroah-Hartman
maintainerQuoted 32 lines · Yu-cheng Yu
Quoted 21 lines · tip-bot for Yu-cheng Yu
Commit-ID: dffba9a31c7769be3231c420d4b364c92ba3f1ac Gitweb: http://git.kernel.org/tip/dffba9a31c7769be3231c420d4b364c92ba3f1ac Author: Yu-cheng Yu <[email protected]> AuthorDate: Mon, 23 Jan 2017 14:54:44 -0800 Committer: Ingo Molnar <[email protected]> CommitDate: Tue, 24 Jan 2017 09:04:48 +0100x86/fpu/xstate: Fix
xcomp_bvin XSAVES headerThe 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 setxcomp_bvto reflect the XSAVES format since at the time there is no valid data.However, after we do
copy_init_fpstate_to_fpregs()infpu__clear(), as in commit:
b22cbe404a9cx86/fpu: Fix invalid FPU ptrace state afterexecve()Quoted 9 lines
and when
__fpu_restore_sig()doesfpu__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=190061Fix it by setting
xcomp_bvcorrectly.
Quoted 6 lines
Please consider pulling this into the stable tree because my previous patch in commit:
b22cbe404a9cx86/fpu: Fix invalid FPU ptrace state afterexecve()exposes the same issue in the stable tree.
I just tried to apply this, and it does not apply at all. Can you please provide a backported version that you have verified will work, so that I can apply it?
thanks,
greg k-h
Quoted 9 lines · Greg Kroah-Hartman
Quoted 8 lines · Yu-cheng Yu
Quoted 7 lines · tip-bot for Yu-cheng Yu
Commit-ID: dffba9a31c7769be3231c420d4b364c92ba3f1ac Gitweb: http://git.kernel.org/tip/dffba9a31c7769be3231c420d4b364c92ba3f1ac Author: Yu-cheng Yu <[email protected]> AuthorDate: Mon, 23 Jan 2017 14:54:44 -0800 Committer: Ingo Molnar <[email protected]> CommitDate: Tue, 24 Jan 2017 09:04:48 +0100
Quoted 5 lines
Quoted 1 line
Quoted 1 line
x86/fpu/xstate: Fix
xcomp_bvin XSAVES headerI just tried to apply this, and it does not apply at all. Can you please provide a backported version that you have verified will work, so that I can apply it?
I will do that.
Thanks,
Yu-cheng