diff mbox series

[uclibc-ng-devel,18/32,FDPIC] nptl: disable mprotect usage in stack protection

Message ID 20180704155605.1892-19-christophe.lyon@st.com
State Accepted
Headers show
Series FDPIC ABI for ARM | expand

Commit Message

Christophe Lyon July 4, 2018, 3:55 p.m. UTC
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é <mickael.guene@st.com>
Signed-off-by: Christophe Lyon <christophe.lyon@st.com>
diff mbox series

Patch

diff --git a/libpthread/nptl/allocatestack.c b/libpthread/nptl/allocatestack.c
index 2900517..1379795 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;
@@ -647,6 +652,7 @@  allocate_stack (const struct pthread_attr *attr, struct pthread **pdp,
 			pd->guardsize - guardsize, prot) != 0)
 	    goto mprot_error;
 #endif
+#endif
 
 	  pd->guardsize = guardsize;
 	}