From: Szabolcs Nagy Date: Tue, 25 Oct 2022 10:20:48 +0000 (+0100) Subject: cheri: Fix capability permissions of PROT_NONE map in locarchive X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cef9089a6894ed882a403a64c9949d7e08eedca8;p=thirdparty%2Fglibc.git cheri: Fix capability permissions of PROT_NONE map in locarchive --- diff --git a/locale/programs/locarchive.c b/locale/programs/locarchive.c index eeb2fa6ffec..81a980b60bf 100644 --- a/locale/programs/locarchive.c +++ b/locale/programs/locarchive.c @@ -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);