aboutsummaryrefslogtreecommitdiff
path: root/nptl
diff options
context:
space:
mode:
authorSzabolcs Nagy <szabolcs.nagy@arm.com>2022-10-24 16:18:42 +0100
committerSzabolcs Nagy <szabolcs.nagy@arm.com>2022-11-22 14:31:25 +0000
commitcb78f7d9d3cfd05d71208d199dafdb28ea05a92c (patch)
tree326884952fdb887be99b288a89695bb2ce32ed86 /nptl
parent83cc56b97a1d3802044d15d3dc23605e555d3f66 (diff)
downloadglibc-cb78f7d9d3cfd05d71208d199dafdb28ea05a92c.zip
glibc-cb78f7d9d3cfd05d71208d199dafdb28ea05a92c.tar.gz
glibc-cb78f7d9d3cfd05d71208d199dafdb28ea05a92c.tar.bz2
cheri: nptl: Fix thread stack capability permissions
Diffstat (limited to 'nptl')
-rw-r--r--nptl/allocatestack.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/nptl/allocatestack.c b/nptl/allocatestack.c
index 219854f..755ace5 100644
--- a/nptl/allocatestack.c
+++ b/nptl/allocatestack.c
@@ -52,6 +52,13 @@
# define MAP_STACK 0
#endif
+/* On CHERI targets ensure the mmap returned capability has RW permissions. */
+#ifdef PROT_MAX
+# define PROT_MAX_RW PROT_MAX (PROT_READ | PROT_WRITE)
+#else
+# define PROT_MAX_RW 0
+#endif
+
/* Get a stack frame from the cache. We have to match by size since
some blocks might be too small or far too large. */
static struct pthread *
@@ -363,7 +370,8 @@ allocate_stack (const struct pthread_attr *attr, struct pthread **pdp,
/* If a guard page is required, avoid committing memory by first
allocate with PROT_NONE and then reserve with required permission
excluding the guard page. */
- mem = __mmap (NULL, size, (guardsize == 0) ? prot : PROT_NONE,
+ mem = __mmap (NULL, size,
+ (guardsize == 0) ? prot : PROT_NONE | PROT_MAX_RW,
MAP_PRIVATE | MAP_ANONYMOUS | MAP_STACK, -1, 0);
if (__glibc_unlikely (mem == MAP_FAILED))