Skip to content

Commit 30a304a

Browse files
KAGA-KOKOsuryasaimadhu
authored andcommitted
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: Thomas Gleixner <[email protected]> Signed-off-by: Borislav Petkov <[email protected]> Reviewed-by: Borislav Petkov <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent e84ba47 commit 30a304a

File tree

4 files changed

+14
-3
lines changed

4 files changed

+14
-3
lines changed

arch/x86/include/asm/fpu/internal.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ static inline void fxsave(struct fxregs_state *fx)
259259
*/
260260
static inline void os_xrstor_booting(struct xregs_state *xstate)
261261
{
262-
u64 mask = -1;
262+
u64 mask = xfeatures_mask_fpstate();
263263
u32 lmask = mask;
264264
u32 hmask = mask >> 32;
265265
int err;
@@ -388,7 +388,7 @@ extern void __restore_fpregs_from_fpstate(union fpregs_state *fpstate, u64 mask)
388388

389389
static inline void restore_fpregs_from_fpstate(union fpregs_state *fpstate)
390390
{
391-
__restore_fpregs_from_fpstate(fpstate, -1);
391+
__restore_fpregs_from_fpstate(fpstate, xfeatures_mask_fpstate());
392392
}
393393

394394
extern int copy_fpstate_to_sigframe(void __user *buf, void __user *fp, int size);

arch/x86/include/asm/fpu/xstate.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,16 @@ static inline u64 xfeatures_mask_restore_user(void)
111111
return xfeatures_mask_all & XFEATURE_MASK_USER_RESTORE;
112112
}
113113

114+
/*
115+
* Like xfeatures_mask_restore_user() but additionally restors the
116+
* supported supervisor states.
117+
*/
118+
static inline u64 xfeatures_mask_fpstate(void)
119+
{
120+
return xfeatures_mask_all & \
121+
(XFEATURE_MASK_USER_RESTORE | XFEATURE_MASK_SUPERVISOR_SUPPORTED);
122+
}
123+
114124
static inline u64 xfeatures_mask_independent(void)
115125
{
116126
if (!boot_cpu_has(X86_FEATURE_ARCH_LBR))

arch/x86/kernel/fpu/xstate.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ static short xsave_cpuid_features[] __initdata = {
6060
* XSAVE buffer, both supervisor and user xstates.
6161
*/
6262
u64 xfeatures_mask_all __ro_after_init;
63+
EXPORT_SYMBOL_GPL(xfeatures_mask_all);
6364

6465
static unsigned int xstate_offsets[XFEATURE_MAX] __ro_after_init =
6566
{ [ 0 ... XFEATURE_MAX - 1] = -1};

arch/x86/mm/extable.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ __visible bool ex_handler_fprestore(const struct exception_table_entry *fixup,
6565
WARN_ONCE(1, "Bad FPU state detected at %pB, reinitializing FPU registers.",
6666
(void *)instruction_pointer(regs));
6767

68-
__restore_fpregs_from_fpstate(&init_fpstate, -1);
68+
__restore_fpregs_from_fpstate(&init_fpstate, xfeatures_mask_fpstate());
6969
return true;
7070
}
7171
EXPORT_SYMBOL_GPL(ex_handler_fprestore);

0 commit comments

Comments
 (0)