public inbox for glibc-cvs@sourceware.org
help / color / mirror / Atom feed
* [glibc] arm: Fix an incorrect check in ____longjmp_chk [BZ #27709]
@ 2021-04-12 13:28 Szabolcs Nagy
  0 siblings, 0 replies; only message in thread
From: Szabolcs Nagy @ 2021-04-12 13:28 UTC (permalink / raw)
  To: glibc-cvs

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=8d4d77f6c848538cfb9e5ad0a14825e7ae4a1657

commit 8d4d77f6c848538cfb9e5ad0a14825e7ae4a1657
Author: Szabolcs Nagy <szabolcs.nagy@arm.com>
Date:   Wed Apr 7 12:45:53 2021 +0100

    arm: Fix an incorrect check in ____longjmp_chk [BZ #27709]
    
    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).

Diff:
---
 sysdeps/unix/sysv/linux/arm/____longjmp_chk.S | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/sysdeps/unix/sysv/linux/arm/____longjmp_chk.S b/sysdeps/unix/sysv/linux/arm/____longjmp_chk.S
index 7f35b4da7e..a26315b7cf 100644
--- a/sysdeps/unix/sysv/linux/arm/____longjmp_chk.S
+++ b/sysdeps/unix/sysv/linux/arm/____longjmp_chk.S
@@ -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);		\


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-04-12 13:28 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-12 13:28 [glibc] arm: Fix an incorrect check in ____longjmp_chk [BZ #27709] Szabolcs Nagy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).