]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
Fix guard alignment in allocate_stack when stack grows up.
authorJohn David Anglin <danglin@gcc.gnu.org>
Sat, 15 Jul 2017 16:40:13 +0000 (12:40 -0400)
committerJohn David Anglin <danglin@gcc.gnu.org>
Sat, 15 Jul 2017 16:40:13 +0000 (12:40 -0400)
ChangeLog
nptl/allocatestack.c

index b6befe232945bb2dec78b850241786eabf1045c7..41c050e0a34b51c923ca4e193e16778a9fb9aafd 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
 2017-07-15  John David Anglin  <danglin@gcc.gnu.org>
 
+       * nptl/allocatestack.c (allocate_stack): Align old and new guard
+       addresses to page boundaries when the stack grows up.
+
        * sysdeps/hppa/math-tests.h: New.
 
 2017-07-14  DJ Delorie  <dj@redhat.com>
index ec7d42e027ba0ef76cc289d7bf0833c433685193..ce2e24af951204e1fbd5d5ad56909226e216a51f 100644 (file)
@@ -697,8 +697,14 @@ allocate_stack (const struct pthread_attr *attr, struct pthread **pdp,
                        prot) != 0)
            goto mprot_error;
 #elif _STACK_GROWS_UP
-         if (__mprotect ((char *) pd - pd->guardsize,
-                       pd->guardsize - guardsize, prot) != 0)
+         char *new_guard = (char *)(((uintptr_t) pd - guardsize)
+                                    & ~pagesize_m1);
+         char *old_guard = (char *)(((uintptr_t) pd - pd->guardsize)
+                                    & ~pagesize_m1);
+         /* The guard size difference might be > 0, but once rounded
+            to the nearest page the size difference might be zero.  */
+         if (new_guard > old_guard
+             && mprotect (old_guard, new_guard - old_guard, prot) != 0)
            goto mprot_error;
 #endif