From fa71cc4400924859467812705749ee9b98b3eec6 Mon Sep 17 00:00:00 2001
From: Oscar Salvador <osalvador@suse.de>
Date: Wed, 5 Oct 2022 18:09:21 +0200
Subject: [PATCH] arm64: Discard .note.GNU-stack section
Patch-mainline: Never, SUSE specific
References: bsc#1203693
Commit "Makefile: link with -z noexecstack --no-warn-rwx-segments: ddbd47d2219a"
creates a new section .note.GNU-stack, which is not discarded by arm64.
This changes the ELF layout and causes the build to fail on arm64.
Quoting Michal Matz:
"The .note.GNU-stack section in head.o is created by 'ld -r -z noexecstack',
when relinking head.o into head.o (for various reasons). That section is created
with SHT_PROGBITS, and as the kernel linker script doesn't discard those
it also makes the output ".notes" section (which
collects all .note* sections) SHT_PROGBITS, which in turn makes ld not generate
a PT_NOTE segment covering all these.
Now, I initially thought the linker with 'ld -r', when generating a
.note.GNU-stack section because of a command line option should simply create it
with the type SHT_NOTE and all would be well. That somewhat works, but is actually
wrong: a SHT_NOTE section has a specific layout per the gABI (at least
it must contain a header), but .note.GNU-stack is empty. So it really can't
be SHT_NOTE but must remain either SHT_PROGBITS or SHT_NOBITS."
Fix it for now by discarding that section.
Signed-off-by: Oscar Salvador <osalvador@suse.de>
Suggested-by: Michael Matz <matz@suse.com"
---
arch/arm64/kernel/vmlinux.lds.S | 1 +
1 file changed, 1 insertion(+)
diff --git a/arch/arm64/kernel/vmlinux.lds.S b/arch/arm64/kernel/vmlinux.lds.S
index 1a40822bbbc5..cd061a9f135d 100644
--- a/arch/arm64/kernel/vmlinux.lds.S
+++ b/arch/arm64/kernel/vmlinux.lds.S
@@ -139,6 +139,7 @@ SECTIONS
/DISCARD/ : {
*(.interp .dynamic)
*(.dynsym .dynstr .hash .gnu.hash)
+ *(.note.GNU-stack)
}
. = KIMAGE_VADDR;
--
2.35.3