diff options
author | Siddhesh Poyarekar <siddhesh@redhat.com> | 2012-05-26 09:48:25 +0530 |
---|---|---|
committer | Siddhesh Poyarekar <siddhesh@redhat.com> | 2012-05-26 09:48:26 +0530 |
commit | 9c6ea9facbba4d430807bd21fa82892d713b1ecd (patch) | |
tree | fc116e5e30c8ea5cada22f53d6914fbc33eb586e /nptl | |
parent | a82392228a31bb94b8dc4c35a37b04611d19891f (diff) | |
download | glibc-9c6ea9facbba4d430807bd21fa82892d713b1ecd.tar.gz glibc-9c6ea9facbba4d430807bd21fa82892d713b1ecd.tar.xz glibc-9c6ea9facbba4d430807bd21fa82892d713b1ecd.zip |
Fix stack size and address inconsistency due to executable stack
When a stack is marked executable due to loading a DSO that requires an executable stack, the logic tends to leave out a portion of stack after the first frame, thus causing a difference in the value returned by pthread_getattr_np before and after the stack is marked executable. It ought to be possible to fix this by marking the rest of the stack as executable too, but in the interest of marking as less of the stack as executable as possible, the path this fix takes is to make pthread_getattr_np also look at the first frame as the underflow end of the stack and compute size and stack top accordingly. The above happens only for the main process stack. NPTL thread stacks are not affected by this change.
Diffstat (limited to 'nptl')
-rw-r--r-- | nptl/ChangeLog | 7 | ||||
-rw-r--r-- | nptl/pthread_getattr_np.c | 16 |
2 files changed, 21 insertions, 2 deletions
diff --git a/nptl/ChangeLog b/nptl/ChangeLog index a488ccb37d..492668bdeb 100644 --- a/nptl/ChangeLog +++ b/nptl/ChangeLog @@ -1,3 +1,10 @@ +2012-05-26 Siddhesh Poyarekar <siddhesh@redhat.com> + + [BZ #12416] + * nptl/pthread_getattr_np.c (pthread_getattr_np): Use + __libc_stack_end rounded to the end of containing page as the + real stack end. + 2012-05-25 Rayson Ho <rho@redhat.com> * sysdeps/unix/sysv/linux/i386/lowlevellock.h: Low-level SystemTap diff --git a/nptl/pthread_getattr_np.c b/nptl/pthread_getattr_np.c index f1268dd82f..75d717bb1f 100644 --- a/nptl/pthread_getattr_np.c +++ b/nptl/pthread_getattr_np.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2002-2004, 2006, 2007, 2011 Free Software Foundation, Inc. +/* Copyright (C) 2002-2012 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@redhat.com>, 2002. @@ -84,6 +84,18 @@ pthread_getattr_np (thread_id, attr) ret = errno; else { + /* We consider the main process stack to have ended with + the page containing __libc_stack_end. There is stuff below + it in the stack too, like the program arguments, environment + variables and auxv info, but we ignore those pages when + returning size so that the output is consistent when the + stack is marked executable due to a loaded DSO requiring + it. */ + void *stack_end = (void *) ((uintptr_t) __libc_stack_end + & -(uintptr_t) GLRO(dl_pagesize)); +#if _STACK_GROWS_DOWN + stack_end += GLRO(dl_pagesize); +#endif /* We need no locking. */ __fsetlocking (fp, FSETLOCKING_BYCALLER); @@ -109,7 +121,7 @@ pthread_getattr_np (thread_id, attr) { /* Found the entry. Now we have the info we need. */ iattr->stacksize = rl.rlim_cur; - iattr->stackaddr = (void *) to; + iattr->stackaddr = stack_end; /* The limit might be too high. */ if ((size_t) iattr->stacksize |