From patchwork Tue Sep 28 15:47:54 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: 45506 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 82B243858421 for ; Tue, 28 Sep 2021 15:48:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 82B243858421 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1632844110; bh=5DFvIQrBT6d5N2SlUAMnya8R7lPa6SmpoF5Y2TBsXK8=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=qgQid9VSnNBA1uGbc1WhlDo5BZ5oiLuBp1BOncz3bRTDzDMl9c75Ql38reM80Q1Gd tYr1ar0qMD6ru7UkUkbT/aZEEpk/ZaYJ3DX1V2sz1p9/QMXrqUlHJl/FgxDfZF0yf6 lk0UepQEWa+VjyoOHjBNnzYsYcRBBtCWiipDVP+U= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pj1-x1036.google.com (mail-pj1-x1036.google.com [IPv6:2607:f8b0:4864:20::1036]) by sourceware.org (Postfix) with ESMTPS id 0DA203858408 for ; Tue, 28 Sep 2021 15:48:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 0DA203858408 Received: by mail-pj1-x1036.google.com with SMTP id om12-20020a17090b3a8c00b0019eff43daf5so3147480pjb.4 for ; Tue, 28 Sep 2021 08:48:05 -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=5DFvIQrBT6d5N2SlUAMnya8R7lPa6SmpoF5Y2TBsXK8=; b=T3YTRdlw8PEXfu4sRfzuhLHmviHyQoFmxLbCxekZtUdIuEcpyq3Z+wDBdyFv8wb+O6 866wtHHN2lsiLdtPfjRhPSwdIIUgHoHCSO4Il/p+KNtcg1Y4MdXgdypLct41k9a4tDwl wgDWSBVE5oigkp0Zv7nZucyemnAkHIPqf+qXVNpLxK28WYNjhgWJWVKt2TSq/vc8+s+V TYow2WPBI8cC0TIrWncs91zzLe2JpFLiU8QGOCQ0XyQoXLrG7gqTxXlQZQQTMEOTkbO1 WB3bgghfd26nDyHuVpvoOhcIpOknsjUKnE96vvBKyzo5qbvYuNgUwiFNsHZgLl8wPA1X 6ONw== X-Gm-Message-State: AOAM531TsyKcjMdr//n+mNbP/pYeJjTSvy3ZzaKd/E5WhQNmJ1UYM1xC jWXwbEXMHQfVq3OzBglQRLOScViy474= X-Google-Smtp-Source: ABdhPJzDR431z1rk0Ph6fpb+dNNa9UVXvWu2TWS4ISXY3PTBhpdO2YFcCaKCIngSHmVVb8WFsyNljQ== X-Received: by 2002:a17:90a:9912:: with SMTP id b18mr741533pjp.46.1632844084055; Tue, 28 Sep 2021 08:48:04 -0700 (PDT) Received: from gnu-gram-1.localdomain (cpe-76-173-15-247.hawaii.res.rr.com. [76.173.15.247]) by smtp.gmail.com with ESMTPSA id w9sm3038778pjk.28.2021.09.28.08.48.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Sep 2021 08:48:03 -0700 (PDT) Received: from gnu-gram-1.localdomain (localhost [IPv6:::1]) by gnu-gram-1.localdomain (Postfix) with ESMTP id 8FCBFE0072; Tue, 28 Sep 2021 08:48:01 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH v2] ld.so: Initialize bootstrap_map.l_ld_readonly [BZ #28340] Date: Tue, 28 Sep 2021 08:47:54 -0700 Message-Id: <20210928154754.1485726-1-hjl.tools@gmail.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-Spam-Status: No, score=-3032.3 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" Cc: Florian Weimer 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 8d2bba3d43..83adf1c5f5 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); #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 d49529da0d..668383ab80 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 */