From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1944) id CA3713851148; Wed, 12 Oct 2022 14:17:46 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CA3713851148 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1665584266; bh=tS9dZt1xVWtQacNutIaljPv/wwkRJA3EDkQ3k5Vd2ng=; h=From:To:Subject:Date:From; b=MUd0GGD3KB8duqlj/4v9Nu1CkdglsCu4kr2RsVFRHLzBsNau9NppECQgAE329N+5T xBaYLvz39FIe+Pw/PrJ4Cac6ZO/arYdbAANA9CrT4h4PYYjs7YIvyODWUgBrBU9i6I evH9sTGJjFdqokZQp+M63tt0zqtRVJEvEKp3vBd0= 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: elf: Use RW permissions for l_ld when needed X-Act-Checkin: glibc X-Git-Author: Szabolcs Nagy X-Git-Refname: refs/heads/arm/morello/main X-Git-Oldrev: a1d26f7b1d8d78588c6fd301515a07f92883b150 X-Git-Newrev: e841326457b09c3d6af9634fe918a47d61113b04 Message-Id: <20221012141746.CA3713851148@sourceware.org> Date: Wed, 12 Oct 2022 14:17:46 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=e841326457b09c3d6af9634fe918a47d61113b04 commit e841326457b09c3d6af9634fe918a47d61113b04 Author: Szabolcs Nagy Date: Fri Sep 2 14:07:06 2022 +0100 cheri: elf: Use RW permissions for l_ld when needed The dynamic section of an executable needs to be written to set the DT_DEBUG entry for debuggers (unless the target has some other place to store r_debug). For this reason we make l_ld writable whenever the dynamic section is writable. The ld.so l_ld is kept RX, since it does not have DT_DEBUG. (Note: relocating the dynamic section is not allowed on cheri and that's the only other reason glibc would write to it.) Diff: --- elf/dl-load.c | 4 +++- elf/rtld.c | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/elf/dl-load.c b/elf/dl-load.c index 367b8cdab1..192ad4f7c9 100644 --- a/elf/dl-load.c +++ b/elf/dl-load.c @@ -1276,7 +1276,9 @@ _dl_map_object_from_fd (const char *name, const char *origname, int fd, } if (l->l_ld != 0) - l->l_ld = (ElfW(Dyn) *) ((ElfW(Addr)) l->l_ld + l->l_addr); + l->l_ld = (ElfW(Dyn) *) (l->l_ld_readonly + ? dl_rx_ptr (l, (elfptr_t) l->l_ld) + : dl_rw_ptr (l, (elfptr_t) l->l_ld)); elf_get_dynamic_info (l, false, false); diff --git a/elf/rtld.c b/elf/rtld.c index 007e938b90..fcb8b9e888 100644 --- a/elf/rtld.c +++ b/elf/rtld.c @@ -1181,8 +1181,10 @@ rtld_setup_main_map (struct link_map *main_map) case PT_DYNAMIC: /* This tells us where to find the dynamic section, which tells us everything we need to do. */ - main_map->l_ld = (void *) main_map->l_addr + ph->p_vaddr; main_map->l_ld_readonly = (ph->p_flags & PF_W) == 0; + main_map->l_ld = (void *) (main_map->l_ld_readonly + ? dl_rx_ptr (main_map, ph->p_vaddr) + : dl_rw_ptr (main_map, ph->p_vaddr)); break; case PT_INTERP: /* This "interpreter segment" was used by the program loader to