From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2178) id 3BD7B385840D; Wed, 3 Nov 2021 09:59:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3BD7B385840D Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Florian Weimer To: glibc-cvs@sourceware.org Subject: [glibc/release/2.34/master] ld.so: Initialize bootstrap_map.l_ld_readonly [BZ #28340] X-Act-Checkin: glibc X-Git-Author: H.J. Lu X-Git-Refname: refs/heads/release/2.34/master X-Git-Oldrev: f42373f911a28d34325a5bfc1ed5a962c89da7eb X-Git-Newrev: 5f36e5c70107ecb59281ef57f9f1c0e37ec3076d Message-Id: <20211103095914.3BD7B385840D@sourceware.org> Date: Wed, 3 Nov 2021 09:59:14 +0000 (GMT) X-BeenThere: glibc-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Glibc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 03 Nov 2021 09:59:14 -0000 https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=5f36e5c70107ecb59281ef57f9f1c0e37ec3076d commit 5f36e5c70107ecb59281ef57f9f1c0e37ec3076d Author: H.J. Lu Date: Thu Sep 23 09:06:49 2021 -0700 ld.so: Initialize bootstrap_map.l_ld_readonly [BZ #28340] 1. Define DL_RO_DYN_SECTION to initalize bootstrap_map.l_ld_readonly before calling elf_get_dynamic_info to get dynamic info in bootstrap_map, 2. Define a single static inline bool dl_relocate_ld (const struct link_map *l) { /* Don't relocate dynamic section if it is readonly */ return !(l->l_ld_readonly || DL_RO_DYN_SECTION); } This updates BZ #28340 fix. (cherry picked from commit 2ec99d8c42b2ff1a1231e4df462a0910a9b7fdef) Diff: --- elf/rtld.c | 1 + sysdeps/generic/dl-relocate-ld.h | 11 ++--------- sysdeps/generic/ldsodefs.h | 10 ++++++++++ sysdeps/mips/dl-relocate-ld.h | 11 ++--------- sysdeps/riscv/dl-relocate-ld.h | 11 ++--------- 5 files changed, 17 insertions(+), 27 deletions(-) diff --git a/elf/rtld.c b/elf/rtld.c index 405166d62b..d83ac1bdc4 100644 --- a/elf/rtld.c +++ b/elf/rtld.c @@ -548,6 +548,7 @@ _dl_start (void *arg) /* Read our own dynamic section and fill in the info array. */ bootstrap_map.l_ld = (void *) bootstrap_map.l_addr + elf_machine_dynamic (); + bootstrap_map.l_ld_readonly = DL_RO_DYN_SECTION; elf_get_dynamic_info (&bootstrap_map); #if NO_TLS_OFFSET != 0 diff --git a/sysdeps/generic/dl-relocate-ld.h b/sysdeps/generic/dl-relocate-ld.h index 5fae206db9..cfb86c2d6a 100644 --- a/sysdeps/generic/dl-relocate-ld.h +++ b/sysdeps/generic/dl-relocate-ld.h @@ -19,14 +19,7 @@ #ifndef _DL_RELOCATE_LD_H #define _DL_RELOCATE_LD_H -/* Return true if dynamic section in the shared library L should be - relocated. */ - -static inline bool -dl_relocate_ld (const struct link_map *l) -{ - /* Don't relocate dynamic section if it is readonly */ - return !l->l_ld_readonly; -} +/* The dynamic section is writable. */ +#define DL_RO_DYN_SECTION 0 #endif /* _DL_RELOCATE_LD_H */ diff --git a/sysdeps/generic/ldsodefs.h b/sysdeps/generic/ldsodefs.h index ed10953f34..fcbbf69748 100644 --- a/sysdeps/generic/ldsodefs.h +++ b/sysdeps/generic/ldsodefs.h @@ -69,6 +69,16 @@ __BEGIN_DECLS `ElfW(TYPE)' is used in place of `Elf32_TYPE' or `Elf64_TYPE'. */ #define ELFW(type) _ElfW (ELF, __ELF_NATIVE_CLASS, type) +/* Return true if dynamic section in the shared library L should be + relocated. */ + +static inline bool +dl_relocate_ld (const struct link_map *l) +{ + /* Don't relocate dynamic section if it is readonly */ + return !(l->l_ld_readonly || DL_RO_DYN_SECTION); +} + /* All references to the value of l_info[DT_PLTGOT], l_info[DT_STRTAB], l_info[DT_SYMTAB], l_info[DT_RELA], l_info[DT_REL], l_info[DT_JMPREL], and l_info[VERSYMIDX (DT_VERSYM)] diff --git a/sysdeps/mips/dl-relocate-ld.h b/sysdeps/mips/dl-relocate-ld.h index 0c18d9a567..376ad75dd1 100644 --- a/sysdeps/mips/dl-relocate-ld.h +++ b/sysdeps/mips/dl-relocate-ld.h @@ -19,14 +19,7 @@ #ifndef _DL_RELOCATE_LD_H #define _DL_RELOCATE_LD_H -/* Return true if dynamic section in the shared library L should be - relocated. */ - -static inline bool -dl_relocate_ld (const struct link_map *l) -{ - /* Never relocate dynamic section. */ - return false; -} +/* The dynamic section is readonly. */ +#define DL_RO_DYN_SECTION 1 #endif /* _DL_RELOCATE_LD_H */ diff --git a/sysdeps/riscv/dl-relocate-ld.h b/sysdeps/riscv/dl-relocate-ld.h index 10327454b1..2ab2b8ac6c 100644 --- a/sysdeps/riscv/dl-relocate-ld.h +++ b/sysdeps/riscv/dl-relocate-ld.h @@ -19,14 +19,7 @@ #ifndef _DL_RELOCATE_LD_H #define _DL_RELOCATE_LD_H -/* Return true if dynamic section in the shared library L should be - relocated. */ - -static inline bool -dl_relocate_ld (const struct link_map *l) -{ - /* Never relocate dynamic section for ABI compatibility. */ - return false; -} +/* The dynamic section is readonly for ABI compatibility. */ +#define DL_RO_DYN_SECTION 1 #endif /* _DL_RELOCATE_LD_H */