Skip to content

Commit b5db73f

Browse files
xhackerustcpalmer-dabbelt
authored andcommitted
riscv: enable HAVE_ARCH_STACKLEAK
Add support for the stackleak feature. Whenever the kernel returns to user space the kernel stack is filled with a poison value. At the same time, disables the plugin in EFI stub code because EFI stub is out of scope for the protection. Tested on qemu and milkv duo: / # echo STACKLEAK_ERASING > /sys/kernel/debug/provoke-crash/DIRECT [ 38.675575] lkdtm: Performing direct entry STACKLEAK_ERASING [ 38.678448] lkdtm: stackleak stack usage: [ 38.678448] high offset: 288 bytes [ 38.678448] current: 496 bytes [ 38.678448] lowest: 1328 bytes [ 38.678448] tracked: 1328 bytes [ 38.678448] untracked: 448 bytes [ 38.678448] poisoned: 14312 bytes [ 38.678448] low offset: 8 bytes [ 38.689887] lkdtm: OK: the rest of the thread stack is properly erased Signed-off-by: Jisheng Zhang <[email protected]> Reviewed-by: Charlie Jenkins <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Palmer Dabbelt <[email protected]>
1 parent 1d20e5d commit b5db73f

File tree

4 files changed

+8
-1
lines changed

4 files changed

+8
-1
lines changed

arch/riscv/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ config RISCV
123123
select HAVE_ARCH_MMAP_RND_COMPAT_BITS if COMPAT
124124
select HAVE_ARCH_RANDOMIZE_KSTACK_OFFSET
125125
select HAVE_ARCH_SECCOMP_FILTER
126+
select HAVE_ARCH_STACKLEAK
126127
select HAVE_ARCH_THREAD_STRUCT_WHITELIST
127128
select HAVE_ARCH_TRACEHOOK
128129
select HAVE_ARCH_TRANSPARENT_HUGEPAGE if 64BIT && MMU

arch/riscv/include/asm/thread_info.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#include <asm/page.h>
1212
#include <linux/const.h>
13+
#include <linux/sizes.h>
1314

1415
/* thread information allocation */
1516
#define THREAD_SIZE_ORDER CONFIG_THREAD_SIZE_ORDER

arch/riscv/kernel/entry.S

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,10 @@ SYM_CODE_START_NOALIGN(ret_from_exception)
133133
#endif
134134
bnez s0, 1f
135135

136+
#ifdef CONFIG_GCC_PLUGIN_STACKLEAK
137+
call stackleak_erase_on_task_stack
138+
#endif
139+
136140
/* Save unwound kernel stack pointer in thread_info */
137141
addi s0, sp, PT_SIZE_ON_STACK
138142
REG_S s0, TASK_TI_KERNEL_SP(tp)

drivers/firmware/efi/libstub/Makefile

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

3435
cflags-$(CONFIG_EFI_PARAMS_FROM_FDT) += -I$(srctree)/scripts/dtc/libfdt

0 commit comments

Comments
 (0)