]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/commitdiff
x86/ia32: Fix ia32_restore_sigcontext() AC leak
authorPeter Zijlstra <peterz@infradead.org>
Mon, 25 Feb 2019 11:56:35 +0000 (12:56 +0100)
committerKleber Sacilotto de Souza <kleber.souza@canonical.com>
Wed, 14 Aug 2019 09:18:49 +0000 (11:18 +0200)
BugLink: https://bugs.launchpad.net/bugs/1838700
[ Upstream commit 67a0514afdbb8b2fc70b771b8c77661a9cb9d3a9 ]

Objtool spotted that we call native_load_gs_index() with AC set.
Re-arrange the code to avoid that.

Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: Khalid Elmously <khalid.elmously@canonical.com>
arch/x86/ia32/ia32_signal.c

index 41c671854642ff7eb4a966193e16c6da139a7714..789284d19b5589b46bc247dd73689287e1dd2149 100644 (file)
@@ -62,9 +62,8 @@
 } while (0)
 
 #define RELOAD_SEG(seg)                {               \
-       unsigned int pre = GET_SEG(seg);        \
+       unsigned int pre = (seg) | 3;           \
        unsigned int cur = get_user_seg(seg);   \
-       pre |= 3;                               \
        if (pre != cur)                         \
                set_user_seg(seg, pre);         \
 }
@@ -73,6 +72,7 @@ static int ia32_restore_sigcontext(struct pt_regs *regs,
                                   struct sigcontext_32 __user *sc)
 {
        unsigned int tmpflags, err = 0;
+       u16 gs, fs, es, ds;
        void __user *buf;
        u32 tmp;
 
@@ -80,16 +80,10 @@ static int ia32_restore_sigcontext(struct pt_regs *regs,
        current->restart_block.fn = do_no_restart_syscall;
 
        get_user_try {
-               /*
-                * Reload fs and gs if they have changed in the signal
-                * handler.  This does not handle long fs/gs base changes in
-                * the handler, but does not clobber them at least in the
-                * normal case.
-                */
-               RELOAD_SEG(gs);
-               RELOAD_SEG(fs);
-               RELOAD_SEG(ds);
-               RELOAD_SEG(es);
+               gs = GET_SEG(gs);
+               fs = GET_SEG(fs);
+               ds = GET_SEG(ds);
+               es = GET_SEG(es);
 
                COPY(di); COPY(si); COPY(bp); COPY(sp); COPY(bx);
                COPY(dx); COPY(cx); COPY(ip); COPY(ax);
@@ -107,6 +101,17 @@ static int ia32_restore_sigcontext(struct pt_regs *regs,
                buf = compat_ptr(tmp);
        } get_user_catch(err);
 
+       /*
+        * Reload fs and gs if they have changed in the signal
+        * handler.  This does not handle long fs/gs base changes in
+        * the handler, but does not clobber them at least in the
+        * normal case.
+        */
+       RELOAD_SEG(gs);
+       RELOAD_SEG(fs);
+       RELOAD_SEG(ds);
+       RELOAD_SEG(es);
+
        err |= fpu__restore_sig(buf, 1);
 
        force_iret();