Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit 68c76ad

Browse files
ardbiesheuvelwilldeacon
authored andcommitted
arm64: unwind: add asynchronous unwind tables to kernel and modules
Enable asynchronous unwind table generation for both the core kernel as well as modules, and emit the resulting .eh_frame sections as init code so we can use the unwind directives for code patching at boot or module load time. This will be used by dynamic shadow call stack support, which will rely on code patching rather than compiler codegen to emit the shadow call stack push and pop instructions. Signed-off-by: Ard Biesheuvel <[email protected]> Reviewed-by: Nick Desaulniers <[email protected]> Reviewed-by: Sami Tolvanen <[email protected]> Tested-by: Sami Tolvanen <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Will Deacon <[email protected]>
1 parent f0c4d9f commit 68c76ad

File tree

9 files changed

+45
-2
lines changed

9 files changed

+45
-2
lines changed

arch/arm64/Kconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,9 @@ config KASAN_SHADOW_OFFSET
370370
default 0xeffffff800000000 if ARM64_VA_BITS_36 && KASAN_SW_TAGS
371371
default 0xffffffffffffffff
372372

373+
config UNWIND_TABLES
374+
bool
375+
373376
source "arch/arm64/Kconfig.platforms"
374377

375378
menu "Kernel Features"

arch/arm64/Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,13 @@ KBUILD_CFLAGS += $(call cc-option,-mabi=lp64)
4545
KBUILD_AFLAGS += $(call cc-option,-mabi=lp64)
4646

4747
# Avoid generating .eh_frame* sections.
48+
ifneq ($(CONFIG_UNWIND_TABLES),y)
4849
KBUILD_CFLAGS += -fno-asynchronous-unwind-tables -fno-unwind-tables
4950
KBUILD_AFLAGS += -fno-asynchronous-unwind-tables -fno-unwind-tables
51+
else
52+
KBUILD_CFLAGS += -fasynchronous-unwind-tables
53+
KBUILD_AFLAGS += -fasynchronous-unwind-tables
54+
endif
5055

5156
ifeq ($(CONFIG_STACKPROTECTOR_PER_TASK),y)
5257
prepare: stack_protector_prepare

arch/arm64/include/asm/module.lds.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,12 @@ SECTIONS {
1717
*/
1818
.text.hot : { *(.text.hot) }
1919
#endif
20+
21+
#ifdef CONFIG_UNWIND_TABLES
22+
/*
23+
* Currently, we only use unwind info at module load time, so we can
24+
* put it into the .init allocation.
25+
*/
26+
.init.eh_frame : { *(.eh_frame) }
27+
#endif
2028
}

arch/arm64/kernel/pi/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ KBUILD_CFLAGS := $(subst $(CC_FLAGS_FTRACE),,$(KBUILD_CFLAGS)) -fpie \
77
-I$(srctree)/scripts/dtc/libfdt -fno-stack-protector \
88
-include $(srctree)/include/linux/hidden.h \
99
-D__DISABLE_EXPORTS -ffreestanding -D__NO_FORTIFY \
10+
-fno-asynchronous-unwind-tables -fno-unwind-tables \
1011
$(call cc-option,-fno-addrsig)
1112

1213
# remove SCS flags from all objects in this directory

arch/arm64/kernel/vmlinux.lds.S

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,17 @@ jiffies = jiffies_64;
121121
#define TRAMP_TEXT
122122
#endif
123123

124+
#ifdef CONFIG_UNWIND_TABLES
125+
#define UNWIND_DATA_SECTIONS \
126+
.eh_frame : { \
127+
__eh_frame_start = .; \
128+
*(.eh_frame) \
129+
__eh_frame_end = .; \
130+
}
131+
#else
132+
#define UNWIND_DATA_SECTIONS
133+
#endif
134+
124135
/*
125136
* The size of the PE/COFF section that covers the kernel image, which
126137
* runs from _stext to _edata, must be a round multiple of the PE/COFF
@@ -231,6 +242,8 @@ SECTIONS
231242
__alt_instructions_end = .;
232243
}
233244

245+
UNWIND_DATA_SECTIONS
246+
234247
. = ALIGN(SEGMENT_ALIGN);
235248
__inittext_end = .;
236249
__initdata_begin = .;

arch/arm64/kvm/hyp/nvhe/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ KBUILD_CFLAGS := $(filter-out $(CC_FLAGS_FTRACE) $(CC_FLAGS_SCS) $(CC_FLAGS_CFI)
9696
# when profile optimization is applied. gen-hyprel does not support SHT_REL and
9797
# causes a build failure. Remove profile optimization flags.
9898
KBUILD_CFLAGS := $(filter-out -fprofile-sample-use=% -fprofile-use=%, $(KBUILD_CFLAGS))
99+
KBUILD_CFLAGS += -fno-asynchronous-unwind-tables -fno-unwind-tables
99100

100101
# KVM nVHE code is run at a different exception code with a different map, so
101102
# compiler instrumentation that inserts callbacks or checks into the code may

drivers/firmware/efi/libstub/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ cflags-$(CONFIG_X86) += -m$(BITS) -D__KERNEL__ \
2020
# disable the stackleak plugin
2121
cflags-$(CONFIG_ARM64) := $(subst $(CC_FLAGS_FTRACE),,$(KBUILD_CFLAGS)) \
2222
-fpie $(DISABLE_STACKLEAK_PLUGIN) \
23+
-fno-unwind-tables -fno-asynchronous-unwind-tables \
2324
$(call cc-option,-mbranch-protection=none)
2425
cflags-$(CONFIG_ARM) := $(subst $(CC_FLAGS_FTRACE),,$(KBUILD_CFLAGS)) \
2526
-fno-builtin -fpic \

include/asm-generic/vmlinux.lds.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,14 +1027,19 @@
10271027
* keep any .init_array.* sections.
10281028
* https://bugs.llvm.org/show_bug.cgi?id=46478
10291029
*/
1030+
#ifdef CONFIG_UNWIND_TABLES
1031+
#define DISCARD_EH_FRAME
1032+
#else
1033+
#define DISCARD_EH_FRAME *(.eh_frame)
1034+
#endif
10301035
#if defined(CONFIG_GCOV_KERNEL) || defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KCSAN)
10311036
# ifdef CONFIG_CONSTRUCTORS
10321037
# define SANITIZER_DISCARDS \
1033-
*(.eh_frame)
1038+
DISCARD_EH_FRAME
10341039
# else
10351040
# define SANITIZER_DISCARDS \
10361041
*(.init_array) *(.init_array.*) \
1037-
*(.eh_frame)
1042+
DISCARD_EH_FRAME
10381043
# endif
10391044
#else
10401045
# define SANITIZER_DISCARDS

scripts/module.lds.S

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
* Archs are free to supply their own linker scripts. ld will
44
* combine them automatically.
55
*/
6+
#ifdef CONFIG_UNWIND_TABLES
7+
#define DISCARD_EH_FRAME
8+
#else
9+
#define DISCARD_EH_FRAME *(.eh_frame)
10+
#endif
11+
612
SECTIONS {
713
/DISCARD/ : {
814
*(.discard)

0 commit comments

Comments
 (0)