]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
mips64: fix clobbering s0 in setjmp() [BZ #22624]
authorSergei Trofimovich <slyfox@gentoo.org>
Mon, 18 Dec 2017 17:23:02 +0000 (17:23 +0000)
committerJoseph Myers <joseph@codesourcery.com>
Mon, 18 Dec 2017 17:23:02 +0000 (17:23 +0000)
When configured as --enable-stack-protector=all glibc
inserts stack checking canary into every function
including __sigsetjmp_aux(). Stack checking code
ends up using s0 register to temporary hold address
of global canary value.

Unfortunately __sigsetjmp_aux assumes no caller' caller-save
registers should be clobbered as it stores them as-is.

The fix is to disable stack protection of __sigsetjmp_aux.

Tested on the following test:

    #include <setjmp.h>
    #include <stdio.h>

    int main() {
        jmp_buf jb;
        volatile register long s0 asm ("$s0");
        s0 = 1234;
        if (setjmp(jb) == 0)
            longjmp(jb, 1);
        printf ("$s0 = %lu\n", s0);
    }

Without the fix:
    $ qemu-mipsn32 -L . ./mips-longjmp-bug
    $s0 = 1082346228

With the fix:
    $ qemu-mipsn32 -L . ./mips-longjmp-bug
    $s0 = 1234

[BZ #22624]
* sysdeps/mips/mips64/setjmp_aux.c (__sigsetjmp_aux): Use
inhibit_stack_protector.

ChangeLog
sysdeps/mips/mips64/setjmp_aux.c

index d290d60a84e7e10d2dbf5951185934c1bb9e7ada..4a7164354f2562cc66529e3c1e8ea02c1f47ff6a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2017-12-18  Sergei Trofimovich  <slyfox@gentoo.org>
+
+       [BZ #22624]
+       * sysdeps/mips/mips64/setjmp_aux.c (__sigsetjmp_aux): Use
+       inhibit_stack_protector.
+
 2017-12-18  Dmitry V. Levin  <ldv@altlinux.org>
 
        [BZ #22627]
index b43c36a7d50d82da6d1e47c31a052e03e94f6aff..43fffc74bf14c667444842ef03c9845d786a5c7f 100644 (file)
    pointer.  We do things this way because it's difficult to reliably
    access them in C.  */
 
+/* Stack protection is disabled to avoid changing s0 (or any other
+   caller-save register) before storing it to environment.
+   See BZ #22624.  */
+
 int
+inhibit_stack_protector
 __sigsetjmp_aux (jmp_buf env, int savemask, long long sp, long long fp,
                 long long gp)
 {