Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp779737pxb; Thu, 12 Nov 2020 16:46:51 -0800 (PST) X-Google-Smtp-Source: ABdhPJznER4uZBvS//M0cXp7sQ10Tj6N4Qgz9qMvQR/AzJFTvu3x1gA8ySmyY4G+LN+Q2vjR52Mh X-Received: by 2002:a17:906:ae95:: with SMTP id md21mr1876912ejb.425.1605228411220; Thu, 12 Nov 2020 16:46:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605228411; cv=none; d=google.com; s=arc-20160816; b=jgTA7GfNzm2WX0ZPHVp22H1nIgof9RhSvxJtFss5OLcNZte3AGozavPTvhU8MaApwB hjnG7q/2LHaT/yNJDvi7oyk12csagZw5V7HVpeNxX6gQlWVKIAVSyKCuXvala9LgyEkE D4nR0cCo1IxUz+niRZwEyiF445vDJuoVvhnMbmuaMrDsJPuo2GyUCC8QBU/8Zd7rrco8 wVW0bntGP8MaUQhiebYyW5XWZsiT9sox2MqPXw0zsk5T16Alo+980ZpAMXA1MZuupfT8 mLZoueUMPxZ63DX/eUOG+FuFBLUmuPwMu81az6LHJd4Te0plv3pb4TZD3uPYj0m+smeS UICg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=uPz0VNRgAU6deAyeUwvHx8BA1S/DOt0Kxt6fec1P47Y=; b=mXFmCwJ2vDjMPKtSJg7O/HYl7FJyjDKwe2MyWAA9qbFfzcF/la0Tc4VJzLlHnlwBi0 sK3ltFPKs5WGDhmBN1SzLUPfJ9v+uM/KybXydIRfHmsqciWvy84PHduD3+FTu9dToy/y LL6+zIv+k/0DHhZY2yWsRFrKfY7dDI4fFP6EZrFQWZZIG33IFBuKAGxIcBwWba/W62Z/ zhekVlA2AMOOpCKvQL/6wL7gDnJTbCsoHQ+zMBbf6yoHTP8YuDn3D5ruS17tVe6oqASH 6lE7p7Ty5fw3iZKOEV6aeXCEYLjMBsOEfejI8QC9sTsOtzsQdoBGTrtpN/zKQ2loi0bV O5Ug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=jVu4e1Sp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r11si4929491edv.237.2020.11.12.16.46.28; Thu, 12 Nov 2020 16:46:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=jVu4e1Sp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726142AbgKMAo7 (ORCPT + 99 others); Thu, 12 Nov 2020 19:44:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42084 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725894AbgKMAo6 (ORCPT ); Thu, 12 Nov 2020 19:44:58 -0500 Received: from mail-pg1-x543.google.com (mail-pg1-x543.google.com [IPv6:2607:f8b0:4864:20::543]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 25732C0613D1 for ; Thu, 12 Nov 2020 16:44:58 -0800 (PST) Received: by mail-pg1-x543.google.com with SMTP id h16so1612743pgb.7 for ; Thu, 12 Nov 2020 16:44:58 -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=uPz0VNRgAU6deAyeUwvHx8BA1S/DOt0Kxt6fec1P47Y=; b=jVu4e1SpPT8q2ZSLkXlUchM4CAK+7CacjDt1JACHjvW3bNh3Jw0OxOWHELqcqv47hV h8wN6iQfU66pciPEgbgT1chLXIf9cRIZskLq2NrJWCPuY+/9tirTRRWs6PwUkwwhg8yM C1A21Zo+dbuBqJVJlG/IvsQPjDiOiuFnD3chj0Of9bMEy1Q1/BhakuQYfRecPXacg6w6 JsKZn7CFQzRwglZdBGIh0eEEvRcSzvGlllD96QpxYfT/Vb1xifRy1Kgo1x7m89VvDOUR i4V4iiFbJdTUWMEvpxuWuG6pPz/WWDJxuqqEfz5/NaC+1f2PwZkAtBA4e3t3/FAS6bp/ DWIQ== 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=uPz0VNRgAU6deAyeUwvHx8BA1S/DOt0Kxt6fec1P47Y=; b=rNb2+pTQ7K9N4uw+Q+wSm8Ltkgin1FWIq6HTX/xEyH61Te5t375VVezMs8lZH/lYAQ 2/W30ydY8sdeEkigVc2dYycgC51iuBn49juxghXIy4TxJBuHU6s8HAwvdPT8LXIhCtUn k5Qb4gBnD0xzw/Y6lxdzPCivw/Mcpr1wRyfYL1/lBNvpZ/FpiPnGlXwF8QmTwy62SYKn /bos30zLmfLs9sivVSa0EAKzx3ptHiVbIJyxD0b1f2oxH8HNyf21/EUQ2e7vqI8HZeid kj9dy526sTRnASsXfhJybOfL+18Kmu9RIG0qrPJ4S/EB3428CXy/FL7iQGbbIA9kwPMQ ndSQ== X-Gm-Message-State: AOAM530Xb/ArMAnSkN842nE4ZfDxqEXkO5FHE/AaKPi0hmO1XFHIAskK DpmevnUwAsNAIZy+Tt/myjbIQlkjKIzTOg6/Sy2wjg== X-Received: by 2002:a17:90b:110b:: with SMTP id gi11mr457122pjb.25.1605228297498; Thu, 12 Nov 2020 16:44:57 -0800 (PST) MIME-Version: 1.0 References: <20201112183839.1009297-1-natechancellor@gmail.com> In-Reply-To: <20201112183839.1009297-1-natechancellor@gmail.com> From: Nick Desaulniers Date: Thu, 12 Nov 2020 16:44:46 -0800 Message-ID: Subject: Re: [PATCH] kbuild: Always link with '-z norelro' To: Nathan Chancellor , Masahiro Yamada Cc: Michal Marek , Catalin Marinas , Will Deacon , Russell King , Florian Fainelli , Arnd Bergmann , Abbott Liu , Linus Walleij , Jian Cai , Andrey Ryabinin , Mike Rapoport , Ard Biesheuvel , Linux Kbuild mailing list , LKML , Linux ARM Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Nov 12, 2020 at 10:41 AM Nathan Chancellor wrote: > > Commit 3bbd3db86470 ("arm64: relocatable: fix inconsistencies in linker > script and options") added '-z norelro' to the arm64 Makefile when > CONFIG_RELOCATABLE was set to help support ld.lld because ld.lld > defaults to '-z relro' but the kernel does not use program headers or > adhere to the section layout that is required for RELRO to work. > > Commit 3b92fa7485eb ("arm64: link with -z norelro regardless of > CONFIG_RELOCATABLE") unconditionally added it to LDFLAGS_vmlinux because > an error occurs with CONFIG_KASAN set even when CONFIG_RELOCATABLE is > unset. > > As it turns out, ARM experiences the same error after CONFIG_KASAN was > implemented, meaning that '-z norelro' needs to be added to that > Makefile as well (multi_v7_defconfig + CONFIG_KASAN=y + LD=ld.lld): > > $ make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- LLVM=1 zImage > ld.lld: error: section: .exit.data is not contiguous with other relro sections > > To avoid playing whack-a-mole with different architectures over time, > hoist '-z norelro' into the main Makefile. This does not affect ld.bfd > because '-z norelro' is the default for it. > > Link: https://github.com/ClangBuiltLinux/linux/issues/1189 > Suggested-by: Nick Desaulniers > Signed-off-by: Nathan Chancellor Why not add it additionally to KBUILD_LDFLAGS_MODULE a la `--build-id=sha1` a few lines above? (or `LDFLAGS_MODULE`, but that looks unused?) We probably don't want this for modules either. In that case, you could add -z norelo to the two existing lines with `--build-id=sha1` above? > --- > > Hi all, > > This should probably go into Russell's tree with acks from the arm64 and > kbuild maintainers. > > Cheers, > Nathan > > Makefile | 2 ++ > arch/arm64/Makefile | 2 +- > 2 files changed, 3 insertions(+), 1 deletion(-) > > diff --git a/Makefile b/Makefile > index 008aba5f1a20..648bfb486244 100644 > --- a/Makefile > +++ b/Makefile > @@ -984,6 +984,8 @@ ifeq ($(CONFIG_RELR),y) > LDFLAGS_vmlinux += --pack-dyn-relocs=relr > endif > > +LDFLAGS_vmlinux += -z norelro > + > # Align the bit size of userspace programs with the kernel > KBUILD_USERCFLAGS += $(filter -m32 -m64 --target=%, $(KBUILD_CFLAGS)) > KBUILD_USERLDFLAGS += $(filter -m32 -m64 --target=%, $(KBUILD_CFLAGS)) > diff --git a/arch/arm64/Makefile b/arch/arm64/Makefile > index 5789c2d18d43..85495ff8f0fd 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 > > base-commit: f8394f232b1eab649ce2df5c5f15b0e528c92091 > -- > 2.29.2 > -- Thanks, ~Nick Desaulniers