diff options
author | Siddhesh Poyarekar <siddhesh@redhat.com> | 2012-06-20 13:03:13 +0530 |
---|---|---|
committer | Siddhesh Poyarekar <siddhesh@redhat.com> | 2012-06-20 15:08:22 +0530 |
commit | 18b5e737de22462ab6b3fc89f26c9ad480ebb843 (patch) | |
tree | 1590e539c9a989c7807a048962c3b895f116a0f9 /nptl/pthread_getattr_np.c | |
parent | a2f34833b1042d5d8eeb263b4cf4caaea138c4ad (diff) | |
download | glibc-18b5e737de22462ab6b3fc89f26c9ad480ebb843.tar.gz glibc-18b5e737de22462ab6b3fc89f26c9ad480ebb843.tar.xz glibc-18b5e737de22462ab6b3fc89f26c9ad480ebb843.zip |
Account for the extra stack size when rlimit is small enough
When rlimit is small enough to be used as the stacksize to be returned in pthread_getattr_np, cases where a stack is made executable due to a DSO load get stack size that is larger than what the kernel allows. This is because in such a case the stack size does not account for the pages that have auxv and program arguments. Additionally, the stacksize for the process derived from this should be truncated to align to page size to avoid going beyond rlimit.
Diffstat (limited to 'nptl/pthread_getattr_np.c')
-rw-r--r-- | nptl/pthread_getattr_np.c | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/nptl/pthread_getattr_np.c b/nptl/pthread_getattr_np.c index 75d717bb1f..7309185d14 100644 --- a/nptl/pthread_getattr_np.c +++ b/nptl/pthread_getattr_np.c @@ -120,8 +120,15 @@ pthread_getattr_np (thread_id, attr) && (uintptr_t) __libc_stack_end < to) { /* Found the entry. Now we have the info we need. */ - iattr->stacksize = rl.rlim_cur; iattr->stackaddr = stack_end; + iattr->stacksize = + rl.rlim_cur - (size_t) (to - (uintptr_t) stack_end); + + /* Cut it down to align it to page size since otherwise we + risk going beyond rlimit when the kernel rounds up the + stack extension request. */ + iattr->stacksize = (iattr->stacksize + & -(intptr_t) GLRO(dl_pagesize)); /* The limit might be too high. */ if ((size_t) iattr->stacksize |