]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
TODO(uapi): mmap perm emulation
authorSzabolcs Nagy <szabolcs.nagy@arm.com>
Mon, 24 Oct 2022 14:29:58 +0000 (15:29 +0100)
committerSzabolcs Nagy <szabolcs.nagy@arm.com>
Wed, 26 Oct 2022 14:32:01 +0000 (15:32 +0100)
sysdeps/unix/sysv/linux/mmap64.c

index 60da02939d7dd6d0a4de626be3bb9b2b20819e86..a7bd3968805a50ec9564bcc7e7ec732062a46ab4 100644 (file)
@@ -22,6 +22,9 @@
 #include <sysdep.h>
 #include <ldsodefs.h>
 #include <mmap_internal.h>
+#ifdef __CHERI_PURE_CAPABILITY__
+# include <cheri_perms.h>
+#endif
 
 #ifdef __NR_mmap2
 /* To avoid silent truncation of offset when using mmap2, do not accept
@@ -64,6 +67,20 @@ __mmap64 (void *addr, size_t len, int prot, int flags, int fd, off64_t offset)
     {
       size_t ps = GLRO(dl_pagesize);
       ret = __builtin_cheri_bounds_set (ret, (len + ps - 1) & -ps);
+      unsigned long mask = CAP_PERM_MASK_BASE;
+      if (prot & PROT_READ)
+       mask |= CAP_PERM_MASK_R;
+      if (prot & PROT_WRITE)
+       mask |= CAP_PERM_MASK_RW;
+      if (prot & PROT_EXEC)
+       mask |= CAP_PERM_MASK_RX;
+      if (prot & PROT_MAX (PROT_READ))
+       mask |= CAP_PERM_MASK_R;
+      if (prot & PROT_MAX (PROT_WRITE))
+       mask |= CAP_PERM_MASK_RW;
+      if (prot & PROT_MAX (PROT_EXEC))
+       mask |= CAP_PERM_MASK_RX;
+      ret = __builtin_cheri_perms_and (ret, mask);
     }
 #endif
   return ret;