Commit 30a304a1 authored by Thomas Gleixner's avatar Thomas Gleixner Committed by Borislav Petkov

x86/fpu: Mask PKRU from kernel XRSTOR[S] operations

As the PKRU state is managed separately restoring it from the xstate
buffer would be counterproductive as it might either restore a stale
value or reinit the PKRU state to 0.
Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
Signed-off-by: default avatarBorislav Petkov <bp@suse.de>
Reviewed-by: default avatarBorislav Petkov <bp@suse.de>
Link: https://lkml.kernel.org/r/20210623121456.606745195@linutronix.de
parent e84ba47e
...@@ -259,7 +259,7 @@ static inline void fxsave(struct fxregs_state *fx) ...@@ -259,7 +259,7 @@ static inline void fxsave(struct fxregs_state *fx)
*/ */
static inline void os_xrstor_booting(struct xregs_state *xstate) static inline void os_xrstor_booting(struct xregs_state *xstate)
{ {
u64 mask = -1; u64 mask = xfeatures_mask_fpstate();
u32 lmask = mask; u32 lmask = mask;
u32 hmask = mask >> 32; u32 hmask = mask >> 32;
int err; int err;
...@@ -388,7 +388,7 @@ extern void __restore_fpregs_from_fpstate(union fpregs_state *fpstate, u64 mask) ...@@ -388,7 +388,7 @@ extern void __restore_fpregs_from_fpstate(union fpregs_state *fpstate, u64 mask)
static inline void restore_fpregs_from_fpstate(union fpregs_state *fpstate) static inline void restore_fpregs_from_fpstate(union fpregs_state *fpstate)
{ {
__restore_fpregs_from_fpstate(fpstate, -1); __restore_fpregs_from_fpstate(fpstate, xfeatures_mask_fpstate());
} }
extern int copy_fpstate_to_sigframe(void __user *buf, void __user *fp, int size); extern int copy_fpstate_to_sigframe(void __user *buf, void __user *fp, int size);
......
...@@ -111,6 +111,16 @@ static inline u64 xfeatures_mask_restore_user(void) ...@@ -111,6 +111,16 @@ static inline u64 xfeatures_mask_restore_user(void)
return xfeatures_mask_all & XFEATURE_MASK_USER_RESTORE; return xfeatures_mask_all & XFEATURE_MASK_USER_RESTORE;
} }
/*
* Like xfeatures_mask_restore_user() but additionally restors the
* supported supervisor states.
*/
static inline u64 xfeatures_mask_fpstate(void)
{
return xfeatures_mask_all & \
(XFEATURE_MASK_USER_RESTORE | XFEATURE_MASK_SUPERVISOR_SUPPORTED);
}
static inline u64 xfeatures_mask_independent(void) static inline u64 xfeatures_mask_independent(void)
{ {
if (!boot_cpu_has(X86_FEATURE_ARCH_LBR)) if (!boot_cpu_has(X86_FEATURE_ARCH_LBR))
......
...@@ -60,6 +60,7 @@ static short xsave_cpuid_features[] __initdata = { ...@@ -60,6 +60,7 @@ static short xsave_cpuid_features[] __initdata = {
* XSAVE buffer, both supervisor and user xstates. * XSAVE buffer, both supervisor and user xstates.
*/ */
u64 xfeatures_mask_all __ro_after_init; u64 xfeatures_mask_all __ro_after_init;
EXPORT_SYMBOL_GPL(xfeatures_mask_all);
static unsigned int xstate_offsets[XFEATURE_MAX] __ro_after_init = static unsigned int xstate_offsets[XFEATURE_MAX] __ro_after_init =
{ [ 0 ... XFEATURE_MAX - 1] = -1}; { [ 0 ... XFEATURE_MAX - 1] = -1};
......
...@@ -65,7 +65,7 @@ __visible bool ex_handler_fprestore(const struct exception_table_entry *fixup, ...@@ -65,7 +65,7 @@ __visible bool ex_handler_fprestore(const struct exception_table_entry *fixup,
WARN_ONCE(1, "Bad FPU state detected at %pB, reinitializing FPU registers.", WARN_ONCE(1, "Bad FPU state detected at %pB, reinitializing FPU registers.",
(void *)instruction_pointer(regs)); (void *)instruction_pointer(regs));
__restore_fpregs_from_fpstate(&init_fpstate, -1); __restore_fpregs_from_fpstate(&init_fpstate, xfeatures_mask_fpstate());
return true; return true;
} }
EXPORT_SYMBOL_GPL(ex_handler_fprestore); EXPORT_SYMBOL_GPL(ex_handler_fprestore);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment