提交 156d480d 编写于 作者: A Andy Lutomirski 提交者: Lin Wang

x86/fpu: Clean up fpregs_set()

mainline inclusion
from mainline-v5.14-rc1
commit da53f60b
category: feature
bugzilla: https://gitee.com/openeuler/intel-kernel/issues/I590ZC
CVE: NA

Intel-SIG: commit da53f60b x86/fpu: Clean up fpregs_set().

--------------------------------

fpregs_set() has unnecessary complexity to support short or nonzero-offset
writes and to handle the case in which a copy from userspace overwrites
some of the target buffer and then fails.  Support for partial writes is
useless -- just require that the write has offset 0 and the correct size,
and copy into a temporary kernel buffer to avoid clobbering the state if
the user access fails.
Signed-off-by: NAndy Lutomirski <luto@kernel.org>
Signed-off-by: NThomas Gleixner <tglx@linutronix.de>
Signed-off-by: NBorislav Petkov <bp@suse.de>
Reviewed-by: NBorislav Petkov <bp@suse.de>
Link: https://lkml.kernel.org/r/20210623121452.710467587@linutronix.deSigned-off-by: NLin Wang <lin.x.wang@intel.com>
上级 41d4cce0
...@@ -304,31 +304,32 @@ int fpregs_set(struct task_struct *target, const struct user_regset *regset, ...@@ -304,31 +304,32 @@ int fpregs_set(struct task_struct *target, const struct user_regset *regset,
struct user_i387_ia32_struct env; struct user_i387_ia32_struct env;
int ret; int ret;
fpu__prepare_write(fpu); /* No funny business with partial or oversized writes is permitted. */
fpstate_sanitize_xstate(fpu); if (pos != 0 || count != sizeof(struct user_i387_ia32_struct))
return -EINVAL;
if (!boot_cpu_has(X86_FEATURE_FPU)) if (!cpu_feature_enabled(X86_FEATURE_FPU))
return fpregs_soft_set(target, regset, pos, count, kbuf, ubuf); return fpregs_soft_set(target, regset, pos, count, kbuf, ubuf);
if (!boot_cpu_has(X86_FEATURE_FXSR)) ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &env, 0, -1);
return user_regset_copyin(&pos, &count, &kbuf, &ubuf, if (ret)
&fpu->state.fsave, 0, return ret;
-1);
if (pos > 0 || count < sizeof(env)) fpu__prepare_write(fpu);
convert_from_fxsr(&env, target);
ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &env, 0, -1); if (cpu_feature_enabled(X86_FEATURE_FXSR))
if (!ret) convert_to_fxsr(&fpu->state.fxsave, &env);
convert_to_fxsr(&target->thread.fpu.state.fxsave, &env); else
memcpy(&fpu->state.fsave, &env, sizeof(env));
/* /*
* update the header bit in the xsave header, indicating the * Update the header bit in the xsave header, indicating the
* presence of FP. * presence of FP.
*/ */
if (boot_cpu_has(X86_FEATURE_XSAVE)) if (cpu_feature_enabled(X86_FEATURE_XSAVE))
fpu->state.xsave.header.xfeatures |= XFEATURE_MASK_FP; fpu->state.xsave.header.xfeatures |= XFEATURE_MASK_FP;
return ret;
return 0;
} }
#endif /* CONFIG_X86_32 || CONFIG_IA32_EMULATION */ #endif /* CONFIG_X86_32 || CONFIG_IA32_EMULATION */
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册