summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristophe Lyon <christophe.lyon@st.com>2018-07-04 17:55:31 +0200
committerWaldemar Brodkorb <wbrodkorb@conet.de>2018-08-10 16:02:45 +0200
commit5b9a9801a4867af70c9ed55379b3eaa3dba59ef3 (patch)
treed408f2e9f64dc5ab9e973232fb8353b29e547119
parentfcecd012a6944eab8912787ca668b280e7233a8d (diff)
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>
-rw-r--r--libpthread/nptl/allocatestack.c6
1 files changed, 6 insertions, 0 deletions
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;
@@ -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;
}