]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
arm: Fix an incorrect check in ____longjmp_chk [BZ #27709]
authorSzabolcs Nagy <szabolcs.nagy@arm.com>
Wed, 7 Apr 2021 11:45:53 +0000 (12:45 +0100)
committerSzabolcs Nagy <szabolcs.nagy@arm.com>
Mon, 12 Apr 2021 13:28:07 +0000 (14:28 +0100)
An incorrect check in __longjmp_chk could fail on valid code causing

FAIL: debug/tst-longjmp_chk2

The original check was

  altstack_sp + altstack_size - setjmp_sp > altstack_size

i.e. sp at setjmp was outside of the altstack range. Here we know that
longjmp is called from a signal handler on the altstack (SS_ONSTACK),
and that it jumps in the wrong direction (sp decreases), so the check
wants to ensure the jump goes to another stack.

The check is wrong when altstack_sp == setjmp_sp which can happen
when the altstack is a local buffer in the function that calls setjmp,
so the patch allows == too. This fixes bug 27709.

Note that the generic __longjmp_chk check seems to be different.
(it checks if longjmp was on the altstack but does not check setjmp,
so it would not catch incorrect longjmp use within the signal handler).

sysdeps/unix/sysv/linux/arm/____longjmp_chk.S

index 7f35b4da7eeb07d8fe47fd8bffa90d74b3f78d08..a26315b7cf96d399837e357e72c34030ed8269a5 100644 (file)
@@ -72,8 +72,8 @@ longjmp_msg:
        ldr     r3, [sp, #8];                   \
        add     r2, r2, r3;                     \
        sub     r2, r2, reg;                    \
-       cmp     r2, r3;                         \
-       bhi     .Lok2;                          \
+       cmp     r3, r2;                         \
+       bls     .Lok2;                          \
 .Lfail:                                                \
        add     sp, sp, #12;                    \
        cfi_adjust_cfa_offset (-12);            \