Commit be31dfdf authored by Thomas Gleixner's avatar Thomas Gleixner Committed by Borislav Petkov

x86/fpu: Use fpstate::size

Make use of fpstate::size in various places which require the buffer size
information for sanity checks or memcpy() sizing.
Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
Signed-off-by: default avatarBorislav Petkov <bp@suse.de>
Link: https://lkml.kernel.org/r/20211013145322.973518954@linutronix.de
parent 248452ce
...@@ -166,13 +166,12 @@ void fpu_swap_kvm_fpu(struct fpu *save, struct fpu *rstor, u64 restore_mask) ...@@ -166,13 +166,12 @@ void fpu_swap_kvm_fpu(struct fpu *save, struct fpu *rstor, u64 restore_mask)
fpregs_lock(); fpregs_lock();
if (save) { if (save) {
if (test_thread_flag(TIF_NEED_FPU_LOAD)) { struct fpstate *fpcur = current->thread.fpu.fpstate;
memcpy(&save->fpstate->regs,
&current->thread.fpu.fpstate->regs, if (test_thread_flag(TIF_NEED_FPU_LOAD))
fpu_kernel_xstate_size); memcpy(&save->fpstate->regs, &fpcur->regs, fpcur->size);
} else { else
save_fpregs_to_fpstate(save); save_fpregs_to_fpstate(save);
}
} }
if (rstor) { if (rstor) {
...@@ -398,7 +397,7 @@ int fpu_clone(struct task_struct *dst) ...@@ -398,7 +397,7 @@ int fpu_clone(struct task_struct *dst)
fpregs_lock(); fpregs_lock();
if (test_thread_flag(TIF_NEED_FPU_LOAD)) { if (test_thread_flag(TIF_NEED_FPU_LOAD)) {
memcpy(&dst_fpu->fpstate->regs, &src_fpu->fpstate->regs, memcpy(&dst_fpu->fpstate->regs, &src_fpu->fpstate->regs,
fpu_kernel_xstate_size); dst_fpu->fpstate->size);
} else { } else {
save_fpregs_to_fpstate(dst_fpu); save_fpregs_to_fpstate(dst_fpu);
} }
......
...@@ -313,15 +313,13 @@ static bool restore_fpregs_from_user(void __user *buf, u64 xrestore, ...@@ -313,15 +313,13 @@ static bool restore_fpregs_from_user(void __user *buf, u64 xrestore,
static bool __fpu_restore_sig(void __user *buf, void __user *buf_fx, static bool __fpu_restore_sig(void __user *buf, void __user *buf_fx,
bool ia32_fxstate) bool ia32_fxstate)
{ {
int state_size = fpu_kernel_xstate_size;
struct task_struct *tsk = current; struct task_struct *tsk = current;
struct fpu *fpu = &tsk->thread.fpu; struct fpu *fpu = &tsk->thread.fpu;
struct user_i387_ia32_struct env; struct user_i387_ia32_struct env;
bool success, fx_only = false;
union fpregs_state *fpregs; union fpregs_state *fpregs;
unsigned int state_size;
u64 user_xfeatures = 0; u64 user_xfeatures = 0;
bool fx_only = false;
bool success;
if (use_xsave()) { if (use_xsave()) {
struct _fpx_sw_bytes fx_sw_user; struct _fpx_sw_bytes fx_sw_user;
...@@ -334,6 +332,7 @@ static bool __fpu_restore_sig(void __user *buf, void __user *buf_fx, ...@@ -334,6 +332,7 @@ static bool __fpu_restore_sig(void __user *buf, void __user *buf_fx,
user_xfeatures = fx_sw_user.xfeatures; user_xfeatures = fx_sw_user.xfeatures;
} else { } else {
user_xfeatures = XFEATURE_MASK_FPSSE; user_xfeatures = XFEATURE_MASK_FPSSE;
state_size = fpu->fpstate->size;
} }
if (likely(!ia32_fxstate)) { if (likely(!ia32_fxstate)) {
......
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