[v2] Fix stack memory protection on targets where the stack grows upward
Commit Message
On 2017-04-16, at 4:06 PM, Andreas Schwab wrote:
> On Apr 16 2017, John David Anglin <dave.anglin@bell.net> wrote:
>
>> + char *new_guard = (char *)(((uintptr_t) pd - guardsize) & ~pagesize_m1);
>> + char *old_guard = (char *)(((uintptr_t) pd - pd->guardsize) & ~pagesize_m1);
>
> The lines are too long.
The long lines are fixed in this version. Otherwise, unchanged.
Dave
--
John David Anglin dave.anglin@bell.net
2017-04-17 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.
@@ -647,8 +647,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