Skip to content

Commit dc8aa31

Browse files
ChangSeokBaeIngo Molnar
authored andcommitted
x86/fpu: Refine and simplify the magic number check during signal return
Before restoring xstate from the user space buffer, the kernel performs sanity checks on these magic numbers: magic1 in the software reserved area, and magic2 at the end of XSAVE region. The position of magic2 is calculated based on the xstate size derived from the user space buffer. But, the in-kernel record is directly available and reliable for this purpose. This reliance on user space data is also inconsistent with the recent fix in: d877550 ("x86/fpu: Stop relying on userspace for info to fault in xsave buffer") Simply use fpstate->user_size, and then get rid of unnecessary size-evaluation code. Signed-off-by: Chang S. Bae <chang.seok.bae@intel.com> Signed-off-by: Ingo Molnar <mingo@kernel.org> Cc: Andy Lutomirski <luto@kernel.org> Cc: H. Peter Anvin <hpa@zytor.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Oleg Nesterov <oleg@redhat.com> Cc: Dave Hansen <dave.hansen@linux.intel.com> Link: https://lore.kernel.org/r/20241211014500.3738-1-chang.seok.bae@intel.com
1 parent bd64e9d commit dc8aa31

File tree

1 file changed

+3
-8
lines changed

1 file changed

+3
-8
lines changed

arch/x86/kernel/fpu/signal.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,14 @@
2727
static inline bool check_xstate_in_sigframe(struct fxregs_state __user *fxbuf,
2828
struct _fpx_sw_bytes *fx_sw)
2929
{
30-
int min_xstate_size = sizeof(struct fxregs_state) +
31-
sizeof(struct xstate_header);
3230
void __user *fpstate = fxbuf;
3331
unsigned int magic2;
3432

3533
if (__copy_from_user(fx_sw, &fxbuf->sw_reserved[0], sizeof(*fx_sw)))
3634
return false;
3735

38-
/* Check for the first magic field and other error scenarios. */
39-
if (fx_sw->magic1 != FP_XSTATE_MAGIC1 ||
40-
fx_sw->xstate_size < min_xstate_size ||
41-
fx_sw->xstate_size > current->thread.fpu.fpstate->user_size ||
42-
fx_sw->xstate_size > fx_sw->extended_size)
36+
/* Check for the first magic field */
37+
if (fx_sw->magic1 != FP_XSTATE_MAGIC1)
4338
goto setfx;
4439

4540
/*
@@ -48,7 +43,7 @@ static inline bool check_xstate_in_sigframe(struct fxregs_state __user *fxbuf,
4843
* fpstate layout with out copying the extended state information
4944
* in the memory layout.
5045
*/
51-
if (__get_user(magic2, (__u32 __user *)(fpstate + fx_sw->xstate_size)))
46+
if (__get_user(magic2, (__u32 __user *)(fpstate + current->thread.fpu.fpstate->user_size)))
5247
return false;
5348

5449
if (likely(magic2 == FP_XSTATE_MAGIC2))

0 commit comments

Comments
 (0)