From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1944) id BEC3938460AB; Wed, 26 Oct 2022 15:18:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BEC3938460AB DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1666797517; bh=7IrlpN4HMpE1RJFFeixfUiig8Tjfhw7eaH8eSirmtqY=; h=From:To:Subject:Date:From; b=oTmGZdfjsQW3/h++XO1wBKx8M+O/HZZddzX4IrzdWUluSVVnPLBZyt8Fq3UMtSRZh VLRxyCRkxAWza3k+kUEMTLIb5eZbsIbtpeKkvUjbvNBCbt2IGwY7eaeHBk7BP0tWAf E9zz7IlMxQKJpGfqtTh7VG7wfOYSvBcFq4aR6DnQ= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Szabolcs Nagy To: glibc-cvs@sourceware.org Subject: [glibc/arm/morello/main] cheri: malloc: Ensure the mappings have RW permission X-Act-Checkin: glibc X-Git-Author: Szabolcs Nagy X-Git-Refname: refs/heads/arm/morello/main X-Git-Oldrev: 9e7e937778da85d4fafc05f521c860a3037da541 X-Git-Newrev: c892e3eded6fa01b8adcfc837a1bdeb3efcea0c7 Message-Id: <20221026151837.BEC3938460AB@sourceware.org> Date: Wed, 26 Oct 2022 15:18:37 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=c892e3eded6fa01b8adcfc837a1bdeb3efcea0c7 commit c892e3eded6fa01b8adcfc837a1bdeb3efcea0c7 Author: Szabolcs Nagy Date: Fri Oct 21 12:35:33 2022 +0100 cheri: malloc: Ensure the mappings have RW permission 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. Diff: --- malloc/malloc.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/malloc/malloc.c b/malloc/malloc.c index 02df29d2ad..701adbebca 100644 --- a/malloc/malloc.c +++ b/malloc/malloc.c @@ -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) /*