提交 61096e82 编写于 作者: T Thomas Gleixner 提交者: Lin Wang

x86/fpu: Reject invalid MXCSR values in copy_kernel_to_xstate()

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

Intel-SIG: commit 947f4947 x86/fpu: Reject invalid MXCSR values in copy_kernel_to_xstate().

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

Instead of masking out reserved bits, check them and reject the provided
state as invalid if not zero.
Suggested-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.308388343@linutronix.deSigned-off-by: NLin Wang <lin.x.wang@intel.com>
上级 7f26af0f
......@@ -1154,6 +1154,19 @@ void copy_xstate_to_kernel(struct membuf to, struct xregs_state *xsave)
membuf_zero(&to, to.left);
}
static inline bool mxcsr_valid(struct xstate_header *hdr, const u32 *mxcsr)
{
u64 mask = XFEATURE_MASK_FP | XFEATURE_MASK_SSE | XFEATURE_MASK_YMM;
/* Only check if it is in use */
if (hdr->xfeatures & mask) {
/* Reserved bits in MXCSR must be zero. */
if (*mxcsr & ~mxcsr_feature_mask)
return false;
}
return true;
}
/*
* Convert from a ptrace standard-format kernel buffer to kernel XSAVE[S] format
* and copy to the target thread. This is called from xstateregs_set().
......@@ -1172,6 +1185,9 @@ int copy_kernel_to_xstate(struct xregs_state *xsave, const void *kbuf)
if (validate_user_xstate_header(&hdr))
return -EINVAL;
if (!mxcsr_valid(&hdr, kbuf + offsetof(struct fxregs_state, mxcsr)))
return -EINVAL;
for (i = 0; i < XFEATURE_MAX; i++) {
u64 mask = ((u64)1 << i);
......@@ -1202,9 +1218,6 @@ int copy_kernel_to_xstate(struct xregs_state *xsave, const void *kbuf)
*/
xsave->header.xfeatures |= hdr.xfeatures;
/* mxcsr reserved bits must be masked to zero for historical reasons. */
xsave->i387.mxcsr &= mxcsr_feature_mask;
return 0;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册