]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
cheri: nptl: Fix thread stack capability permissions
authorSzabolcs Nagy <szabolcs.nagy@arm.com>
Mon, 24 Oct 2022 15:18:42 +0000 (16:18 +0100)
committerSzabolcs Nagy <szabolcs.nagy@arm.com>
Thu, 27 Oct 2022 13:46:52 +0000 (14:46 +0100)
nptl/allocatestack.c

index 219854f2cb5a78365a25b56155d5a7eb47fb8d59..755ace5ec4c21847e7ac75e8c2a49fc1eab34441 100644 (file)
 # 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))