]> Git Repo - J-linux.git/commitdiff
ARM: 9407/1: Add support for STACKLEAK gcc plugin
authorJinjie Ruan <[email protected]>
Thu, 27 Jun 2024 07:38:44 +0000 (08:38 +0100)
committerRussell King (Oracle) <[email protected]>
Tue, 2 Jul 2024 08:18:43 +0000 (09:18 +0100)
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]>
arch/arm/Kconfig
arch/arm/boot/compressed/Makefile
arch/arm/include/asm/stacktrace.h
arch/arm/kernel/entry-common.S
drivers/firmware/efi/libstub/Makefile

index 08572703d94d522865d709acd8f7ac354f073406..26a01ad4087c5da6d1abd536c8c4e48d46a1b9c9 100644 (file)
@@ -86,6 +86,7 @@ config ARM
        select HAVE_ARCH_PFN_VALID
        select HAVE_ARCH_SECCOMP
        select HAVE_ARCH_SECCOMP_FILTER if AEABI && !OABI_COMPAT
+       select HAVE_ARCH_STACKLEAK
        select HAVE_ARCH_THREAD_STRUCT_WHITELIST
        select HAVE_ARCH_TRACEHOOK
        select HAVE_ARCH_TRANSPARENT_HUGEPAGE if ARM_LPAE
index 6bca03c0c7f0e28e832187366d96b77ea0dfc614..945b5975fce20008c9c5ed15e2fb05894357efd9 100644 (file)
@@ -9,6 +9,7 @@ OBJS            =
 
 HEAD   = head.o
 OBJS   += misc.o decompress.o
+CFLAGS_decompress.o += $(DISABLE_STACKLEAK_PLUGIN)
 ifeq ($(CONFIG_DEBUG_UNCOMPRESS),y)
 OBJS   += debug.o
 AFLAGS_head.o += -DDEBUG
index 360f0d2406bfa08364086e885157a3a02459c277..f80a85b091d6c4ff365e15ae7100af1c3aed597f 100644 (file)
@@ -26,6 +26,13 @@ struct stackframe {
 #endif
 };
 
+static inline bool on_thread_stack(void)
+{
+       unsigned long delta = current_stack_pointer ^ (unsigned long)current->stack;
+
+       return delta < THREAD_SIZE;
+}
+
 static __always_inline
 void arm_get_current_stackframe(struct pt_regs *regs, struct stackframe *frame)
 {
index 5c31e9de7a602e22a65f64c12cf2819be9fa56d6..f379c852dcb72fa5e960bba5621cc2152f0df0d3 100644 (file)
@@ -119,6 +119,9 @@ no_work_pending:
 
        ct_user_enter save = 0
 
+#ifdef CONFIG_GCC_PLUGIN_STACKLEAK
+       bl      stackleak_erase_on_task_stack
+#endif
        restore_user_regs fast = 0, offset = 0
 ENDPROC(ret_to_user_from_irq)
 ENDPROC(ret_to_user)
index 5a8a9b3429b564d7f4f0415ffd01cf5598c9c3c5..59d3dccaa8e56ec93455ade0f9ed188f31beb4e0 100644 (file)
@@ -27,7 +27,8 @@ cflags-$(CONFIG_ARM64)                += -fpie $(DISABLE_STACKLEAK_PLUGIN) \
 cflags-$(CONFIG_ARM)           += -DEFI_HAVE_STRLEN -DEFI_HAVE_STRNLEN \
                                   -DEFI_HAVE_MEMCHR -DEFI_HAVE_STRRCHR \
                                   -DEFI_HAVE_STRCMP -fno-builtin -fpic \
-                                  $(call cc-option,-mno-single-pic-base)
+                                  $(call cc-option,-mno-single-pic-base) \
+                                  $(DISABLE_STACKLEAK_PLUGIN)
 cflags-$(CONFIG_RISCV)         += -fpic -DNO_ALTERNATIVE -mno-relax
 cflags-$(CONFIG_LOONGARCH)     += -fpie
 
This page took 0.070785 seconds and 4 git commands to generate.