linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] kbuild: Always link with '-z norelro'
@ 2020-11-12 18:38 Nathan Chancellor
  2020-11-13  0:44 ` Nick Desaulniers
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Nathan Chancellor @ 2020-11-12 18:38 UTC (permalink / raw)
  To: Masahiro Yamada, Michal Marek, Catalin Marinas, Will Deacon,
	Russell King
  Cc: Florian Fainelli, Arnd Bergmann, Abbott Liu, Linus Walleij,
	Jian Cai, Andrey Ryabinin, Mike Rapoport, Ard Biesheuvel,
	linux-kbuild, linux-kernel, linux-arm-kernel, Nathan Chancellor,
	Nick Desaulniers

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 <ndesaulniers@google.com>
Signed-off-by: Nathan Chancellor <natechancellor@gmail.com>
---

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


^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2020-11-19 19:34 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-12 18:38 [PATCH] kbuild: Always link with '-z norelro' Nathan Chancellor
2020-11-13  0:44 ` Nick Desaulniers
2020-11-13  0:53   ` Nathan Chancellor
2020-11-13  6:06     ` Ard Biesheuvel
2020-11-13 19:34       ` Nick Desaulniers
2020-11-18 23:05         ` Nick Desaulniers
2020-11-18 23:06           ` Ard Biesheuvel
2020-11-18 23:24             ` Nick Desaulniers
2020-11-19 19:33               ` Nathan Chancellor
2020-11-16 12:31 ` Catalin Marinas
2020-11-17 21:17 ` Linus Walleij

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).