Skip to content

Commit cdcec1b

Browse files
KAGA-KOKOsuryasaimadhu
authored andcommitted
x86/fpu/signal: Sanitize copy_user_to_fpregs_zeroing()
Now that user_xfeatures is correctly set when xsave is enabled, remove the duplicated initialization of components. Rename the function while at it. 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 1258a8c commit cdcec1b

File tree

1 file changed

+15
-21
lines changed

1 file changed

+15
-21
lines changed

arch/x86/kernel/fpu/signal.c

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -251,33 +251,27 @@ sanitize_restored_user_xstate(union fpregs_state *state,
251251
}
252252

253253
/*
254-
* Restore the extended state if present. Otherwise, restore the FP/SSE state.
254+
* Restore the FPU state directly from the userspace signal frame.
255255
*/
256-
static int copy_user_to_fpregs_zeroing(void __user *buf, u64 xbv, int fx_only)
256+
static int restore_fpregs_from_user(void __user *buf, u64 xrestore, bool fx_only)
257257
{
258-
u64 init_bv;
259-
int r;
260-
261258
if (use_xsave()) {
262-
if (fx_only) {
263-
init_bv = xfeatures_mask_uabi() & ~XFEATURE_MASK_FPSSE;
259+
u64 init_bv = xfeatures_mask_uabi() & ~xrestore;
260+
int ret;
264261

265-
r = fxrstor_from_user_sigframe(buf);
266-
if (!r)
267-
os_xrstor(&init_fpstate.xsave, init_bv);
268-
return r;
269-
} else {
270-
init_bv = xfeatures_mask_uabi() & ~xbv;
271-
272-
r = xrstor_from_user_sigframe(buf, xbv);
273-
if (!r && unlikely(init_bv))
274-
os_xrstor(&init_fpstate.xsave, init_bv);
275-
return r;
276-
}
262+
if (likely(!fx_only))
263+
ret = xrstor_from_user_sigframe(buf, xrestore);
264+
else
265+
ret = fxrstor_from_user_sigframe(buf);
266+
267+
if (!ret && unlikely(init_bv))
268+
os_xrstor(&init_fpstate.xsave, init_bv);
269+
return ret;
277270
} else if (use_fxsr()) {
278271
return fxrstor_from_user_sigframe(buf);
279-
} else
272+
} else {
280273
return frstor_from_user_sigframe(buf);
274+
}
281275
}
282276

283277
static int __fpu_restore_sig(void __user *buf, void __user *buf_fx,
@@ -314,7 +308,7 @@ static int __fpu_restore_sig(void __user *buf, void __user *buf_fx,
314308
*/
315309
fpregs_lock();
316310
pagefault_disable();
317-
ret = copy_user_to_fpregs_zeroing(buf_fx, user_xfeatures, fx_only);
311+
ret = restore_fpregs_from_user(buf_fx, user_xfeatures, fx_only);
318312
pagefault_enable();
319313
if (!ret) {
320314

0 commit comments

Comments
 (0)