Browse Source

nptl: disable mprotect usage in stack protection

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>
Christophe Lyon 5 years ago
parent
commit
5b9a9801a4
1 changed files with 6 additions and 0 deletions
  1. 6 0
      libpthread/nptl/allocatestack.c

+ 6 - 0
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;