Skip to content

Commit 2335c9c

Browse files
Jinjie RuanRussell King (Oracle)
authored andcommitted
ARM: 9407/1: Add support for STACKLEAK gcc plugin
Add the STACKLEAK gcc plugin to arm32 by adding the helper used by stackleak common code: on_thread_stack(). It initialize the stack with the poison value before returning from system calls which improves the kernel security. Additionally, this disables the plugin in EFI stub code and decompress code, which are out of scope for the protection. Before the test on Qemu versatilepb board: # echo STACKLEAK_ERASING > /sys/kernel/debug/provoke-crash/DIRECT lkdtm: Performing direct entry STACKLEAK_ERASING lkdtm: XFAIL: stackleak is not supported on this arch (HAVE_ARCH_STACKLEAK=n) After: # echo STACKLEAK_ERASING > /sys/kernel/debug/provoke-crash/DIRECT lkdtm: Performing direct entry STACKLEAK_ERASING lkdtm: stackleak stack usage: high offset: 80 bytes current: 280 bytes lowest: 696 bytes tracked: 696 bytes untracked: 192 bytes poisoned: 7220 bytes low offset: 4 bytes lkdtm: OK: the rest of the thread stack is properly erased Signed-off-by: Jinjie Ruan <[email protected]> Acked-by: Ard Biesheuvel <[email protected]> Reviewed-by: Linus Walleij <[email protected]> Signed-off-by: Russell King (Oracle) <[email protected]>
1 parent ed0f941 commit 2335c9c

File tree

5 files changed

+14
-1
lines changed

5 files changed

+14
-1
lines changed

arch/arm/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ config ARM
8686
select HAVE_ARCH_PFN_VALID
8787
select HAVE_ARCH_SECCOMP
8888
select HAVE_ARCH_SECCOMP_FILTER if AEABI && !OABI_COMPAT
89+
select HAVE_ARCH_STACKLEAK
8990
select HAVE_ARCH_THREAD_STRUCT_WHITELIST
9091
select HAVE_ARCH_TRACEHOOK
9192
select HAVE_ARCH_TRANSPARENT_HUGEPAGE if ARM_LPAE

arch/arm/boot/compressed/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ OBJS =
99

1010
HEAD = head.o
1111
OBJS += misc.o decompress.o
12+
CFLAGS_decompress.o += $(DISABLE_STACKLEAK_PLUGIN)
1213
ifeq ($(CONFIG_DEBUG_UNCOMPRESS),y)
1314
OBJS += debug.o
1415
AFLAGS_head.o += -DDEBUG

arch/arm/include/asm/stacktrace.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ struct stackframe {
2626
#endif
2727
};
2828

29+
static inline bool on_thread_stack(void)
30+
{
31+
unsigned long delta = current_stack_pointer ^ (unsigned long)current->stack;
32+
33+
return delta < THREAD_SIZE;
34+
}
35+
2936
static __always_inline
3037
void arm_get_current_stackframe(struct pt_regs *regs, struct stackframe *frame)
3138
{

arch/arm/kernel/entry-common.S

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,9 @@ no_work_pending:
119119

120120
ct_user_enter save = 0
121121

122+
#ifdef CONFIG_GCC_PLUGIN_STACKLEAK
123+
bl stackleak_erase_on_task_stack
124+
#endif
122125
restore_user_regs fast = 0, offset = 0
123126
ENDPROC(ret_to_user_from_irq)
124127
ENDPROC(ret_to_user)

drivers/firmware/efi/libstub/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ cflags-$(CONFIG_ARM64) += -fpie $(DISABLE_STACKLEAK_PLUGIN) \
2727
cflags-$(CONFIG_ARM) += -DEFI_HAVE_STRLEN -DEFI_HAVE_STRNLEN \
2828
-DEFI_HAVE_MEMCHR -DEFI_HAVE_STRRCHR \
2929
-DEFI_HAVE_STRCMP -fno-builtin -fpic \
30-
$(call cc-option,-mno-single-pic-base)
30+
$(call cc-option,-mno-single-pic-base) \
31+
$(DISABLE_STACKLEAK_PLUGIN)
3132
cflags-$(CONFIG_RISCV) += -fpic -DNO_ALTERNATIVE -mno-relax
3233
cflags-$(CONFIG_LOONGARCH) += -fpie
3334

0 commit comments

Comments
 (0)