From 5b9a9801a4867af70c9ed55379b3eaa3dba59ef3 Mon Sep 17 00:00:00 2001 From: Christophe Lyon Date: Wed, 4 Jul 2018 17:55:31 +0200 Subject: nptl: disable mprotect usage in stack protection MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Since mprotect does not work on MMU-less systems, disable it if __ARCH_USE_MMU__ is not defined. * libpthread/nptl/allocatestack.c (change_stack_perm): Call mprotect only if __ARCH_USE_MMU__ is defined. (allocate_stack): Likewise. Signed-off-by: Mickaël Guêné Signed-off-by: Christophe Lyon --- libpthread/nptl/allocatestack.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/libpthread/nptl/allocatestack.c b/libpthread/nptl/allocatestack.c index 290051796..137979542 100644 --- a/libpthread/nptl/allocatestack.c +++ b/libpthread/nptl/allocatestack.c @@ -328,8 +328,10 @@ change_stack_perm (struct pthread *pd #else # error "Define either _STACK_GROWS_DOWN or _STACK_GROWS_UP" #endif +#ifdef __ARCH_USE_MMU__ if (mprotect (stack, len, PROT_READ | PROT_WRITE | PROT_EXEC) != 0) return errno; +#endif return 0; } @@ -593,6 +595,7 @@ allocate_stack (const struct pthread_attr *attr, struct pthread **pdp, #elif defined _STACK_GROWS_UP char *guard = (char *) (((uintptr_t) pd - guardsize) & ~pagesize_m1); #endif +#ifdef __ARCH_USE_MMU__ if (mprotect (guard, guardsize, PROT_NONE) != 0) { int err; @@ -618,6 +621,7 @@ allocate_stack (const struct pthread_attr *attr, struct pthread **pdp, return err; } +#endif pd->guardsize = guardsize; } @@ -630,6 +634,7 @@ allocate_stack (const struct pthread_attr *attr, struct pthread **pdp, char *guard = mem + (((size - guardsize) / 2) & ~pagesize_m1); char *oldguard = mem + (((size - pd->guardsize) / 2) & ~pagesize_m1); +#ifdef __ARCH_USE_MMU__ if (oldguard < guard && mprotect (oldguard, guard - oldguard, prot) != 0) goto mprot_error; @@ -646,6 +651,7 @@ allocate_stack (const struct pthread_attr *attr, struct pthread **pdp, if (mprotect ((char *) (((uintptr_t) pd - pd->guardsize) & ~pagesize_m1), pd->guardsize - guardsize, prot) != 0) goto mprot_error; +#endif #endif pd->guardsize = guardsize; -- cgit v1.2.3