From patchwork Tue May 2 07:41:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fangrui Song X-Patchwork-Id: 13228553 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 DBD91C77B73 for ; Tue, 2 May 2023 07:42:27 +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=EZ13S9pfv99bF9/X8qDUtDEjJPqiHCNG/i8s3V7vHOE=; b=OVI XyvUaGOpkdrWDaJQ0VFaMezulCSbllSn6NqQA2nm6UVbUvifQFw5tYhrf6Unqxh25qNBv4P/PcQlr g6DIUibzDGNjq6lvAcgf11l/lvKFTLiPisM8x0RsLYWWqojTnhMKUMdrnmyF0pIhrst6EV41bNOMQ sK4GWzzDWiI8mgc0zx9JA4PNWE4NCmcrfs1PqUWbw+jzMGrAtfT5nqtn9ZjEs23wkASirxfUcJ5hj bP7FxztL3YKrhL/0KFYWBKk7jzMZEZ/0IE/DcIWOSZVJmaJGp/Coi2PFLxtRmOt17126MRRhNO5Rt sXiRrj/0nlIK62Fn2PGNn3ZCcyebWQg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1ptkdc-000Vuf-31; Tue, 02 May 2023 07:41:28 +0000 Received: from mail-pg1-x54a.google.com ([2607:f8b0:4864:20::54a]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1ptkdZ-000VtE-3C for linux-arm-kernel@lists.infradead.org; Tue, 02 May 2023 07:41:27 +0000 Received: by mail-pg1-x54a.google.com with SMTP id 41be03b00d2f7-52c3f0b1703so778641a12.1 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=e/s2/L5CmcjNdGwpcZzZq3RnhISTy3dHiTrJWTBqNv78ZnhljQnImnayFldT1cB4iJ eURWrG2i8oVyFW8x1DjAwsvYHIwqthkqYym8oVUQfoIvrVg81Wdybfk8cGEaBmQouDWk 0EZCWJh8CaDcoskSa1m749DIOYljGg2QLASXiijBwzojkihZbpS0c/9C//k2kvJbqO9i nc2Esh9YbuWGDFt98WgvdPUDwYy5/4tm1oIrEG95RKmru0z78CckIO5eAw2LNMaL8NJa 7XdTR4nzd0iOGEK0rOECZvMhNuyXZ6MU5vCIq2sIMrnOqz5aiLqabe1/sj56mAUqQotG koiQ== X-Gm-Message-State: AC+VfDzVlJV2iMKTxa1snsMZ9o04ecKYw1ZmVSk+1yapslXVf2Yxq5/P WDQq3iZJIi0KX8HZbBHAzZFUqSK20vnD 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230502_004126_032695_A08B0E0C X-CRM114-Status: GOOD ( 15.84 ) 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. 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-maskray@google.com/) * move .got to the vmlinux_rodata pseudo-segment as suggested by Ard Biesheuvel Changes from v2 (https://lore.kernel.org/r/all/20230501222551.1254686-1-maskray@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.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