From patchwork Mon Oct 18 18:35:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 46360 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BC4183858437 for ; Mon, 18 Oct 2021 18:36:03 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BC4183858437 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1634582163; bh=O94feyzaO5Y2elXP5yRfQsAVLdzI6y0myMK8fJs0mUI=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=Ahy42ECHBhfWG+DPOLeoLUSxYIS8d779cAsD5MScSprvbyxtcs1pEUf/cVPG0e7bF 7li2piSRbvWro6bP6Bucl69LHTS6RjPkEP/Rvm1hAX0etzOK31rcsZpL6f0PLOvEgi 5OjFhDSmg4umNCNXXM9hCq4t70eEMMVDKSwXkM+o= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pg1-x52f.google.com (mail-pg1-x52f.google.com [IPv6:2607:f8b0:4864:20::52f]) by sourceware.org (Postfix) with ESMTPS id D154E3858C60 for ; Mon, 18 Oct 2021 18:35:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org D154E3858C60 Received: by mail-pg1-x52f.google.com with SMTP id m21so17028492pgu.13 for ; Mon, 18 Oct 2021 11:35:40 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=O94feyzaO5Y2elXP5yRfQsAVLdzI6y0myMK8fJs0mUI=; b=4J9UXO8xRNKzwBOzIN2Wrl6NV92dHFPCEpxFKApg61qHhwvKuqclUW4XJHtcBlB+4X oswfHwSpvzfOHCI/d3+cnDVwPS0L4CnpY9o+ghDGqwXhOHfm9On/MMKkO9EfCi5Y0kRt IseYx31jxkAIXsUleqlPSTyqB2LG6aTW1KH5GF4QbOpiT6zOdIftA6pKT0VLSGMsXFc9 YFHmEsTpED1YFLfq3WP+Pioyyof/Xxa4zXmsrH8HPGBD15YTbdymopu8dwW5CndQCCuA n4iWhLL/YuAji7np2s45Ed6sRLoj4+AMArXOQh7PPYgiQFs/Os3RA2PM9t7ZuiCfYozV B0Iw== X-Gm-Message-State: AOAM5332HjnREUcCP5oGdwdwnpy0KnemiYldLuDKBe3yaFjQJRZ9jPKc SjI/sA6PB/HnJLsQoLlFf3Q9d4DixOU= X-Google-Smtp-Source: ABdhPJw/2JkJhIsopkC6uZovXQJP+vtQafXkbz4qHW4nxE9325wu4lJfY7loX9rIgny69msJ1lnZow== X-Received: by 2002:a62:d11e:0:b0:446:d705:7175 with SMTP id z30-20020a62d11e000000b00446d7057175mr30879990pfg.74.1634582139568; Mon, 18 Oct 2021 11:35:39 -0700 (PDT) Received: from gnu-cfl-2.localdomain ([2607:fb90:a48a:adf1:e15a:7fe6:0:c66]) by smtp.gmail.com with ESMTPSA id b19sm3772120pgs.33.2021.10.18.11.35.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Oct 2021 11:35:39 -0700 (PDT) Received: from gnu-cfl-2.lan (localhost [IPv6:::1]) by gnu-cfl-2.localdomain (Postfix) with ESMTP id 3CE4B1A044C; Mon, 18 Oct 2021 11:35:38 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH v4] ld.so: Initialize bootstrap_map.l_ld_readonly [BZ #28340] Date: Mon, 18 Oct 2021 11:35:38 -0700 Message-Id: <20211018183538.3981830-1-hjl.tools@gmail.com> X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 X-Spam-Status: No, score=-3032.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: "H.J. Lu via Libc-alpha" From: "H.J. Lu" Reply-To: "H.J. Lu" Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" 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. --- 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 c66a1d00bc..b8ba2d8836 100644 --- a/elf/rtld.c +++ b/elf/rtld.c @@ -547,6 +547,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, true, false); #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 9ec1511bb0..0410f777a6 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 */