about summary refs log tree commit diff
path: root/support
diff options
context:
space:
mode:
authorSzabolcs Nagy <szabolcs.nagy@arm.com>2022-10-25 09:14:46 +0100
committerSzabolcs Nagy <szabolcs.nagy@arm.com>2022-11-22 14:31:25 +0000
commit8f6565fa273e95dfedf84366629e815f759d3f76 (patch)
treea12dfcd56f17da51f4d340d7f7d874f8de60d436 /support
parent8e860da0db41471ac5a4c68b4838308c13ba5f41 (diff)
downloadglibc-8f6565fa273e95dfedf84366629e815f759d3f76.tar.gz
glibc-8f6565fa273e95dfedf84366629e815f759d3f76.tar.xz
glibc-8f6565fa273e95dfedf84366629e815f759d3f76.zip
cheri: Fix capability permissions of PROT_NONE maps in test code
Diffstat (limited to 'support')
-rw-r--r--support/blob_repeat.c2
-rw-r--r--support/support_stack_alloc.c2
-rw-r--r--support/xunistd.h8
3 files changed, 10 insertions, 2 deletions
diff --git a/support/blob_repeat.c b/support/blob_repeat.c
index 2c952906ea..5e5fecac00 100644
--- a/support/blob_repeat.c
+++ b/support/blob_repeat.c
@@ -151,7 +151,7 @@ allocate_big (size_t total_size, const void *element, size_t element_size,
 
   /* Reserve the memory region.  If we cannot create the mapping,
      there is no reason to set up the backing file.  */
-  void *target = mmap (NULL, total_size, PROT_NONE,
+  void *target = mmap (NULL, total_size, PROT_NONE | PROT_MAX_RW,
                        MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
   if (target == MAP_FAILED)
     return (struct support_blob_repeat) { 0 };
diff --git a/support/support_stack_alloc.c b/support/support_stack_alloc.c
index 77115fceb1..c138c0d4f9 100644
--- a/support/support_stack_alloc.c
+++ b/support/support_stack_alloc.c
@@ -60,7 +60,7 @@ support_stack_alloc (size_t size)
      so we know they are allocated.  */
   void *alloc_base = xmmap (0,
                             alloc_size,
-                            PROT_NONE,
+                            PROT_NONE|PROT_MAX_RW,
                             MAP_PRIVATE|MAP_ANONYMOUS|MAP_NORESERVE|MAP_STACK,
                             -1);
   /* Some architecture still requires executable stack for the signal return
diff --git a/support/xunistd.h b/support/xunistd.h
index 960a62d412..2429424443 100644
--- a/support/xunistd.h
+++ b/support/xunistd.h
@@ -25,6 +25,7 @@
 #include <sys/cdefs.h>
 #include <sys/types.h>
 #include <sys/stat.h>
+#include <sys/mman.h>
 #include <unistd.h>
 
 __BEGIN_DECLS
@@ -77,6 +78,13 @@ void xclose (int);
 /* Write the buffer.  Retry on short writes.  */
 void xwrite (int, const void *, size_t);
 
+/* 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
+
 /* Invoke mmap with a zero file offset.  */
 void *xmmap (void *addr, size_t length, int prot, int flags, int fd);
 void xmprotect (void *addr, size_t length, int prot);