]> 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>
Wed, 26 Oct 2022 14:32:01 +0000 (15:32 +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 cc222eaba2fd21ddcbb42cef640c698b5060c67f..392116a5ac91d1300c181178bb5435c09d2d0815 100644 (file)
@@ -1284,8 +1284,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)
 
 
 /*