From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1944) id 2C4FC385117D; Wed, 12 Oct 2022 14:17:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2C4FC385117D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1665584221; bh=dZSAIY/6bOLJgoWtj/xwcE9wycUe+3EHRAS9PPnI1Pw=; h=From:To:Subject:Date:From; b=dNX7I/usNF2+uS8SELJCrS6qldHG5LhmcFnwmJIuAgow2wlqKNBK1/8XggF/CORbP 2XuaB/uk0ZCS4XM+cy8ZQMOe7O9LeOXBA0Xq0797GJpzkjgFM6OZEXhvqklP203msO D4R+xYX37dSIDCCNTenNP0nNYxZ/CoNEuxp3v6cI= 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] aarch64: morello: use RW and RX capabilities for static start code X-Act-Checkin: glibc X-Git-Author: Szabolcs Nagy X-Git-Refname: refs/heads/arm/morello/main X-Git-Oldrev: 8d2bab6e1795b5a2a6656a81e7419d6820a5d9cf X-Git-Newrev: bb624b6c4376d3b3a3c4fe3ed5d1cd6366fd3ac6 Message-Id: <20221012141701.2C4FC385117D@sourceware.org> Date: Wed, 12 Oct 2022 14:17:01 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=bb624b6c4376d3b3a3c4fe3ed5d1cd6366fd3ac6 commit bb624b6c4376d3b3a3c4fe3ed5d1cd6366fd3ac6 Author: Szabolcs Nagy Date: Tue Aug 30 16:00:57 2022 +0100 aarch64: morello: use RW and RX capabilities for static start code For each module there will be separate RW and RX capabilities that cover the writable and all load segments respectively. Prepare the relative reloc processing in static start code for such separate capabilities. Diff: --- sysdeps/aarch64/morello/cheri-rel.h | 16 ++++++++-------- sysdeps/aarch64/morello/start.c | 9 +++++---- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/sysdeps/aarch64/morello/cheri-rel.h b/sysdeps/aarch64/morello/cheri-rel.h index e5522cec08..91271f42d4 100644 --- a/sysdeps/aarch64/morello/cheri-rel.h +++ b/sysdeps/aarch64/morello/cheri-rel.h @@ -3,9 +3,8 @@ #include static inline uintptr_t -morello_relative (uintptr_t base, - const ElfW(Rela) *reloc, - void *reloc_addr) +morello_relative (uint64_t base, uintptr_t cap_rx, uintptr_t cap_rw, + const ElfW(Rela) *reloc, void *reloc_addr) { uint64_t *__attribute__((may_alias)) u64_reloc_addr = reloc_addr; @@ -16,7 +15,12 @@ morello_relative (uintptr_t base, unsigned long perm = u64_reloc_addr[1] >> 56; uintptr_t value; - value = base + loc; + /* Permissions field is encoded as: + 4 = executable, 2 = read/write, 1 = read-only. */ + if (perm == 2) + value = __builtin_cheri_address_set (cap_rw, base + loc); + else + value = __builtin_cheri_address_set (cap_rx, base + loc); value = __builtin_cheri_bounds_set_exact (value, len); @@ -24,10 +28,6 @@ morello_relative (uintptr_t base, if (perm == 1) value = __builtin_cheri_perms_and (value, CAP_PERM_MASK_R); - if (perm == 2) - value = __builtin_cheri_perms_and (value, CAP_PERM_MASK_RW); - if (perm == 4) - value = __builtin_cheri_perms_and (value, CAP_PERM_MASK_RX); /* Seal executable capabilities with MORELLO_RB. */ if (perm == 4) diff --git a/sysdeps/aarch64/morello/start.c b/sysdeps/aarch64/morello/start.c index dda9adb30e..fbc9512789 100644 --- a/sysdeps/aarch64/morello/start.c +++ b/sysdeps/aarch64/morello/start.c @@ -124,13 +124,14 @@ get_base (void) } static void -apply_rel (uintptr_t base, uintptr_t start, uintptr_t end) +apply_rel (uintptr_t cap_rx, uintptr_t cap_rw, uintptr_t start, uintptr_t end) { const ElfW(Rela) *r; for (r = (const ElfW(Rela) *)start; r != (void *)end; r++) { - uintptr_t *reloc_addr = base + r->r_offset; - uintptr_t value = morello_relative (base, r, reloc_addr); + uintptr_t *reloc_addr = + (uintptr_t *) __builtin_cheri_address_set (cap_rw, r->r_offset); + uintptr_t value = morello_relative (0, cap_rx, cap_rw, r, reloc_addr); *reloc_addr = value; } } @@ -151,7 +152,7 @@ __real_start (void rtld_fini (void), uintptr_t *sp) uintptr_t start = get_rela_dyn_start (); uintptr_t end = get_rela_dyn_end (); uintptr_t base = get_base (); - apply_rel (base, start, end); + apply_rel (base, base, start, end); rtld_fini = 0; } /* Compiler barrier after relocs are processed. */