From patchwork Mon May 1 22:25:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fangrui Song X-Patchwork-Id: 13228390 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 442EDC77B73 for ; Mon, 1 May 2023 23:31:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:Message-ID: Mime-Version:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=sLCboVVDuiTjcOSjERnfUWge+uJJyaIoghMhvmGPV3M=; b=HbY 6vPRmhSzJbcbaV3Hb1s/agXA0ZJ/CGwaLLuBnmRwz9ETOaicrrkvM6T6eQa3HFrLGPPFSid6VxGb+ 6pqRBxZVTe5UNrDxQBgzI5HLFZCJaEODTuqeviUram/7XbXU4JuOmSv9CysSpt40vbodT7bgOEIGb 2S2+3Sy8mg1kcStW2R3XPw2KhmSw/z7UtV1QDg9HdpQQKQyTkxYOz2JOvq4+aS2GP83xmosN5iH1q dzPP8r7npFP/ARu5Rtajz5zp6I6l0Bv7gr2aK+D+J4To5oJVZuZC1K8DIxpHXA2OQLn2KotO+wz5E 5jHIpf711weqrg+t4wxnQlC0UCoVUnA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1ptcyU-00HBrr-33; Mon, 01 May 2023 23:30:30 +0000 Received: from mail-yb1-f201.google.com ([209.85.219.201]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1ptbxz-00H5Qu-2k for linux-arm-kernel@lists.infradead.org; Mon, 01 May 2023 22:25:57 +0000 Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-b9e2b65f2eeso1972927276.2 for ; Mon, 01 May 2023 15:25:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1682979954; x=1685571954; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=1BxhGqqIjMamiGADI4rmVFfxoo9kAM2Y8zr5TqlELr0=; b=U3MTB4tzWaoAeuLf7zTSo4Amq9ScioPloA+jQir4eqboGDJVyEgqL6DdVasMfZHsZg vBrehczzN1QTDBrGeQtOjR2w5eHKvycMGoOQXD/HWtb/lBc4NbvnS5An/1CbpglUq5qW SeAvFePY6ORF0a+vI3w3jbAKcvG5ZU5Zr2VElZ27XoWwdAvOUCBMnebjx9wV12CbMCCE ZE2aNA6Yye5kE6xtjIZ/PAWB3laZQjF1We1N2y0aGiJyGWJDDFeV9w3eRY8Z9/5nsH1u fJ+xc92EqXKQ9t/nvrZ6KoEflzOlDUJE2xukjZk/QYj71b51EMACkelg/5rJaWRwVJth 0q+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682979954; x=1685571954; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=1BxhGqqIjMamiGADI4rmVFfxoo9kAM2Y8zr5TqlELr0=; b=Uq+Efbs+dqYq0yj/tuOY5nNtu9UQEylHcIA2KoVG3odryMhSE2Y9/zPJSYysuRyBfS UKzrBwP4EIeCF8C42aVLJIC9zz1vbmKlAPcNjIhGXvGpZr7lY9TktQpGp3SwNvn36Za4 2232JQF0/7D0Fq5BEWT+he7coeagxzW1GiDhsYuys68+gLsQLKMKsFaJVCRlDzIBWKwK +mprassb6zRDWjnsriV9XL40i8uDC7DSoCTpoz57LdobRyBp2jonFm2TrQdcpQK4r8lK fQIIyCjqzkZQcbAUMVnjaMraj3BnMoveBZG1ZtSjo+OBJ2wnFsQ00BmrjTGwiubGSo8W 9jXA== X-Gm-Message-State: AC+VfDwQC/6Qd6XT/cgvPhgiD89qZ5Dsgw9bHHh/NaUt4lhLaozQ1tpP N+iNwqwvqkIIs7oU7+ublIbSQmDF7blN X-Google-Smtp-Source: ACHHUZ53guwu8TPGl5Urv7haX8BeewTLGvNppYh1wGDiEF7DNctu6QYxPwQXGekB2IEN6HmXnsYcxrmR94WS X-Received: from meowing-l.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:3eba]) (user=maskray job=sendgmr) by 2002:a05:6902:100e:b0:b8b:f584:6b73 with SMTP id w14-20020a056902100e00b00b8bf5846b73mr5947503ybt.10.1682979953813; Mon, 01 May 2023 15:25:53 -0700 (PDT) Date: Mon, 1 May 2023 22:25:51 +0000 Mime-Version: 1.0 Message-ID: <20230501222551.1254686-1-maskray@google.com> Subject: [PATCH v2] arm64: lds: move .got section out of .text From: Fangrui Song To: Catalin Marinas , Will Deacon , linux-arm-kernel@lists.infradead.org, Ard Biesheuvel Cc: linux-kernel@vger.kernel.org, Bill Wendling , Nick Desaulniers , Fangrui Song X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230501_152555_885954_97A47FE6 X-CRM114-Status: GOOD ( 14.10 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Currently, the .got section is placed within the output section .text. However, when .got is non-empty, the SHF_WRITE flag is set for .text when linked by lld. GNU ld recognizes .text as a special section and ignores the SHF_WRITE flag. By renaming .text, we can also get the SHF_WRITE flag. The kernel has performed R_AARCH64_RELATIVE resolving very early, and can then assume that .got is read-only. Let's move .got to the vmlinux_rodata pseudo-segment. The change avoids a section with both executable and writable permissions. Signed-off-by: Fangrui Song Reviewed-by: Ard Biesheuvel --- Changes from v1 (https://lore.kernel.org/lkml/20230428050442.180913-1-maskray@google.com/) * move .got to the vmlinux_rodata pseudo-segment as suggested by Ard Biesheuvel --- arch/arm64/kernel/vmlinux.lds.S | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/arch/arm64/kernel/vmlinux.lds.S b/arch/arm64/kernel/vmlinux.lds.S index b9202c2ee18e..3cd7e76cc562 100644 --- a/arch/arm64/kernel/vmlinux.lds.S +++ b/arch/arm64/kernel/vmlinux.lds.S @@ -181,10 +181,17 @@ SECTIONS KPROBES_TEXT HYPERVISOR_TEXT *(.gnu.warning) - . = ALIGN(16); - *(.got) /* Global offset table */ } + . = ALIGN(SEGMENT_ALIGN); + _etext = .; /* End of text section */ + + /* everything from this point to __init_begin will be marked RO NX */ + RO_DATA(PAGE_SIZE) + + HYPERVISOR_DATA_SECTIONS + + .got : { *(.got) } /* * Make sure that the .got.plt is either completely empty or it * contains only the lazy dispatch entries. @@ -193,14 +200,6 @@ SECTIONS ASSERT(SIZEOF(.got.plt) == 0 || SIZEOF(.got.plt) == 0x18, "Unexpected GOT/PLT entries detected!") - . = ALIGN(SEGMENT_ALIGN); - _etext = .; /* End of text section */ - - /* everything from this point to __init_begin will be marked RO NX */ - RO_DATA(PAGE_SIZE) - - HYPERVISOR_DATA_SECTIONS - /* code sections that are never executed via the kernel mapping */ .rodata.text : { TRAMP_TEXT