]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
cheri: malloc: Ensure the mappings have RW permission
authorSzabolcs Nagy <szabolcs.nagy@arm.com>
Fri, 21 Oct 2022 11:35:33 +0000 (12:35 +0100)
committerSzabolcs Nagy <szabolcs.nagy@arm.com>
Thu, 27 Oct 2022 13:46:53 +0000 (14:46 +0100)
The arena allocator incrementally applies RW mprotect to a PROT_NONE
mapping.  Use PROT_MAX to ensure the pointers derived from the original
mapping have RW capability permission.

malloc/malloc.c

index 02df29d2ad8ab050d8e9f9f8a41d55278297baa6..701adbebca95507243d04deb438d682e3d937a70 100644 (file)
@@ -1134,8 +1134,16 @@ static mchunkptr mremap_chunk(mchunkptr p, size_t new_size);
 # define MAP_NORESERVE 0
 #endif
 
+/* Allow RW mprotect later, on CHERI this means RW capability permission.  */
+#ifdef PROT_MAX
+# define PROT_MAX_RW PROT_MAX (PROT_READ | PROT_WRITE)
+#else
+# define PROT_MAX_RW 0
+#endif
+
 #define MMAP(addr, size, prot, flags) \
- __mmap((addr), (size), (prot), (flags)|MAP_ANONYMOUS|MAP_PRIVATE, -1, 0)
+ __mmap((addr), (size), (prot)|PROT_MAX_RW, \
+       (flags)|MAP_ANONYMOUS|MAP_PRIVATE, -1, 0)
 
 
 /*