From 075385f98af239ff5807a5c6ed17fec51e048454 Mon Sep 17 00:00:00 2001 From: John David Anglin Date: Sat, 15 Jul 2017 12:40:13 -0400 Subject: Fix guard alignment in allocate_stack when stack grows up. --- nptl/allocatestack.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'nptl') diff --git a/nptl/allocatestack.c b/nptl/allocatestack.c index ec7d42e..ce2e24a 100644 --- a/nptl/allocatestack.c +++ b/nptl/allocatestack.c @@ -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 -- cgit v1.1