From nobody Thu Dec 18 19:43:32 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0674CC77B7E for ; Tue, 2 May 2023 07:41:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233401AbjEBHl2 (ORCPT ); Tue, 2 May 2023 03:41:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45564 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233167AbjEBHlZ (ORCPT ); Tue, 2 May 2023 03:41:25 -0400 Received: from mail-pg1-x54a.google.com (mail-pg1-x54a.google.com [IPv6:2607:f8b0:4864:20::54a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 377C3E7A for ; Tue, 2 May 2023 00:41:24 -0700 (PDT) Received: by mail-pg1-x54a.google.com with SMTP id 41be03b00d2f7-517bad1b8c5so3366675a12.0 for ; Tue, 02 May 2023 00:41:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1683013283; x=1685605283; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=4L2V9c4CmIAtK3KFjaBFh5H6J9gLqid7KK9E18ZFAsY=; b=buBabAKCzebIEoI0YvCo/l96UaflEhqn7hv/Q+Mi/cHHkpKuMH0Zue5iWzUfOvn8NO nRXOxjpEY2DKW/iQu/tT8mHID+TnbtSuBLqkFH5xRdG6gru0Bzxzdu+w89s8WKBOLbmb Dq1iqiiNlFtmVJ2xg8wW7u4SKG4d00ZG+BM2kwgZYuQLsS8NO2Yr3MIPRngr5/gDJDGy bpt1UiH99ZsnByKISJ8HsyQMGDth2eUZfWGmNK/SppducYy3c/GVWh3SyUPAp6lHEJHK oo3t1xDNKvK464q2aDg8tbbNtbnbfr4Nq9wcoZq2CNNMz4FC2odazqaEAxy2vYzGnHk4 AcbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683013283; x=1685605283; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=4L2V9c4CmIAtK3KFjaBFh5H6J9gLqid7KK9E18ZFAsY=; b=FaVAUCN1GC/r5s9Pr8WfCC0+r5hHKGQ1+HPyYEhFOZZc9VwoFlfCZBlWYeTXPkAx0+ XpwM0ErBr4pox4NNNeMmd6KvxEeUEbvSBKENC/jgfREhUzdfiN8wRVfYIZV+hlzauX1Q 8D+htaoLCN2lRvRc5eD2nUfgCuSJ2qIZVLz3vGSwBc/mZDnJH1a+KRXbw7K5DARa6UJR goYVl870nKDKyxL80+Afh46IFdNtPr7BKTBw3j6iC/bx6pOBpZGrvAIecygrkLBKOXQA iM+kiLaPhOXSlwD3M3TpMRTupFFmwl7idpcx3F7rh8axnV1hbhf2XT6C+Uuj0qPmZdB+ CVSA== X-Gm-Message-State: AC+VfDyIR7Hs/bbl+G4XkK0QmOCUzbepFyciy5ajHRT10uyyz/hhxDZJ rGrWwwLazRBJARSPfa/cEMLkSGaJyimS X-Google-Smtp-Source: ACHHUZ6N4sXR/rmHOtONduuauPYGhL1OTBsYWaPVnhILOdVwKsdHmT9krrtc3mSlv0Y81sha5+9tXNDH73S1 X-Received: from meowing-l.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:3eba]) (user=maskray job=sendgmr) by 2002:a63:2a0d:0:b0:528:9f8f:1b92 with SMTP id q13-20020a632a0d000000b005289f8f1b92mr4016671pgq.4.1683013283612; Tue, 02 May 2023 00:41:23 -0700 (PDT) Date: Tue, 2 May 2023 07:41:05 +0000 Mime-Version: 1.0 Message-ID: <20230502074105.1541926-1-maskray@google.com> Subject: [PATCH v3] 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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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. As Ard Biesheuvel notes: "This matters to consumers of the vmlinux ELF representation of the kernel image, such as syzkaller, which disregards writable PT_LOAD segments when resolving code symbols. The kernel itself does not care about this distinction, but given that the GOT contains data and not code, it does not require executable permissions, and therefore does not belong in .text to begin with." Signed-off-by: Fangrui Song Reviewed-by: Ard Biesheuvel -- Changes from v1 (https://lore.kernel.org/lkml/20230428050442.180913-1-maskr= ay@google.com/) * move .got to the vmlinux_rodata pseudo-segment as suggested by Ard Bieshe= uvel Changes from v2 (https://lore.kernel.org/r/all/20230501222551.1254686-1-mas= kray@google.com/) * add Ard Biesheuvel's Reviewed-by tag and addition to the commit message. --- 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.ld= s.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) - . =3D ALIGN(16); - *(.got) /* Global offset table */ } =20 + . =3D ALIGN(SEGMENT_ALIGN); + _etext =3D .; /* 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) =3D=3D 0 || SIZEOF(.got.plt) =3D=3D 0x18, "Unexpected GOT/PLT entries detected!") =20 - . =3D ALIGN(SEGMENT_ALIGN); - _etext =3D .; /* 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 --=20 2.40.1.495.gc816e09b53d-goog