From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-23.2 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8F35AC2BB40 for ; Mon, 14 Dec 2020 21:52:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5CD3622262 for ; Mon, 14 Dec 2020 21:52:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2441136AbgLNVpQ (ORCPT ); Mon, 14 Dec 2020 16:45:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56750 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2441034AbgLNVo6 (ORCPT ); Mon, 14 Dec 2020 16:44:58 -0500 Received: from mail-pf1-x444.google.com (mail-pf1-x444.google.com [IPv6:2607:f8b0:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A2C8CC061793 for ; Mon, 14 Dec 2020 13:44:18 -0800 (PST) Received: by mail-pf1-x444.google.com with SMTP id q22so13037045pfk.12 for ; Mon, 14 Dec 2020 13:44:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=6EWmrppepC6CHcBZOqhjNztvHasoofk8FBuQ7CK72Yo=; b=mlBDwaeR5EuT6thidly4obxEYWArXsfs8EmBKFKvYaUpY1DmcjmF+VaqtG4iTHINT7 FCF4QnHO0zFmQGeRNsOnf9aLmv0PgPgM62Yiq5xdZxNZ55Oo4kUVltzD7qWaf3M3O/L4 D0JItD3kQic9c8ZP/u2MlOvD+RaeHKs8561wd3mGt1txmrGnkQCy12wzgpOqqd2kxDw+ +T4eRRkuhC4NJbRoLJq7alsoh+TwbAVMbKSPRMWVX28HMsXdeFKXUyJwNXnrqGDvAS0p oJFC5Tq8Q64l74jlOjiJWeTDfSYUHNDbT/uG7iZqCZ4COqrasq0kWFLb7//kPGEK7DNN tvwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=6EWmrppepC6CHcBZOqhjNztvHasoofk8FBuQ7CK72Yo=; b=TSTZKwx3LiyypQWQzzSpXArK90FlaTfyC92Agyjq5JMuHzEKYgovmU2K8ZxhyjILsg Y5Qs1zCi/kDP6KZ5s8aWWrBL4FnJLfwsbjVIA1c55SOeh0uVmClBYnK8f+Imuuh0oSTu ZUJTQg2lv8OhK+SgwIneG16tiR+g6UY/Hn0JCEkv0KgaEEe4fGkE8GxKUQJjDpteMK1d M7/IE+yDU3La5/dOvWgRbVSKy7tXkwiLncbLeLyNOEHRT01g+nnmZWXZP1atmaaUTWss LLe51pg8as0f6W5hFm7JgeNu6BMmiJVWIj1TsdAoiowWbvkbVdJzcIieDXZQlG78xYwT YJyA== X-Gm-Message-State: AOAM5329bEyJnmFZISpFDL/Rs7jvnnYG0x/i8wFjBQf93YgyiRU2OfYt ZanoLPQxPz4FjnrdddFmGbMQAo6eZBM5DFaWYKkSMA== X-Google-Smtp-Source: ABdhPJz0JzYkf4G+e7/8YeB0Xj41+fXETTPGT4aAt+KsRx0P/0WfwpiHwW5NxVnrsiyY7ZkKS7H3cI1Y6xqq+O4xRgY= X-Received: by 2002:a62:7c4a:0:b029:19d:b7bc:2c51 with SMTP id x71-20020a627c4a0000b029019db7bc2c51mr26329699pfc.30.1607982257943; Mon, 14 Dec 2020 13:44:17 -0800 (PST) MIME-Version: 1.0 References: <20201016175339.2429280-1-ndesaulniers@google.com> <160319373854.2175971.17968938488121846972.b4-ty@kernel.org> In-Reply-To: <160319373854.2175971.17968938488121846972.b4-ty@kernel.org> From: Nick Desaulniers Date: Mon, 14 Dec 2020 13:44:06 -0800 Message-ID: Subject: Re: [PATCH] arm64: link with -z norelro regardless of CONFIG_RELOCATABLE To: Alan Modra Cc: Catalin Marinas , kernel-team , Will Deacon , LKML , Peter Smith , clang-built-linux , "# 3.4.x" , Linux ARM , Ard Biesheuvel , =?UTF-8?B?RsSBbmctcnXDrCBTw7JuZw==?= , Quentin Perret Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Oct 20, 2020 at 10:57 AM Will Deacon wrote: > > On Fri, 16 Oct 2020 10:53:39 -0700, Nick Desaulniers wrote: > > With CONFIG_EXPERT=y, CONFIG_KASAN=y, CONFIG_RANDOMIZE_BASE=n, > > CONFIG_RELOCATABLE=n, we observe the following failure when trying to > > link the kernel image with LD=ld.lld: > > > > error: section: .exit.data is not contiguous with other relro sections > > > > ld.lld defaults to -z relro while ld.bfd defaults to -z norelro. This > > was previously fixed, but only for CONFIG_RELOCATABLE=y. > > Applied to arm64 (for-next/core), thanks! > > [1/1] arm64: link with -z norelro regardless of CONFIG_RELOCATABLE > https://git.kernel.org/arm64/c/3b92fa7485eb It looks like this is now producing warnings when linking with BFD. $ make ... ... LD .tmp_vmlinux.kallsyms1 aarch64-linux-gnu-ld: warning: -z norelro ignored KSYMS .tmp_vmlinux.kallsyms1.S AS .tmp_vmlinux.kallsyms1.S LD .tmp_vmlinux.kallsyms2 aarch64-linux-gnu-ld: warning: -z norelro ignored KSYMS .tmp_vmlinux.kallsyms2.S AS .tmp_vmlinux.kallsyms2.S LD vmlinux aarch64-linux-gnu-ld: warning: -z norelro ignored Alan, looking at binutils-gdb commit 5fd104addfddb ("Emit a warning when -z relro is unsupported") mentions targets lacking relro support will produce this warning. I thought aarch64 supports relro though...? Looks like we're invoking: + aarch64-linux-gnu-ld -EL -maarch64elf --no-undefined -X -z norelro -shared -Bsymbolic -z notext --no-apply-dynamic-relocs --fix-cortex-a53-843419 --build-id=sha1 --orphan-handling=warn --strip-debug -o .tmp_vmlinux.kallsyms1 -T ./arch/arm64/kernel/vmlinux.lds --whole-archive arch/arm64/kernel/head.o init/built-in.a usr/built-in.a arch/arm64/built-in.a kernel/built-in.a certs/built-in.a mm/built-in.a fs/built-in.a ipc/built-in.a security/built-in.a crypto/built-in.a block/built-in.a arch/arm64/lib/built-in.a lib/built-in.a arch/arm64/lib/lib.a lib/lib.a drivers/built-in.a sound/built-in.a net/built-in.a virt/built-in.a --no-whole-archive --start-group ./drivers/firmware/efi/libstub/lib.a --end-group aarch64-linux-gnu-ld: warning: -z norelro ignored So we set the emulation mode via -maarch64elf, and our preprocessed linker script has `OUTPUT_ARCH(aarch64)`. From that commit, there's a linked mailing list discussion: https://sourceware.org/legacy-ml/binutils/2017-01/msg00441.html Is there something more we need to do to our linker script (https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/arm64/kernel/vmlinux.lds.S) for BFD not to warn when passing `-z norelro`? It looks like common page size might need to be specified? I tried: diff --git a/arch/arm64/kernel/vmlinux.lds.S b/arch/arm64/kernel/vmlinux.lds.S index 1bda604f4c70..ae8cce140fdf 100644 --- a/arch/arm64/kernel/vmlinux.lds.S +++ b/arch/arm64/kernel/vmlinux.lds.S @@ -121,7 +121,7 @@ SECTIONS _text = .; HEAD_TEXT } - .text : { /* Real text segment */ + .text ALIGN (CONSTANT (COMMONPAGESIZE)): { /* Real text segment */ and passing `-z common-page-size=4096` but neither seemed to do the trick. (https://docs.adacore.com/live/wave/binutils-stable/html/ld/ld.html#index-COMMONPAGESIZE-553 Worst case, we add `-z norelro` just for LLD: diff --git a/arch/arm64/Makefile b/arch/arm64/Makefile index 6a87d592bd00..6a6235e1e8a9 100644 --- a/arch/arm64/Makefile +++ b/arch/arm64/Makefile @@ -10,7 +10,7 @@ # # Copyright (C) 1995-2001 by Russell King -LDFLAGS_vmlinux :=--no-undefined -X -z norelro +LDFLAGS_vmlinux :=--no-undefined -X ifeq ($(CONFIG_RELOCATABLE), y) # Pass --no-apply-dynamic-relocs to restore pre-binutils-2.27 behaviour @@ -28,6 +28,10 @@ LDFLAGS_vmlinux += --fix-cortex-a53-843419 endif endif +ifeq ($(CONFIG_LD_IS_LLD), y) +LDFLAGS_vmlinux += -z norelro +endif + ifeq ($(CONFIG_ARM64_USE_LSE_ATOMICS), y) ifneq ($(CONFIG_ARM64_LSE_ATOMICS), y) $(warning LSE atomics not supported by binutils) -- Thanks, ~Nick Desaulniers From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EE3E0C4361B for ; Mon, 14 Dec 2020 21:45:56 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 8533420738 for ; Mon, 14 Dec 2020 21:45:56 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8533420738 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:To:Subject:Message-ID:Date:From:In-Reply-To: References:MIME-Version:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=IcEOGchpiV8MvfAss2ofi2Fwg9wX4hHHtHATwcGG0lM=; b=C5BwR1b0rIyTN8LkjA/KiSwNE mzHRWhh67/K7eCcAWfmHQJJls/fr6V/PeLhlxNXtuR9UUT9RBLxwE04CpbekxB3nOYvTRNOMwgIi/ t+ovUJOWjtwfBmWNOwIUT663Cmo5cPToTj05g81mk50sN9rfn/Wt8ved6eQFiKJRjUq0cQQHQMrAq jBU+ROQi40IIUkxufkvebdB2BMFplxgxhPpuN346Gl221KA5wDzbf1K7x1+IGuotgUy0RTxnLgl24 fiJbkw6clrBnY+aZy/BFSZgDexq0/B/vazFawgKowuM5ggPiFUUFSFnKjBxlm+4zlBIHepTHefzv/ T1MXtKBUg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kovdr-0003M7-9E; Mon, 14 Dec 2020 21:44:27 +0000 Received: from mail-pg1-x543.google.com ([2607:f8b0:4864:20::543]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kovdn-0003LE-Pk for linux-arm-kernel@lists.infradead.org; Mon, 14 Dec 2020 21:44:25 +0000 Received: by mail-pg1-x543.google.com with SMTP id n7so13657948pgg.2 for ; Mon, 14 Dec 2020 13:44:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=6EWmrppepC6CHcBZOqhjNztvHasoofk8FBuQ7CK72Yo=; b=mlBDwaeR5EuT6thidly4obxEYWArXsfs8EmBKFKvYaUpY1DmcjmF+VaqtG4iTHINT7 FCF4QnHO0zFmQGeRNsOnf9aLmv0PgPgM62Yiq5xdZxNZ55Oo4kUVltzD7qWaf3M3O/L4 D0JItD3kQic9c8ZP/u2MlOvD+RaeHKs8561wd3mGt1txmrGnkQCy12wzgpOqqd2kxDw+ +T4eRRkuhC4NJbRoLJq7alsoh+TwbAVMbKSPRMWVX28HMsXdeFKXUyJwNXnrqGDvAS0p oJFC5Tq8Q64l74jlOjiJWeTDfSYUHNDbT/uG7iZqCZ4COqrasq0kWFLb7//kPGEK7DNN tvwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=6EWmrppepC6CHcBZOqhjNztvHasoofk8FBuQ7CK72Yo=; b=W/IfIMR3lulYJBnJ+RZAxvBvig2KLt2o8jFxwN5PAJuGiR1DHW1O0z7ELWx3S6d66s x2qYAurn6406lw5xrMWtgHVZ6ktY6hb+BUd3s0RM5AqCmBkO0UrYxXqO/qdeJmWeAehP oPYC4RK9FVpjbAn+SJvHAD3q90SpvfnKo12byvE200lSEl82LnNQKPBbbMQrGB5JW/56 0JVWqhWHz5cuztg3wgD12GYRjpgcHmQnTmh9hjvq3F8KXKRXZLbym21gtV+ejq4rX6mF cm+kG9zsOfm8rTNM8BL5b0jNoAjFeL+AjbU8126HAQxDkRtTxKLPDxxQRDCJYh7tWemK P0pw== X-Gm-Message-State: AOAM530yhMdavhome/b5o9p/roAGcE4BkDBULtmRqmKTkgFqTI/WQ2h1 oZjLIFrozgs5Z0ol460VZIPUYURh2zLqS+BwJBp5oA== X-Google-Smtp-Source: ABdhPJz0JzYkf4G+e7/8YeB0Xj41+fXETTPGT4aAt+KsRx0P/0WfwpiHwW5NxVnrsiyY7ZkKS7H3cI1Y6xqq+O4xRgY= X-Received: by 2002:a62:7c4a:0:b029:19d:b7bc:2c51 with SMTP id x71-20020a627c4a0000b029019db7bc2c51mr26329699pfc.30.1607982257943; Mon, 14 Dec 2020 13:44:17 -0800 (PST) MIME-Version: 1.0 References: <20201016175339.2429280-1-ndesaulniers@google.com> <160319373854.2175971.17968938488121846972.b4-ty@kernel.org> In-Reply-To: <160319373854.2175971.17968938488121846972.b4-ty@kernel.org> From: Nick Desaulniers Date: Mon, 14 Dec 2020 13:44:06 -0800 Message-ID: Subject: Re: [PATCH] arm64: link with -z norelro regardless of CONFIG_RELOCATABLE To: Alan Modra X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201214_164423_987516_731A4F24 X-CRM114-Status: GOOD ( 18.15 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?B?RsSBbmctcnXDrCBTw7JuZw==?= , Will Deacon , Quentin Perret , Catalin Marinas , LKML , "# 3.4.x" , Peter Smith , clang-built-linux , kernel-team , Ard Biesheuvel , Linux ARM Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Tue, Oct 20, 2020 at 10:57 AM Will Deacon wrote: > > On Fri, 16 Oct 2020 10:53:39 -0700, Nick Desaulniers wrote: > > With CONFIG_EXPERT=y, CONFIG_KASAN=y, CONFIG_RANDOMIZE_BASE=n, > > CONFIG_RELOCATABLE=n, we observe the following failure when trying to > > link the kernel image with LD=ld.lld: > > > > error: section: .exit.data is not contiguous with other relro sections > > > > ld.lld defaults to -z relro while ld.bfd defaults to -z norelro. This > > was previously fixed, but only for CONFIG_RELOCATABLE=y. > > Applied to arm64 (for-next/core), thanks! > > [1/1] arm64: link with -z norelro regardless of CONFIG_RELOCATABLE > https://git.kernel.org/arm64/c/3b92fa7485eb It looks like this is now producing warnings when linking with BFD. $ make ... ... LD .tmp_vmlinux.kallsyms1 aarch64-linux-gnu-ld: warning: -z norelro ignored KSYMS .tmp_vmlinux.kallsyms1.S AS .tmp_vmlinux.kallsyms1.S LD .tmp_vmlinux.kallsyms2 aarch64-linux-gnu-ld: warning: -z norelro ignored KSYMS .tmp_vmlinux.kallsyms2.S AS .tmp_vmlinux.kallsyms2.S LD vmlinux aarch64-linux-gnu-ld: warning: -z norelro ignored Alan, looking at binutils-gdb commit 5fd104addfddb ("Emit a warning when -z relro is unsupported") mentions targets lacking relro support will produce this warning. I thought aarch64 supports relro though...? Looks like we're invoking: + aarch64-linux-gnu-ld -EL -maarch64elf --no-undefined -X -z norelro -shared -Bsymbolic -z notext --no-apply-dynamic-relocs --fix-cortex-a53-843419 --build-id=sha1 --orphan-handling=warn --strip-debug -o .tmp_vmlinux.kallsyms1 -T ./arch/arm64/kernel/vmlinux.lds --whole-archive arch/arm64/kernel/head.o init/built-in.a usr/built-in.a arch/arm64/built-in.a kernel/built-in.a certs/built-in.a mm/built-in.a fs/built-in.a ipc/built-in.a security/built-in.a crypto/built-in.a block/built-in.a arch/arm64/lib/built-in.a lib/built-in.a arch/arm64/lib/lib.a lib/lib.a drivers/built-in.a sound/built-in.a net/built-in.a virt/built-in.a --no-whole-archive --start-group ./drivers/firmware/efi/libstub/lib.a --end-group aarch64-linux-gnu-ld: warning: -z norelro ignored So we set the emulation mode via -maarch64elf, and our preprocessed linker script has `OUTPUT_ARCH(aarch64)`. From that commit, there's a linked mailing list discussion: https://sourceware.org/legacy-ml/binutils/2017-01/msg00441.html Is there something more we need to do to our linker script (https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/arm64/kernel/vmlinux.lds.S) for BFD not to warn when passing `-z norelro`? It looks like common page size might need to be specified? I tried: diff --git a/arch/arm64/kernel/vmlinux.lds.S b/arch/arm64/kernel/vmlinux.lds.S index 1bda604f4c70..ae8cce140fdf 100644 --- a/arch/arm64/kernel/vmlinux.lds.S +++ b/arch/arm64/kernel/vmlinux.lds.S @@ -121,7 +121,7 @@ SECTIONS _text = .; HEAD_TEXT } - .text : { /* Real text segment */ + .text ALIGN (CONSTANT (COMMONPAGESIZE)): { /* Real text segment */ and passing `-z common-page-size=4096` but neither seemed to do the trick. (https://docs.adacore.com/live/wave/binutils-stable/html/ld/ld.html#index-COMMONPAGESIZE-553 Worst case, we add `-z norelro` just for LLD: diff --git a/arch/arm64/Makefile b/arch/arm64/Makefile index 6a87d592bd00..6a6235e1e8a9 100644 --- a/arch/arm64/Makefile +++ b/arch/arm64/Makefile @@ -10,7 +10,7 @@ # # Copyright (C) 1995-2001 by Russell King -LDFLAGS_vmlinux :=--no-undefined -X -z norelro +LDFLAGS_vmlinux :=--no-undefined -X ifeq ($(CONFIG_RELOCATABLE), y) # Pass --no-apply-dynamic-relocs to restore pre-binutils-2.27 behaviour @@ -28,6 +28,10 @@ LDFLAGS_vmlinux += --fix-cortex-a53-843419 endif endif +ifeq ($(CONFIG_LD_IS_LLD), y) +LDFLAGS_vmlinux += -z norelro +endif + ifeq ($(CONFIG_ARM64_USE_LSE_ATOMICS), y) ifneq ($(CONFIG_ARM64_LSE_ATOMICS), y) $(warning LSE atomics not supported by binutils) -- Thanks, ~Nick Desaulniers _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel