This is the mail archive of the
glibc-cvs@sourceware.org
mailing list for the glibc project.
GNU C Library master sources branch, master, updated. glibc-2.10-238-g57dbdb9
- From: drepper at sourceware dot org
- To: glibc-cvs at sourceware dot org
- Date: 31 Jul 2009 04:52:12 -0000
- Subject: GNU C Library master sources branch, master, updated. glibc-2.10-238-g57dbdb9
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU C Library master sources".
The branch, master has been updated
via 57dbdb9f07fb20d5dd765c5dc91e31cb67d08b7e (commit)
via da97dfdcfa0ecbbf2d455c54a08bb9223ce1fc18 (commit)
via 98b1e6c8668259044a20a016a5a5957b226ce04b (commit)
via 8e80581787d2342824d9b70d238e646326776c31 (commit)
via 07df80996944b95a238be755eb4957a83a5e4762 (commit)
via 85d9d2f3a089f747177895b115ca2186f34b0122 (commit)
via a9a04420818e1ab0a49838e2eb83ebb66baaeaac (commit)
via 5ead9ce5c788e7dbb0bd01888c4bcb37a8bc2ff1 (commit)
via 2dec6007d183aa51abedbbb048382973129f3935 (commit)
from 78c4ef475d47a2289635f74b726f52defedb4651 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
http://sources.redhat.com/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=57dbdb9f07fb20d5dd765c5dc91e31cb67d08b7e
commit 57dbdb9f07fb20d5dd765c5dc91e31cb67d08b7e
Author: Ulrich Drepper <drepper@redhat.com>
Date: Thu Jul 30 21:51:56 2009 -0700
Whitespace cleanup.
diff --git a/sysdeps/unix/sysv/linux/i386/____longjmp_chk.S b/sysdeps/unix/sysv/linux/i386/____longjmp_chk.S
index 02c401c..b07e972 100644
--- a/sysdeps/unix/sysv/linux/i386/____longjmp_chk.S
+++ b/sysdeps/unix/sysv/linux/i386/____longjmp_chk.S
@@ -93,7 +93,7 @@ ENTRY (____longjmp_chk)
cmpl %esp, %edi
jnbe .Lcheck
- /* Restore registers. */
+ /* Restore registers. */
.Lout: movl (JB_BX*4)(%ecx), %ebx
movl (JB_SI*4)(%ecx), %esi
movl (JB_DI*4)(%ecx), %edi
@@ -104,7 +104,7 @@ ENTRY (____longjmp_chk)
cfi_restore(%ebp)
/* Jump to saved PC. */
- jmp *%edx
+ jmp *%edx
cfi_def_cfa(%ecx, 0)
cfi_register(%eip, %edx)
http://sources.redhat.com/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=da97dfdcfa0ecbbf2d455c54a08bb9223ce1fc18
commit da97dfdcfa0ecbbf2d455c54a08bb9223ce1fc18
Author: Ulrich Drepper <drepper@redhat.com>
Date: Thu Jul 30 21:50:14 2009 -0700
Add sigstack handling to Linux ____longjmp_chk on i386.
All other i386 ports need to provide their own versions.
diff --git a/ChangeLog b/ChangeLog
index 9e8f883..eca461f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
2009-07-30 Ulrich Drepper <drepper@redhat.com>
+ * sysdeps/unix/sysv/linux/i386/____longjmp_chk.S: New file.
+ * sysdeps/i386/____longjmp_chk.S: Remove all code. This is now a file
+ which always causes a compile error.
+
+ * sysdeps/i386/__longjmp.S: Remove bound-checking pointer support.
+
* sysdeps/unix/sysv/linux/x86_64/____longjmp_chk.S: New file. Content
comes from...
* sysdeps/x86_64/____longjmp_chk.S: ...here. This is now a file
diff --git a/sysdeps/i386/____longjmp_chk.S b/sysdeps/i386/____longjmp_chk.S
index 6cd7496..0910861 100644
--- a/sysdeps/i386/____longjmp_chk.S
+++ b/sysdeps/i386/____longjmp_chk.S
@@ -1,45 +1 @@
-/* Copyright (C) 2001,2004,2005,2006,2009 Free Software Foundation, Inc.
- This file is part of the GNU C Library.
-
- The GNU C Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation; either
- version 2.1 of the License, or (at your option) any later version.
-
- The GNU C Library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with the GNU C Library; if not, write to the Free
- Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
- 02111-1307 USA. */
-
- .section .rodata.str1.1,"aMS",@progbits,1
- .type longjmp_msg,@object
-longjmp_msg:
- .string "longjmp causes uninitialized stack frame"
- .size longjmp_msg, .-longjmp_msg
-
-
-#define __longjmp ____longjmp_chk
-
-#ifdef PIC
-# define CALL_FAIL movl %ebx, %ecx; \
- cfi_register(%ebx,%ecx); \
- LOAD_PIC_REG (bx); \
- leal longjmp_msg@GOTOFF(%ebx), %eax; \
- call __GI___fortify_fail@PLT
-#else
-# define CALL_FAIL movl $longjmp_msg, %eax; \
- call __fortify_fail
-#endif
-
-#define CHECK_ESP(reg) \
- cmpl reg, %esp; \
- jbe .Lok; \
- CALL_FAIL; \
-.Lok:
-
-#include "__longjmp.S"
+#error "OS-specific version needed"
diff --git a/sysdeps/i386/__longjmp.S b/sysdeps/i386/__longjmp.S
index 8b07320..f2eeeec 100644
--- a/sysdeps/i386/__longjmp.S
+++ b/sysdeps/i386/__longjmp.S
@@ -21,20 +21,11 @@
#include <sysdep.h>
#include <jmpbuf-offsets.h>
#include <asm-syntax.h>
-#include <bp-sym.h>
-#include <bp-asm.h>
-
-#define PARMS LINKAGE /* no space for saved regs */
-#define JBUF PARMS
-#define VAL JBUF+PTR_SIZE
.text
-ENTRY (BP_SYM (__longjmp))
- ENTER
-
+ENTRY (__longjmp)
#ifdef PTR_DEMANGLE
- movl JBUF(%esp), %eax /* User's jmp_buf in %eax. */
- CHECK_BOUNDS_BOTH_WIDE (%eax, JBUF(%esp), $JB_SIZE)
+ movl 4(%esp), %eax /* User's jmp_buf in %eax. */
/* Save the return address now. */
movl (JB_PC*4)(%eax), %edx
@@ -62,18 +53,17 @@ ENTRY (BP_SYM (__longjmp))
cfi_restore(%edi)
cfi_restore(%ebp)
- movl VAL(%esp), %eax /* Second argument is return value. */
+ movl 8(%esp), %eax /* Second argument is return value. */
movl %ecx, %esp
#else
- movl JBUF(%esp), %ecx /* User's jmp_buf in %ecx. */
- CHECK_BOUNDS_BOTH_WIDE (%ecx, JBUF(%esp), $JB_SIZE)
+ movl 4(%esp), %ecx /* User's jmp_buf in %ecx. */
# ifdef CHECK_ESP
movl (JB_SP*4)(%ecx), %eax
CHECK_ESP (%eax)
# endif
- movl VAL(%esp), %eax /* Second argument is return value. */
+ movl 8(%esp), %eax /* Second argument is return value. */
/* Save the return address now. */
movl (JB_PC*4)(%ecx), %edx
/* Restore registers. */
@@ -85,4 +75,4 @@ ENTRY (BP_SYM (__longjmp))
#endif
/* Jump to saved PC. */
jmp *%edx
-END (BP_SYM (__longjmp))
+END (__longjmp)
diff --git a/sysdeps/unix/sysv/linux/i386/____longjmp_chk.S b/sysdeps/unix/sysv/linux/i386/____longjmp_chk.S
new file mode 100644
index 0000000..02c401c
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/i386/____longjmp_chk.S
@@ -0,0 +1,143 @@
+/* Copyright (C) 2001,2004,2005,2006,2009 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sysdep.h>
+#include <jmpbuf-offsets.h>
+#include <asm-syntax.h>
+
+
+ .section .rodata.str1.1,"aMS",@progbits,1
+ .type longjmp_msg,@object
+longjmp_msg:
+ .string "longjmp causes uninitialized stack frame"
+ .size longjmp_msg, .-longjmp_msg
+
+
+#ifdef PIC
+# define CALL_FAIL movl %ebx, %ecx; \
+ cfi_register(%ebx,%ecx); \
+ LOAD_PIC_REG (bx); \
+ leal longjmp_msg@GOTOFF(%ebx), %eax; \
+ call __GI___fortify_fail@PLT
+#else
+# define CALL_FAIL movl $longjmp_msg, %eax; \
+ call __fortify_fail
+#endif
+
+#define CHECK_ESP(reg) \
+ cmpl reg, %esp; \
+ jbe .Lok; \
+ CALL_FAIL; \
+.Lok:
+
+
+ .text
+ENTRY (____longjmp_chk)
+ movl 4(%esp), %ecx /* User's jmp_buf in %ecx. */
+
+ /* Save the return address now. */
+ movl (JB_PC*4)(%ecx), %edx
+ /* Get the stack pointer. */
+ movl (JB_SP*4)(%ecx), %edi
+ cfi_undefined(%edi)
+ PTR_DEMANGLE (%edx)
+ PTR_DEMANGLE (%edi)
+
+ pushl $0
+ cfi_adjust_cfa_offset(4)
+ cmpl %edi, %esp
+ jbe .Lok
+
+ subl $12, %esp
+ cfi_adjust_cfa_offset(12)
+ xorl %ebx, %ebx
+ movl %esp, %ecx
+ movl $__NR_sigaltstack, %eax
+ ENTER_KERNEL
+ movl 4(%esp), %ebx
+ addl $12, %esp
+ cfi_adjust_cfa_offset(-12)
+ movl 8(%esp), %ecx
+ testl %eax, %eax
+ jne .Lok
+ andl $1, %ebx
+ movl %ebx, (%esp)
+.Lok:
+ cfi_def_cfa(%ecx, 0)
+ cfi_register(%eip, %edx)
+ cfi_register(%esp, %edi)
+ cfi_offset(%ebx, JB_BX*4)
+ cfi_offset(%esi, JB_SI*4)
+ cfi_offset(%edi, JB_DI*4)
+ cfi_offset(%ebp, JB_BP*4)
+
+ movl 12(%esp), %eax /* Second argument is return value. */
+ xchgl %edi, %esp
+ cfi_restore(%edi)
+
+ cmpl %esp, %edi
+ jnbe .Lcheck
+
+ /* Restore registers. */
+.Lout: movl (JB_BX*4)(%ecx), %ebx
+ movl (JB_SI*4)(%ecx), %esi
+ movl (JB_DI*4)(%ecx), %edi
+ movl (JB_BP*4)(%ecx), %ebp
+ cfi_restore(%ebx)
+ cfi_restore(%esi)
+ cfi_restore(%edi)
+ cfi_restore(%ebp)
+
+ /* Jump to saved PC. */
+ jmp *%edx
+
+ cfi_def_cfa(%ecx, 0)
+ cfi_register(%eip, %edx)
+ cfi_offset(%ebx, JB_BX*4)
+ cfi_offset(%esi, JB_SI*4)
+ cfi_offset(%edi, JB_DI*4)
+ cfi_offset(%ebp, JB_BP*4)
+
+.Lcheck:
+ cmpl $0, (%edi)
+ je .Lfail
+
+ subl $12, %esp
+ cfi_adjust_cfa_offset(12)
+ xorl %ebx, %ebx
+ movl %esp, %ecx
+ movl $__NR_sigaltstack, %eax
+ ENTER_KERNEL
+ testl $1, 4(%esp)
+ leal 12(%esp), %esp
+ movl 8(%edi), %ecx
+ movl 12(%edi), %eax
+ cfi_adjust_cfa_offset(-12)
+ je .Lout
+
+.Lfail: xchgl %edi, %esp
+ cfi_def_cfa(%esp, 8)
+ cfi_restore(%esp)
+ cfi_restore(%ebx)
+ cfi_restore(%esi)
+ cfi_undefined(%edi)
+ cfi_restore(%ebp)
+
+ CALL_FAIL
+ hlt
+END (____longjmp_chk)
http://sources.redhat.com/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=98b1e6c8668259044a20a016a5a5957b226ce04b
commit 98b1e6c8668259044a20a016a5a5957b226ce04b
Author: Ulrich Drepper <drepper@redhat.com>
Date: Thu Jul 30 21:42:27 2009 -0700
____longjmp_chk is now OS-specific.
We use sigaltstack internally which on some systems is a syscall
and should be used as such. Move the x86-64 version to the Linux
specific directory and create in its place a file which always
causes compile errors.
diff --git a/ChangeLog b/ChangeLog
index db6e93d..9e8f883 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
2009-07-30 Ulrich Drepper <drepper@redhat.com>
+ * sysdeps/unix/sysv/linux/x86_64/____longjmp_chk.S: New file. Content
+ comes from...
+ * sysdeps/x86_64/____longjmp_chk.S: ...here. This is now a file
+ which always causes a compile error.
+
* debug/Makefile (tests): Add tst-longjmp_chk2.
* debug/tst-longjmp_chk2.c: New file.
diff --git a/sysdeps/x86_64/____longjmp_chk.S b/sysdeps/unix/sysv/linux/x86_64/____longjmp_chk.S
similarity index 100%
copy from sysdeps/x86_64/____longjmp_chk.S
copy to sysdeps/unix/sysv/linux/x86_64/____longjmp_chk.S
diff --git a/sysdeps/x86_64/____longjmp_chk.S b/sysdeps/x86_64/____longjmp_chk.S
index 80e4aff..0910861 100644
--- a/sysdeps/x86_64/____longjmp_chk.S
+++ b/sysdeps/x86_64/____longjmp_chk.S
@@ -1,145 +1 @@
-/* Copyright (C) 2001,2004,2005,2006,2009 Free Software Foundation, Inc.
- This file is part of the GNU C Library.
-
- The GNU C Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation; either
- version 2.1 of the License, or (at your option) any later version.
-
- The GNU C Library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with the GNU C Library; if not, write to the Free
- Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
- 02111-1307 USA. */
-
-#include <sysdep.h>
-#include <jmpbuf-offsets.h>
-#include <asm-syntax.h>
-
- .section .rodata.str1.1,"aMS",@progbits,1
- .type longjmp_msg,@object
-longjmp_msg:
- .string "longjmp causes uninitialized stack frame"
- .size longjmp_msg, .-longjmp_msg
-
-
-//#define __longjmp ____longjmp_chk
-
-#ifdef PIC
-# define CALL_FAIL leaq longjmp_msg(%rip), %rdi; \
- call __GI___fortify_fail
-#else
-# define CALL_FAIL movq $longjmp_msg, %rdi; \
- call __fortify_fail
-#endif
-
-#define CHECK_RSP(reg) \
- cmpq reg, %rsp; \
- jbe .Lok; \
- CALL_FAIL; \
-.Lok:
-
-/* Jump to the position specified by ENV, causing the
- setjmp call there to return VAL, or 1 if VAL is 0.
- void __longjmp (__jmp_buf env, int val). */
- .text
-ENTRY(____longjmp_chk)
- /* Restore registers. */
- movq (JB_RSP*8)(%rdi),%r8
- movq (JB_RBP*8)(%rdi),%r9
- movq (JB_PC*8)(%rdi),%rdx
-#ifdef PTR_DEMANGLE
- PTR_DEMANGLE (%r8)
- PTR_DEMANGLE (%r9)
- PTR_DEMANGLE (%rdx)
-#endif
-
- /* Save function parameters. */
- movq %rdi, %r10
- movl %esi, %ecx
-
- xorl %eax, %eax
- cmpq %r8, %rsp
- jbe .Lok
-
- subq $24, %rsp
- cfi_adjust_cfa_offset(24)
- xorl %edi, %edi
- movq %rsp, %rsi
- movl $__NR_sigaltstack, %eax
- syscall
- testl %eax, %eax
- movl $0, %eax
- leaq 24(%rsp), %rsp
- cfi_adjust_cfa_offset(-24)
- jne .Lok
- movl 8(%rsp), %eax
- andl $1, %eax
-
-.Lok:
- /* We add unwind information for the target here. */
- cfi_def_cfa(%r10, 0)
- cfi_register(%rsp,%r8)
- cfi_register(%rbp,%r9)
- cfi_register(%rip,%rdx)
- cfi_offset(%rbx,JB_RBX*8)
- cfi_offset(%r12,JB_R12*8)
- cfi_offset(%r13,JB_R13*8)
- cfi_offset(%r14,JB_R14*8)
- cfi_offset(%r15,JB_R15*8)
-
- xchgq %r8, %rsp
- cfi_restore(%rsp)
- xchgq %r9, %rbp
- cfi_restore(%rbp)
-
- movq (JB_RBX*8)(%r10),%rbx
- movq (JB_R12*8)(%r10),%r12
- movq (JB_R13*8)(%r10),%r13
- movq (JB_R14*8)(%r10),%r14
- movq (JB_R15*8)(%r10),%r15
-
- cmpq %rsp, %r8
- jnbe .Lcheck
-
- /* Set return value for setjmp. */
-.Lout: movl %ecx, %eax
- jmpq *%rdx
-
-.Lcheck:
- testl %eax, %eax
- je .Lfail
-
- subq $24, %rsp
- cfi_adjust_cfa_offset(24)
- xorl %edi, %edi
- movq %rsp, %rsi
- movl $__NR_sigaltstack, %eax
- syscall
- addq $24, %rsp
- cfi_adjust_cfa_offset(-24)
- testl $1, 8(%rsp)
- je .Lout
-
-.Lfail: xchgq %r8, %rsp
- /* We want the stack trace to show that of the caller. */
- cfi_def_cfa(%rsp, 8)
- cfi_restore(%rsp)
- cfi_register(%rbp, %r9)
- cfi_restore(%rip)
- cfi_restore(%rbx)
- cfi_restore(%r12)
- cfi_restore(%r13)
- cfi_restore(%r14)
- cfi_restore(%r15)
-
- xchgq %r9, %rbp
- cfi_restore(%rbp)
-
- CALL_FAIL
- hlt
-END (BP_SYM (____longjmp_chk))
+#error "OS-specific version needed"
http://sources.redhat.com/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=8e80581787d2342824d9b70d238e646326776c31
commit 8e80581787d2342824d9b70d238e646326776c31
Author: Ulrich Drepper <drepper@redhat.com>
Date: Thu Jul 30 21:29:27 2009 -0700
Change code a bit to correct CFI.
diff --git a/sysdeps/x86_64/____longjmp_chk.S b/sysdeps/x86_64/____longjmp_chk.S
index 23aa0cb..80e4aff 100644
--- a/sysdeps/x86_64/____longjmp_chk.S
+++ b/sysdeps/x86_64/____longjmp_chk.S
@@ -74,6 +74,8 @@ ENTRY(____longjmp_chk)
syscall
testl %eax, %eax
movl $0, %eax
+ leaq 24(%rsp), %rsp
+ cfi_adjust_cfa_offset(-24)
jne .Lok
movl 8(%rsp), %eax
andl $1, %eax
@@ -125,7 +127,7 @@ ENTRY(____longjmp_chk)
.Lfail: xchgq %r8, %rsp
/* We want the stack trace to show that of the caller. */
- cfi_def_cfa(%rsp, 32)
+ cfi_def_cfa(%rsp, 8)
cfi_restore(%rsp)
cfi_register(%rbp, %r9)
cfi_restore(%rip)
http://sources.redhat.com/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=07df80996944b95a238be755eb4957a83a5e4762
commit 07df80996944b95a238be755eb4957a83a5e4762
Author: Ulrich Drepper <drepper@redhat.com>
Date: Thu Jul 30 20:09:30 2009 -0700
Optimize ____longjmp_chk for x86-64 a bit.
diff --git a/sysdeps/x86_64/____longjmp_chk.S b/sysdeps/x86_64/____longjmp_chk.S
index 50d2fca..23aa0cb 100644
--- a/sysdeps/x86_64/____longjmp_chk.S
+++ b/sysdeps/x86_64/____longjmp_chk.S
@@ -66,14 +66,12 @@ ENTRY(____longjmp_chk)
cmpq %r8, %rsp
jbe .Lok
- subq $32, %rsp
- cfi_adjust_cfa_offset(32)
- movq %r10, 24(%rsp)
+ subq $24, %rsp
+ cfi_adjust_cfa_offset(24)
xorl %edi, %edi
movq %rsp, %rsi
movl $__NR_sigaltstack, %eax
syscall
- movq 24(%rsp), %r10
testl %eax, %eax
movl $0, %eax
jne .Lok
@@ -127,7 +125,7 @@ ENTRY(____longjmp_chk)
.Lfail: xchgq %r8, %rsp
/* We want the stack trace to show that of the caller. */
- cfi_def_cfa(%rsp, 40)
+ cfi_def_cfa(%rsp, 32)
cfi_restore(%rsp)
cfi_register(%rbp, %r9)
cfi_restore(%rip)
http://sources.redhat.com/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=85d9d2f3a089f747177895b115ca2186f34b0122
commit 85d9d2f3a089f747177895b115ca2186f34b0122
Author: Ulrich Drepper <drepper@redhat.com>
Date: Thu Jul 30 19:46:46 2009 -0700
Add CFLAGS definition missing from last patch.
diff --git a/debug/Makefile b/debug/Makefile
index 99c8092..d7c51ca 100644
--- a/debug/Makefile
+++ b/debug/Makefile
@@ -82,6 +82,8 @@ CFLAGS-recv_chk.c = -fexceptions -fasynchronous-unwind-tables
CFLAGS-recvfrom_chk.c = -fexceptions -fasynchronous-unwind-tables
CFLAGS-tst-longjmp_chk.c = -fexceptions -fasynchronous-unwind-tables \
-D_FORTIFY_SOURCE=1
+CFLAGS-tst-longjmp_chk2.c = -fexceptions -fasynchronous-unwind-tables \
+ -D_FORTIFY_SOURCE=1
# We know these tests have problems with format strings, this is what
# we are testing. Disable that warning.
http://sources.redhat.com/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=a9a04420818e1ab0a49838e2eb83ebb66baaeaac
commit a9a04420818e1ab0a49838e2eb83ebb66baaeaac
Author: Ulrich Drepper <drepper@redhat.com>
Date: Thu Jul 30 17:48:58 2009 -0700
Add test case for ____longjmp_chk vs signal stacks.
diff --git a/ChangeLog b/ChangeLog
index 2492d49..db6e93d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
2009-07-30 Ulrich Drepper <drepper@redhat.com>
+ * debug/Makefile (tests): Add tst-longjmp_chk2.
+ * debug/tst-longjmp_chk2.c: New file.
+
* sysdeps/x86_64/__longjmp.S: Remove CHECK_RSP handling. Fix CFI.
Remove incorrect use of BP_SYM.
* sysdeps/x86_64/____longjmp_chk.S: Rewrite. Complete implementation
diff --git a/debug/Makefile b/debug/Makefile
index 181169b..99c8092 100644
--- a/debug/Makefile
+++ b/debug/Makefile
@@ -118,7 +118,8 @@ LDFLAGS-tst-lfschk6 = -lstdc++
tests = backtrace-tst tst-longjmp_chk tst-chk1 tst-chk2 tst-chk3 \
tst-lfschk1 tst-lfschk2 tst-lfschk3 test-strcpy_chk test-stpcpy_chk \
- tst-chk4 tst-chk5 tst-chk6 tst-lfschk4 tst-lfschk5 tst-lfschk6
+ tst-chk4 tst-chk5 tst-chk6 tst-lfschk4 tst-lfschk5 tst-lfschk6 \
+ tst-longjmp_chk2
extra-libs = libSegFault libpcprofile
extra-libs-others = $(extra-libs)
diff --git a/debug/tst-longjmp_chk2.c b/debug/tst-longjmp_chk2.c
new file mode 100644
index 0000000..22d8bf0
--- /dev/null
+++ b/debug/tst-longjmp_chk2.c
@@ -0,0 +1,114 @@
+/* Test case mostly written by Paolo Bonzini <pbonzini@redhat.com>. */
+#include <assert.h>
+#include <setjmp.h>
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/time.h>
+#include <sys/resource.h>
+
+
+static jmp_buf mainloop;
+static sigset_t mainsigset;
+static int pass;
+
+
+static void
+stackoverflow_handler (int sig)
+{
+ stack_t altstack;
+ pass++;
+ sigaltstack (NULL, &altstack);
+ /* Using printf is not really kosher in signal handlers but we know
+ it will work. */
+ printf ("%*sin signal handler\n", pass, "");
+ if (altstack.ss_flags & SS_ONSTACK)
+ printf ("%*son alternate stack\n", pass, "");
+ siglongjmp (mainloop, pass);
+}
+
+
+static volatile int *
+recurse_1 (int n, volatile int *p)
+{
+ if (n >= 0)
+ *recurse_1 (n + 1, p) += n;
+ return p;
+}
+
+
+static int
+recurse (int n)
+{
+ int sum = 0;
+ return *recurse_1 (n, &sum);
+}
+
+
+static int
+do_test (void)
+{
+ char mystack[SIGSTKSZ];
+ stack_t altstack;
+ struct sigaction action;
+ sigset_t emptyset;
+ /* Before starting the endless recursion, try to be friendly to the user's
+ machine. On some Linux 2.2.x systems, there is no stack limit for user
+ processes at all. We don't want to kill such systems. */
+ struct rlimit rl;
+ rl.rlim_cur = rl.rlim_max = 0x100000; /* 1 MB */
+ setrlimit (RLIMIT_STACK, &rl);
+ /* Install the alternate stack. */
+ altstack.ss_sp = mystack;
+ altstack.ss_size = sizeof (mystack);
+ altstack.ss_flags = 0; /* no SS_DISABLE */
+ if (sigaltstack (&altstack, NULL) < 0)
+ {
+ puts ("first sigaltstack failed");
+ return 0;
+ }
+ /* Install the SIGSEGV handler. */
+ sigemptyset (&action.sa_mask);
+ action.sa_handler = &stackoverflow_handler;
+ action.sa_flags = SA_ONSTACK;
+ sigaction (SIGSEGV, &action, (struct sigaction *) NULL);
+ sigaction (SIGBUS, &action, (struct sigaction *) NULL);
+
+ /* Save the current signal mask. */
+ sigemptyset (&emptyset);
+ sigprocmask (SIG_BLOCK, &emptyset, &mainsigset);
+
+ /* Provoke two stack overflows in a row. */
+ if (sigsetjmp (mainloop, 1) != 0)
+ {
+ assert (pass != 0);
+ printf ("%*sout of signal handler\n", pass, "");
+ }
+ else
+ assert (pass == 0);
+
+ sigaltstack (NULL, &altstack);
+ if (altstack.ss_flags & SS_ONSTACK)
+ printf ("%*son alternate stack\n", pass, "");
+ else
+ printf ("%*snot on alternate stack\n", pass, "");
+
+ if (pass < 2)
+ {
+ recurse (0);
+ puts ("recurse call returned");
+ return 2;
+ }
+
+ altstack.ss_flags |= SS_DISABLE;
+ if (sigaltstack (&altstack, NULL) == -1)
+ printf ("disabling alternate stack failed\n");
+ else
+ printf ("disabling alternate stack succeeded \n");
+
+ return 0;
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
http://sources.redhat.com/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=5ead9ce5c788e7dbb0bd01888c4bcb37a8bc2ff1
commit 5ead9ce5c788e7dbb0bd01888c4bcb37a8bc2ff1
Author: Ulrich Drepper <drepper@redhat.com>
Date: Thu Jul 30 17:31:48 2009 -0700
Fix x86-64 ____longjmp_chk to handle signal stacks.
The simple test previously used might trigger if the longjmp jumps
from the signal stack to the normal stack. We now explicitly test
for this case.
diff --git a/ChangeLog b/ChangeLog
index 9e78199..2492d49 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
2009-07-30 Ulrich Drepper <drepper@redhat.com>
+ * sysdeps/x86_64/__longjmp.S: Remove CHECK_RSP handling. Fix CFI.
+ Remove incorrect use of BP_SYM.
+ * sysdeps/x86_64/____longjmp_chk.S: Rewrite. Complete implementation
+ here now since it is more complex than just a simple check.
+
* sysdeps/ia64/backtrace.c (backtrace_helper): Stop backtrace when
we make no more progress.
diff --git a/sysdeps/x86_64/____longjmp_chk.S b/sysdeps/x86_64/____longjmp_chk.S
index 030a0dc..50d2fca 100644
--- a/sysdeps/x86_64/____longjmp_chk.S
+++ b/sysdeps/x86_64/____longjmp_chk.S
@@ -16,6 +16,10 @@
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
+#include <sysdep.h>
+#include <jmpbuf-offsets.h>
+#include <asm-syntax.h>
+
.section .rodata.str1.1,"aMS",@progbits,1
.type longjmp_msg,@object
longjmp_msg:
@@ -23,7 +27,7 @@ longjmp_msg:
.size longjmp_msg, .-longjmp_msg
-#define __longjmp ____longjmp_chk
+//#define __longjmp ____longjmp_chk
#ifdef PIC
# define CALL_FAIL leaq longjmp_msg(%rip), %rdi; \
@@ -39,4 +43,103 @@ longjmp_msg:
CALL_FAIL; \
.Lok:
-#include "__longjmp.S"
+/* Jump to the position specified by ENV, causing the
+ setjmp call there to return VAL, or 1 if VAL is 0.
+ void __longjmp (__jmp_buf env, int val). */
+ .text
+ENTRY(____longjmp_chk)
+ /* Restore registers. */
+ movq (JB_RSP*8)(%rdi),%r8
+ movq (JB_RBP*8)(%rdi),%r9
+ movq (JB_PC*8)(%rdi),%rdx
+#ifdef PTR_DEMANGLE
+ PTR_DEMANGLE (%r8)
+ PTR_DEMANGLE (%r9)
+ PTR_DEMANGLE (%rdx)
+#endif
+
+ /* Save function parameters. */
+ movq %rdi, %r10
+ movl %esi, %ecx
+
+ xorl %eax, %eax
+ cmpq %r8, %rsp
+ jbe .Lok
+
+ subq $32, %rsp
+ cfi_adjust_cfa_offset(32)
+ movq %r10, 24(%rsp)
+ xorl %edi, %edi
+ movq %rsp, %rsi
+ movl $__NR_sigaltstack, %eax
+ syscall
+ movq 24(%rsp), %r10
+ testl %eax, %eax
+ movl $0, %eax
+ jne .Lok
+ movl 8(%rsp), %eax
+ andl $1, %eax
+
+.Lok:
+ /* We add unwind information for the target here. */
+ cfi_def_cfa(%r10, 0)
+ cfi_register(%rsp,%r8)
+ cfi_register(%rbp,%r9)
+ cfi_register(%rip,%rdx)
+ cfi_offset(%rbx,JB_RBX*8)
+ cfi_offset(%r12,JB_R12*8)
+ cfi_offset(%r13,JB_R13*8)
+ cfi_offset(%r14,JB_R14*8)
+ cfi_offset(%r15,JB_R15*8)
+
+ xchgq %r8, %rsp
+ cfi_restore(%rsp)
+ xchgq %r9, %rbp
+ cfi_restore(%rbp)
+
+ movq (JB_RBX*8)(%r10),%rbx
+ movq (JB_R12*8)(%r10),%r12
+ movq (JB_R13*8)(%r10),%r13
+ movq (JB_R14*8)(%r10),%r14
+ movq (JB_R15*8)(%r10),%r15
+
+ cmpq %rsp, %r8
+ jnbe .Lcheck
+
+ /* Set return value for setjmp. */
+.Lout: movl %ecx, %eax
+ jmpq *%rdx
+
+.Lcheck:
+ testl %eax, %eax
+ je .Lfail
+
+ subq $24, %rsp
+ cfi_adjust_cfa_offset(24)
+ xorl %edi, %edi
+ movq %rsp, %rsi
+ movl $__NR_sigaltstack, %eax
+ syscall
+ addq $24, %rsp
+ cfi_adjust_cfa_offset(-24)
+ testl $1, 8(%rsp)
+ je .Lout
+
+.Lfail: xchgq %r8, %rsp
+ /* We want the stack trace to show that of the caller. */
+ cfi_def_cfa(%rsp, 40)
+ cfi_restore(%rsp)
+ cfi_register(%rbp, %r9)
+ cfi_restore(%rip)
+ cfi_restore(%rbx)
+ cfi_restore(%r12)
+ cfi_restore(%r13)
+ cfi_restore(%r14)
+ cfi_restore(%r15)
+
+ xchgq %r9, %rbp
+ cfi_restore(%rbp)
+
+ CALL_FAIL
+ hlt
+END (BP_SYM (____longjmp_chk))
diff --git a/sysdeps/x86_64/__longjmp.S b/sysdeps/x86_64/__longjmp.S
index 24552ec..b045c04 100644
--- a/sysdeps/x86_64/__longjmp.S
+++ b/sysdeps/x86_64/__longjmp.S
@@ -34,16 +34,12 @@ ENTRY(__longjmp)
PTR_DEMANGLE (%r9)
PTR_DEMANGLE (%rdx)
#endif
-#ifdef CHECK_RSP
- CHECK_RSP (%r8)
-#endif
/* We add unwind information for the target here. */
cfi_def_cfa(%rdi, 0)
cfi_register(%rsp,%r8)
cfi_register(%rbp,%r9)
cfi_register(%rip,%rdx)
cfi_offset(%rbx,JB_RBX*8)
- cfi_offset(%rbp,JB_RBP*8)
cfi_offset(%r12,JB_R12*8)
cfi_offset(%r13,JB_R13*8)
cfi_offset(%r14,JB_R14*8)
@@ -58,4 +54,4 @@ ENTRY(__longjmp)
movq %r8,%rsp
movq %r9,%rbp
jmpq *%rdx
-END (BP_SYM (__longjmp))
+END (__longjmp)
http://sources.redhat.com/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=2dec6007d183aa51abedbbb048382973129f3935
commit 2dec6007d183aa51abedbbb048382973129f3935
Author: Ulrich Drepper <drepper@redhat.com>
Date: Thu Jul 30 16:53:52 2009 -0700
Stop backtrace when we make no more progress.
diff --git a/ChangeLog b/ChangeLog
index 0d0120c..9e78199 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2009-07-30 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/ia64/backtrace.c (backtrace_helper): Stop backtrace when
+ we make no more progress.
+
2009-07-29 Ulrich Drepper <drepper@redhat.com>
* math/s_fma.c: Don't define alias if __fma is a macro.
diff --git a/sysdeps/ia64/backtrace.c b/sysdeps/ia64/backtrace.c
index 423fed8..5cefb86 100644
--- a/sysdeps/ia64/backtrace.c
+++ b/sysdeps/ia64/backtrace.c
@@ -1,5 +1,5 @@
/* Return backtrace of current program state.
- Copyright (C) 2003, 2004, 2005, 2007 Free Software Foundation, Inc.
+ Copyright (C) 2003, 2004, 2005, 2007, 2009 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Jakub Jelinek <jakub@redhat.com>, 2003.
@@ -61,7 +61,13 @@ backtrace_helper (struct _Unwind_Context *ctx, void *a)
/* We are first called with address in the __backtrace function.
Skip it. */
if (arg->cnt != -1)
- arg->array[arg->cnt] = (void *) unwind_getip (ctx);
+ {
+ arg->array[arg->cnt] = (void *) unwind_getip (ctx);
+
+ /* Check whether we make any progress. */
+ if (arg->cnt > 0 && arg->array[arg->cnt - 1] == arg->array[arg->cnt])
+ return _URC_END_OF_STACK;
+ }
if (++arg->cnt == arg->size)
return _URC_END_OF_STACK;
return _URC_NO_REASON;
-----------------------------------------------------------------------
Summary of changes:
ChangeLog | 24 ++++
debug/Makefile | 5 +-
debug/tst-longjmp_chk2.c | 114 +++++++++++++++++
sysdeps/i386/____longjmp_chk.S | 46 +-------
sysdeps/i386/__longjmp.S | 22 +---
sysdeps/ia64/backtrace.c | 10 ++-
sysdeps/unix/sysv/linux/i386/____longjmp_chk.S | 143 +++++++++++++++++++++
sysdeps/unix/sysv/linux/x86_64/____longjmp_chk.S | 145 ++++++++++++++++++++++
sysdeps/x86_64/____longjmp_chk.S | 43 +------
sysdeps/x86_64/__longjmp.S | 6 +-
10 files changed, 447 insertions(+), 111 deletions(-)
create mode 100644 debug/tst-longjmp_chk2.c
create mode 100644 sysdeps/unix/sysv/linux/i386/____longjmp_chk.S
create mode 100644 sysdeps/unix/sysv/linux/x86_64/____longjmp_chk.S
hooks/post-receive
--
GNU C Library master sources