]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commitdiff
x86/fpu/signal: Move header zeroing out of xsave_to_user_sigframe()
authorThomas Gleixner <tglx@linutronix.de>
Wed, 8 Sep 2021 13:29:29 +0000 (15:29 +0200)
committerStefan Bader <stefan.bader@canonical.com>
Wed, 27 Apr 2022 09:55:49 +0000 (11:55 +0200)
BugLink: https://bugs.launchpad.net/bugs/1967750
There is no reason to have the header zeroing in the pagefault disabled
region. Do it upfront once.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Borislav Petkov <bp@suse.de>
Link: https://lkml.kernel.org/r/20210908132525.621674721@linutronix.de
(cherry picked from commit 4164a482a5d92c29eaf53d01755103f6bbce38f2)
Acked-by: Dimitri John Ledkov <dimitri.ledkov@canonical.com>
Signed-off-by: Andrea Righi <andrea.righi@canonical.com>
arch/x86/include/asm/fpu/internal.h
arch/x86/kernel/fpu/signal.c

index 4cfd40dc3cb5ddfdab1520d7c7a040fa603877e7..c856ca481546724231fac8669afa949b16de3aa2 100644 (file)
@@ -318,9 +318,12 @@ static inline void os_xrstor(struct xregs_state *xstate, u64 mask)
  * We don't use modified optimization because xrstor/xrstors might track
  * a different application.
  *
- * We don't use compacted format xsave area for
- * backward compatibility for old applications which don't understand
- * compacted format of xsave area.
+ * We don't use compacted format xsave area for backward compatibility for
+ * old applications which don't understand the compacted format of the
+ * xsave area.
+ *
+ * The caller has to zero buf::header before calling this because XSAVE*
+ * does not touch the reserved fields in the header.
  */
 static inline int xsave_to_user_sigframe(struct xregs_state __user *buf)
 {
@@ -334,14 +337,6 @@ static inline int xsave_to_user_sigframe(struct xregs_state __user *buf)
        u32 hmask = mask >> 32;
        int err;
 
-       /*
-        * Clear the xsave header first, so that reserved fields are
-        * initialized to zero.
-        */
-       err = __clear_user(&buf->header, sizeof(buf->header));
-       if (unlikely(err))
-               return -EFAULT;
-
        stac();
        XSTATE_OP(XSAVE, buf, lmask, hmask, err);
        clac();
index cd96f5ce0ca7ada8f88ef58af748d7f240591537..91c1e68e5fca59528415c8761af1530298ec8fd5 100644 (file)
@@ -189,6 +189,18 @@ int copy_fpstate_to_sigframe(void __user *buf, void __user *buf_fx, int size)
 
        if (!access_ok(buf, size))
                return -EACCES;
+
+       if (use_xsave()) {
+               struct xregs_state __user *xbuf = buf_fx;
+
+               /*
+                * Clear the xsave header first, so that reserved fields are
+                * initialized to zero.
+                */
+               ret = __clear_user(&xbuf->header, sizeof(xbuf->header));
+               if (unlikely(ret))
+                       return ret;
+       }
 retry:
        /*
         * Load the FPU registers if they are not valid for the current task.