Skip to content

Commit 19cb359

Browse files
Lyle LiKexyBiscuit
authored andcommitted
FROMLIST: x86/fpu: Fix the os panic issue caused by the XGETBV instruction
The callers of the xfeatures_in_use function must ensure that the current processor has the X86_FEATURE_XGETBV1 feature. However, in some places where xfeatures_in_use is called, there is no check to see if the processor supports this feature, leading to the execution of the XGETBV XCR1 instruction on processors that do not support this feature, triggering a #GP exception, and ultimately causing an OS panic. To fix this issue, a check for the X86_FEATURE_XGETBV1 feature has been added before calling xfeatures_in_use. Fixes: ae6012d ("x86/pkeys: Ensure updated PKRU value is XRSTOR'd") Fixes: 30d0255 ("x86/fpu: Optimize out sigframe xfeatures when in init state") Signed-off-by: Lyle Li <[email protected]> Signed-off-by: Tony W Wang-oc <[email protected]> Link: https://lore.kernel.org/all/[email protected]/ Signed-off-by: Kexy Biscuit <[email protected]>
1 parent ff8b01e commit 19cb359

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

arch/x86/kernel/fpu/xstate.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ static inline int update_pkru_in_sigframe(struct xregs_state __user *buf, u32 pk
9393
if (unlikely(!cpu_feature_enabled(X86_FEATURE_OSPKE)))
9494
return 0;
9595

96+
if (!cpu_feature_enabled(X86_FEATURE_XGETBV1))
97+
return 0;
98+
9699
/* Mark PKRU as in-use so that it is restored correctly. */
97100
err = set_xfeature_in_sigframe(buf, XFEATURE_MASK_PKRU);
98101
if (err)
@@ -306,7 +309,7 @@ static inline int xsave_to_user_sigframe(struct xregs_state __user *buf, u32 pkr
306309
int err;
307310

308311
/* Optimize away writing unnecessary xfeatures: */
309-
if (fpu_state_size_dynamic())
312+
if (cpu_feature_enabled(X86_FEATURE_XGETBV1) && fpu_state_size_dynamic())
310313
mask &= xfeatures_need_sigframe_write();
311314

312315
lmask = mask;

0 commit comments

Comments
 (0)