x86/fpu: Fail ptrace() requests that try to set invalid MXCSR values
authorAndy Lutomirski <luto@kernel.org>
Wed, 23 Jun 2021 12:01:40 +0000 (14:01 +0200)
committerBorislav Petkov <bp@suse.de>
Wed, 23 Jun 2021 15:49:46 +0000 (17:49 +0200)
There is no benefit from accepting and silently changing an invalid MXCSR
value supplied via ptrace().  Instead, return -EINVAL on invalid input.

Signed-off-by: Andy Lutomirski <luto@kernel.org>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Borislav Petkov <bp@suse.de>
Link: https://lkml.kernel.org/r/20210623121452.613614842@linutronix.de
arch/x86/kernel/fpu/regset.c

index f24ce87..5610f77 100644 (file)
@@ -63,8 +63,9 @@ int xfpregs_set(struct task_struct *target, const struct user_regset *regset,
        if (ret)
                return ret;
 
-       /* Mask invalid MXCSR bits (for historical reasons). */
-       newstate.mxcsr &= mxcsr_feature_mask;
+       /* Do not allow an invalid MXCSR value. */
+       if (newstate.mxcsr & ~mxcsr_feature_mask)
+               return -EINVAL;
 
        fpu__prepare_write(fpu);