]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
cheri: Fix capability permissions of PROT_NONE maps in test code
authorSzabolcs Nagy <szabolcs.nagy@arm.com>
Tue, 25 Oct 2022 08:14:46 +0000 (09:14 +0100)
committerSzabolcs Nagy <szabolcs.nagy@arm.com>
Thu, 27 Oct 2022 13:46:52 +0000 (14:46 +0100)
support/blob_repeat.c
support/support_stack_alloc.c
support/xunistd.h
sysdeps/unix/sysv/linux/tst-pkey.c

index 2c952906ea001905fb74856c59b4721f77cc3e17..5e5fecac00f0fb740d1027f85cf07300116fc7fc 100644 (file)
@@ -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 };
index 77115fceb138bdd83dc73afab53fad5ac4123653..c138c0d4f98c4edfc238f7e6db665179543427d7 100644 (file)
@@ -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
index 960a62d412986df324ebf5b913d6706804e56c45..2429424443e75a5bb3bff47094e53eeefde6b106 100644 (file)
@@ -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);
index df51f695bc94644b71a2c9ba38ceef98e49cc229..48b4308d639f144f4d5c466467133c81ed4d937f 100644 (file)
@@ -175,7 +175,7 @@ do_test (void)
   /* pkey_mprotect with key -1 should work even when there is no
      protection key support.  */
   {
-    int *page = xmmap (NULL, pagesize, PROT_NONE,
+    int *page = xmmap (NULL, pagesize, PROT_NONE | PROT_MAX_RW,
                        MAP_ANONYMOUS | MAP_PRIVATE, -1);
     TEST_COMPARE (pkey_mprotect (page, pagesize, PROT_READ | PROT_WRITE, -1),
                   0);