]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
cheri: Fix capability permissions of PROT_NONE map in locarchive
authorSzabolcs Nagy <szabolcs.nagy@arm.com>
Tue, 25 Oct 2022 10:20:48 +0000 (11:20 +0100)
committerSzabolcs Nagy <szabolcs.nagy@arm.com>
Wed, 26 Oct 2022 14:39:59 +0000 (15:39 +0100)
locale/programs/locarchive.c

index eeb2fa6ffecd1dba1a31e3712999efb799df90be..81a980b60bf7299d77abd5c9fbfcd3c681f47a28 100644 (file)
@@ -84,6 +84,13 @@ static const char *locnames[] =
 /* Size of the reserved address space area.  */
 #define RESERVE_MMAP_SIZE      512 * 1024 * 1024
 
+/* 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
+
 /* To prepare for enlargements of the mmaped area reserve some address
    space.  On some machines, being a file mapping rather than an anonymous
    mapping affects the address selection.  So do this mapping from the
@@ -94,7 +101,8 @@ prepare_address_space (int fd, size_t total, size_t *reserved, int *xflags,
 {
   if (total < RESERVE_MMAP_SIZE)
     {
-      void *p = mmap64 (NULL, RESERVE_MMAP_SIZE, PROT_NONE, MAP_SHARED, fd, 0);
+      void *p = mmap64 (NULL, RESERVE_MMAP_SIZE,
+                       PROT_NONE | PROT_MAX_RW, MAP_SHARED, fd, 0);
       if (p != MAP_FAILED)
        {
          void *aligned_p = PTR_ALIGN_UP (p, MAP_FIXED_ALIGNMENT);