mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/chenhuacai/linux-loongson
synced 2025-08-27 15:36:48 +00:00
stackleak: Rename STACKLEAK to KSTACK_ERASE
In preparation for adding Clang sanitizer coverage stack depth tracking that can support stack depth callbacks: - Add the new top-level CONFIG_KSTACK_ERASE option which will be implemented either with the stackleak GCC plugin, or with the Clang stack depth callback support. - Rename CONFIG_GCC_PLUGIN_STACKLEAK as needed to CONFIG_KSTACK_ERASE, but keep it for anything specific to the GCC plugin itself. - Rename all exposed "STACKLEAK" names and files to "KSTACK_ERASE" (named for what it does rather than what it protects against), but leave as many of the internals alone as possible to avoid even more churn. While here, also split "prev_lowest_stack" into CONFIG_KSTACK_ERASE_METRICS, since that's the only place it is referenced from. Suggested-by: Ingo Molnar <mingo@kernel.org> Link: https://lore.kernel.org/r/20250717232519.2984886-1-kees@kernel.org Signed-off-by: Kees Cook <kees@kernel.org>
This commit is contained in:
parent
fc07839203
commit
57fbad15c2
@ -1465,7 +1465,7 @@ stack_erasing
|
|||||||
=============
|
=============
|
||||||
|
|
||||||
This parameter can be used to control kernel stack erasing at the end
|
This parameter can be used to control kernel stack erasing at the end
|
||||||
of syscalls for kernels built with ``CONFIG_GCC_PLUGIN_STACKLEAK``.
|
of syscalls for kernels built with ``CONFIG_KSTACK_ERASE``.
|
||||||
|
|
||||||
That erasing reduces the information which kernel stack leak bugs
|
That erasing reduces the information which kernel stack leak bugs
|
||||||
can reveal and blocks some uninitialized stack variable attacks.
|
can reveal and blocks some uninitialized stack variable attacks.
|
||||||
@ -1473,7 +1473,7 @@ The tradeoff is the performance impact: on a single CPU system kernel
|
|||||||
compilation sees a 1% slowdown, other systems and workloads may vary.
|
compilation sees a 1% slowdown, other systems and workloads may vary.
|
||||||
|
|
||||||
= ====================================================================
|
= ====================================================================
|
||||||
0 Kernel stack erasing is disabled, STACKLEAK_METRICS are not updated.
|
0 Kernel stack erasing is disabled, KSTACK_ERASE_METRICS are not updated.
|
||||||
1 Kernel stack erasing is enabled (default), it is performed before
|
1 Kernel stack erasing is enabled (default), it is performed before
|
||||||
returning to the userspace at the end of syscalls.
|
returning to the userspace at the end of syscalls.
|
||||||
= ====================================================================
|
= ====================================================================
|
||||||
|
@ -176,5 +176,5 @@ Be very careful vs. KASLR when changing anything here. The KASLR address
|
|||||||
range must not overlap with anything except the KASAN shadow area, which is
|
range must not overlap with anything except the KASAN shadow area, which is
|
||||||
correct as KASAN disables KASLR.
|
correct as KASAN disables KASLR.
|
||||||
|
|
||||||
For both 4- and 5-level layouts, the STACKLEAK_POISON value in the last 2MB
|
For both 4- and 5-level layouts, the KSTACK_ERASE_POISON value in the last 2MB
|
||||||
hole: ffffffffffff4111
|
hole: ffffffffffff4111
|
||||||
|
@ -303,7 +303,7 @@ Memory poisoning
|
|||||||
|
|
||||||
When releasing memory, it is best to poison the contents, to avoid reuse
|
When releasing memory, it is best to poison the contents, to avoid reuse
|
||||||
attacks that rely on the old contents of memory. E.g., clear stack on a
|
attacks that rely on the old contents of memory. E.g., clear stack on a
|
||||||
syscall return (``CONFIG_GCC_PLUGIN_STACKLEAK``), wipe heap memory on a
|
syscall return (``CONFIG_KSTACK_ERASE``), wipe heap memory on a
|
||||||
free. This frustrates many uninitialized variable attacks, stack content
|
free. This frustrates many uninitialized variable attacks, stack content
|
||||||
exposures, heap content exposures, and use-after-free attacks.
|
exposures, heap content exposures, and use-after-free attacks.
|
||||||
|
|
||||||
|
@ -259,7 +259,7 @@ KALLSYSM,则会直接打印原始地址。
|
|||||||
--------
|
--------
|
||||||
|
|
||||||
在释放内存时,最好对内存内容进行清除处理,以防止攻击者重用内存中以前
|
在释放内存时,最好对内存内容进行清除处理,以防止攻击者重用内存中以前
|
||||||
的内容。例如,在系统调用返回时清除堆栈(CONFIG_GCC_PLUGIN_STACKLEAK),
|
的内容。例如,在系统调用返回时清除堆栈(CONFIG_KSTACK_ERASE),
|
||||||
在释放堆内容是清除其内容。这有助于防止许多未初始化变量攻击、堆栈内容
|
在释放堆内容是清除其内容。这有助于防止许多未初始化变量攻击、堆栈内容
|
||||||
泄露、堆内容泄露以及使用后释放攻击(user-after-free)。
|
泄露、堆内容泄露以及使用后释放攻击(user-after-free)。
|
||||||
|
|
||||||
|
@ -9992,8 +9992,6 @@ L: linux-hardening@vger.kernel.org
|
|||||||
S: Maintained
|
S: Maintained
|
||||||
T: git git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux.git for-next/hardening
|
T: git git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux.git for-next/hardening
|
||||||
F: Documentation/kbuild/gcc-plugins.rst
|
F: Documentation/kbuild/gcc-plugins.rst
|
||||||
F: include/linux/stackleak.h
|
|
||||||
F: kernel/stackleak.c
|
|
||||||
F: scripts/Makefile.gcc-plugins
|
F: scripts/Makefile.gcc-plugins
|
||||||
F: scripts/gcc-plugins/
|
F: scripts/gcc-plugins/
|
||||||
|
|
||||||
@ -13087,10 +13085,12 @@ T: git git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux.git for-next/har
|
|||||||
F: Documentation/ABI/testing/sysfs-kernel-oops_count
|
F: Documentation/ABI/testing/sysfs-kernel-oops_count
|
||||||
F: Documentation/ABI/testing/sysfs-kernel-warn_count
|
F: Documentation/ABI/testing/sysfs-kernel-warn_count
|
||||||
F: arch/*/configs/hardening.config
|
F: arch/*/configs/hardening.config
|
||||||
|
F: include/linux/kstack_erase.h
|
||||||
F: include/linux/overflow.h
|
F: include/linux/overflow.h
|
||||||
F: include/linux/randomize_kstack.h
|
F: include/linux/randomize_kstack.h
|
||||||
F: include/linux/ucopysize.h
|
F: include/linux/ucopysize.h
|
||||||
F: kernel/configs/hardening.config
|
F: kernel/configs/hardening.config
|
||||||
|
F: kernel/kstack_erase.c
|
||||||
F: lib/tests/randstruct_kunit.c
|
F: lib/tests/randstruct_kunit.c
|
||||||
F: lib/tests/usercopy_kunit.c
|
F: lib/tests/usercopy_kunit.c
|
||||||
F: mm/usercopy.c
|
F: mm/usercopy.c
|
||||||
|
@ -630,11 +630,11 @@ config SECCOMP_CACHE_DEBUG
|
|||||||
|
|
||||||
If unsure, say N.
|
If unsure, say N.
|
||||||
|
|
||||||
config HAVE_ARCH_STACKLEAK
|
config HAVE_ARCH_KSTACK_ERASE
|
||||||
bool
|
bool
|
||||||
help
|
help
|
||||||
An architecture should select this if it has the code which
|
An architecture should select this if it has the code which
|
||||||
fills the used part of the kernel stack with the STACKLEAK_POISON
|
fills the used part of the kernel stack with the KSTACK_ERASE_POISON
|
||||||
value before returning from system calls.
|
value before returning from system calls.
|
||||||
|
|
||||||
config HAVE_STACKPROTECTOR
|
config HAVE_STACKPROTECTOR
|
||||||
|
@ -87,11 +87,11 @@ config ARM
|
|||||||
select HAVE_ARCH_KGDB if !CPU_ENDIAN_BE32 && MMU
|
select HAVE_ARCH_KGDB if !CPU_ENDIAN_BE32 && MMU
|
||||||
select HAVE_ARCH_KASAN if MMU && !XIP_KERNEL
|
select HAVE_ARCH_KASAN if MMU && !XIP_KERNEL
|
||||||
select HAVE_ARCH_KASAN_VMALLOC if HAVE_ARCH_KASAN
|
select HAVE_ARCH_KASAN_VMALLOC if HAVE_ARCH_KASAN
|
||||||
|
select HAVE_ARCH_KSTACK_ERASE
|
||||||
select HAVE_ARCH_MMAP_RND_BITS if MMU
|
select HAVE_ARCH_MMAP_RND_BITS if MMU
|
||||||
select HAVE_ARCH_PFN_VALID
|
select HAVE_ARCH_PFN_VALID
|
||||||
select HAVE_ARCH_SECCOMP
|
select HAVE_ARCH_SECCOMP
|
||||||
select HAVE_ARCH_SECCOMP_FILTER if AEABI && !OABI_COMPAT
|
select HAVE_ARCH_SECCOMP_FILTER if AEABI && !OABI_COMPAT
|
||||||
select HAVE_ARCH_STACKLEAK
|
|
||||||
select HAVE_ARCH_THREAD_STRUCT_WHITELIST
|
select HAVE_ARCH_THREAD_STRUCT_WHITELIST
|
||||||
select HAVE_ARCH_TRACEHOOK
|
select HAVE_ARCH_TRACEHOOK
|
||||||
select HAVE_ARCH_TRANSPARENT_HUGEPAGE if ARM_LPAE
|
select HAVE_ARCH_TRANSPARENT_HUGEPAGE if ARM_LPAE
|
||||||
|
@ -9,7 +9,7 @@ OBJS =
|
|||||||
|
|
||||||
HEAD = head.o
|
HEAD = head.o
|
||||||
OBJS += misc.o decompress.o
|
OBJS += misc.o decompress.o
|
||||||
CFLAGS_decompress.o += $(DISABLE_STACKLEAK_PLUGIN)
|
CFLAGS_decompress.o += $(DISABLE_KSTACK_ERASE)
|
||||||
ifeq ($(CONFIG_DEBUG_UNCOMPRESS),y)
|
ifeq ($(CONFIG_DEBUG_UNCOMPRESS),y)
|
||||||
OBJS += debug.o
|
OBJS += debug.o
|
||||||
AFLAGS_head.o += -DDEBUG
|
AFLAGS_head.o += -DDEBUG
|
||||||
|
@ -119,7 +119,7 @@ no_work_pending:
|
|||||||
|
|
||||||
ct_user_enter save = 0
|
ct_user_enter save = 0
|
||||||
|
|
||||||
#ifdef CONFIG_GCC_PLUGIN_STACKLEAK
|
#ifdef CONFIG_KSTACK_ERASE
|
||||||
bl stackleak_erase_on_task_stack
|
bl stackleak_erase_on_task_stack
|
||||||
#endif
|
#endif
|
||||||
restore_user_regs fast = 0, offset = 0
|
restore_user_regs fast = 0, offset = 0
|
||||||
|
@ -187,12 +187,12 @@ config ARM64
|
|||||||
select HAVE_ARCH_KCSAN if EXPERT
|
select HAVE_ARCH_KCSAN if EXPERT
|
||||||
select HAVE_ARCH_KFENCE
|
select HAVE_ARCH_KFENCE
|
||||||
select HAVE_ARCH_KGDB
|
select HAVE_ARCH_KGDB
|
||||||
|
select HAVE_ARCH_KSTACK_ERASE
|
||||||
select HAVE_ARCH_MMAP_RND_BITS
|
select HAVE_ARCH_MMAP_RND_BITS
|
||||||
select HAVE_ARCH_MMAP_RND_COMPAT_BITS if COMPAT
|
select HAVE_ARCH_MMAP_RND_COMPAT_BITS if COMPAT
|
||||||
select HAVE_ARCH_PREL32_RELOCATIONS
|
select HAVE_ARCH_PREL32_RELOCATIONS
|
||||||
select HAVE_ARCH_RANDOMIZE_KSTACK_OFFSET
|
select HAVE_ARCH_RANDOMIZE_KSTACK_OFFSET
|
||||||
select HAVE_ARCH_SECCOMP_FILTER
|
select HAVE_ARCH_SECCOMP_FILTER
|
||||||
select HAVE_ARCH_STACKLEAK
|
|
||||||
select HAVE_ARCH_THREAD_STRUCT_WHITELIST
|
select HAVE_ARCH_THREAD_STRUCT_WHITELIST
|
||||||
select HAVE_ARCH_TRACEHOOK
|
select HAVE_ARCH_TRACEHOOK
|
||||||
select HAVE_ARCH_TRANSPARENT_HUGEPAGE
|
select HAVE_ARCH_TRANSPARENT_HUGEPAGE
|
||||||
|
@ -614,7 +614,7 @@ SYM_CODE_END(ret_to_kernel)
|
|||||||
SYM_CODE_START_LOCAL(ret_to_user)
|
SYM_CODE_START_LOCAL(ret_to_user)
|
||||||
ldr x19, [tsk, #TSK_TI_FLAGS] // re-check for single-step
|
ldr x19, [tsk, #TSK_TI_FLAGS] // re-check for single-step
|
||||||
enable_step_tsk x19, x2
|
enable_step_tsk x19, x2
|
||||||
#ifdef CONFIG_GCC_PLUGIN_STACKLEAK
|
#ifdef CONFIG_KSTACK_ERASE
|
||||||
bl stackleak_erase_on_task_stack
|
bl stackleak_erase_on_task_stack
|
||||||
#endif
|
#endif
|
||||||
kernel_exit 0
|
kernel_exit 0
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
# Copyright 2022 Google LLC
|
# Copyright 2022 Google LLC
|
||||||
|
|
||||||
KBUILD_CFLAGS := $(subst $(CC_FLAGS_FTRACE),,$(KBUILD_CFLAGS)) -fpie \
|
KBUILD_CFLAGS := $(subst $(CC_FLAGS_FTRACE),,$(KBUILD_CFLAGS)) -fpie \
|
||||||
-Os -DDISABLE_BRANCH_PROFILING $(DISABLE_STACKLEAK_PLUGIN) \
|
-Os -DDISABLE_BRANCH_PROFILING $(DISABLE_KSTACK_ERASE) \
|
||||||
$(DISABLE_LATENT_ENTROPY_PLUGIN) \
|
$(DISABLE_LATENT_ENTROPY_PLUGIN) \
|
||||||
$(call cc-option,-mbranch-protection=none) \
|
$(call cc-option,-mbranch-protection=none) \
|
||||||
-I$(srctree)/scripts/dtc/libfdt -fno-stack-protector \
|
-I$(srctree)/scripts/dtc/libfdt -fno-stack-protector \
|
||||||
|
@ -12,7 +12,7 @@ asflags-y := -D__KVM_NVHE_HYPERVISOR__ -D__DISABLE_EXPORTS
|
|||||||
ccflags-y := -D__KVM_NVHE_HYPERVISOR__ -D__DISABLE_EXPORTS -D__DISABLE_TRACE_MMIO__
|
ccflags-y := -D__KVM_NVHE_HYPERVISOR__ -D__DISABLE_EXPORTS -D__DISABLE_TRACE_MMIO__
|
||||||
ccflags-y += -fno-stack-protector \
|
ccflags-y += -fno-stack-protector \
|
||||||
-DDISABLE_BRANCH_PROFILING \
|
-DDISABLE_BRANCH_PROFILING \
|
||||||
$(DISABLE_STACKLEAK_PLUGIN)
|
$(DISABLE_KSTACK_ERASE)
|
||||||
|
|
||||||
hostprogs := gen-hyprel
|
hostprogs := gen-hyprel
|
||||||
HOST_EXTRACFLAGS += -I$(objtree)/include
|
HOST_EXTRACFLAGS += -I$(objtree)/include
|
||||||
|
@ -120,11 +120,11 @@ config LOONGARCH
|
|||||||
select HAVE_ARCH_KASAN
|
select HAVE_ARCH_KASAN
|
||||||
select HAVE_ARCH_KFENCE
|
select HAVE_ARCH_KFENCE
|
||||||
select HAVE_ARCH_KGDB if PERF_EVENTS
|
select HAVE_ARCH_KGDB if PERF_EVENTS
|
||||||
|
select HAVE_ARCH_KSTACK_ERASE
|
||||||
select HAVE_ARCH_MMAP_RND_BITS if MMU
|
select HAVE_ARCH_MMAP_RND_BITS if MMU
|
||||||
select HAVE_ARCH_RANDOMIZE_KSTACK_OFFSET
|
select HAVE_ARCH_RANDOMIZE_KSTACK_OFFSET
|
||||||
select HAVE_ARCH_SECCOMP
|
select HAVE_ARCH_SECCOMP
|
||||||
select HAVE_ARCH_SECCOMP_FILTER
|
select HAVE_ARCH_SECCOMP_FILTER
|
||||||
select HAVE_ARCH_STACKLEAK
|
|
||||||
select HAVE_ARCH_TRACEHOOK
|
select HAVE_ARCH_TRACEHOOK
|
||||||
select HAVE_ARCH_TRANSPARENT_HUGEPAGE
|
select HAVE_ARCH_TRANSPARENT_HUGEPAGE
|
||||||
select HAVE_ARCH_USERFAULTFD_MINOR if USERFAULTFD
|
select HAVE_ARCH_USERFAULTFD_MINOR if USERFAULTFD
|
||||||
|
@ -135,13 +135,13 @@ config RISCV
|
|||||||
select HAVE_ARCH_KASAN if MMU && 64BIT
|
select HAVE_ARCH_KASAN if MMU && 64BIT
|
||||||
select HAVE_ARCH_KASAN_VMALLOC if MMU && 64BIT
|
select HAVE_ARCH_KASAN_VMALLOC if MMU && 64BIT
|
||||||
select HAVE_ARCH_KFENCE if MMU && 64BIT
|
select HAVE_ARCH_KFENCE if MMU && 64BIT
|
||||||
|
select HAVE_ARCH_KSTACK_ERASE
|
||||||
select HAVE_ARCH_KGDB if !XIP_KERNEL
|
select HAVE_ARCH_KGDB if !XIP_KERNEL
|
||||||
select HAVE_ARCH_KGDB_QXFER_PKT
|
select HAVE_ARCH_KGDB_QXFER_PKT
|
||||||
select HAVE_ARCH_MMAP_RND_BITS if MMU
|
select HAVE_ARCH_MMAP_RND_BITS if MMU
|
||||||
select HAVE_ARCH_MMAP_RND_COMPAT_BITS if COMPAT
|
select HAVE_ARCH_MMAP_RND_COMPAT_BITS if COMPAT
|
||||||
select HAVE_ARCH_RANDOMIZE_KSTACK_OFFSET
|
select HAVE_ARCH_RANDOMIZE_KSTACK_OFFSET
|
||||||
select HAVE_ARCH_SECCOMP_FILTER
|
select HAVE_ARCH_SECCOMP_FILTER
|
||||||
select HAVE_ARCH_STACKLEAK
|
|
||||||
select HAVE_ARCH_THREAD_STRUCT_WHITELIST
|
select HAVE_ARCH_THREAD_STRUCT_WHITELIST
|
||||||
select HAVE_ARCH_TRACEHOOK
|
select HAVE_ARCH_TRACEHOOK
|
||||||
select HAVE_ARCH_TRANSPARENT_HUGEPAGE if 64BIT && MMU
|
select HAVE_ARCH_TRANSPARENT_HUGEPAGE if 64BIT && MMU
|
||||||
|
@ -220,7 +220,7 @@ SYM_CODE_START_NOALIGN(ret_from_exception)
|
|||||||
#endif
|
#endif
|
||||||
bnez s0, 1f
|
bnez s0, 1f
|
||||||
|
|
||||||
#ifdef CONFIG_GCC_PLUGIN_STACKLEAK
|
#ifdef CONFIG_KSTACK_ERASE
|
||||||
call stackleak_erase_on_task_stack
|
call stackleak_erase_on_task_stack
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
# This file was copied from arm64/kernel/pi/Makefile.
|
# This file was copied from arm64/kernel/pi/Makefile.
|
||||||
|
|
||||||
KBUILD_CFLAGS := $(subst $(CC_FLAGS_FTRACE),,$(KBUILD_CFLAGS)) -fpie \
|
KBUILD_CFLAGS := $(subst $(CC_FLAGS_FTRACE),,$(KBUILD_CFLAGS)) -fpie \
|
||||||
-Os -DDISABLE_BRANCH_PROFILING $(DISABLE_STACKLEAK_PLUGIN) \
|
-Os -DDISABLE_BRANCH_PROFILING $(DISABLE_KSTACK_ERASE) \
|
||||||
$(call cc-option,-mbranch-protection=none) \
|
$(call cc-option,-mbranch-protection=none) \
|
||||||
-I$(srctree)/scripts/dtc/libfdt -fno-stack-protector \
|
-I$(srctree)/scripts/dtc/libfdt -fno-stack-protector \
|
||||||
-include $(srctree)/include/linux/hidden.h \
|
-include $(srctree)/include/linux/hidden.h \
|
||||||
|
@ -53,7 +53,7 @@ targets += purgatory.ro purgatory.chk
|
|||||||
|
|
||||||
PURGATORY_CFLAGS_REMOVE := -mcmodel=kernel
|
PURGATORY_CFLAGS_REMOVE := -mcmodel=kernel
|
||||||
PURGATORY_CFLAGS := -mcmodel=medany -ffreestanding -fno-zero-initialized-in-bss
|
PURGATORY_CFLAGS := -mcmodel=medany -ffreestanding -fno-zero-initialized-in-bss
|
||||||
PURGATORY_CFLAGS += $(DISABLE_STACKLEAK_PLUGIN) -DDISABLE_BRANCH_PROFILING
|
PURGATORY_CFLAGS += $(DISABLE_KSTACK_ERASE) -DDISABLE_BRANCH_PROFILING
|
||||||
PURGATORY_CFLAGS += -fno-stack-protector -g0
|
PURGATORY_CFLAGS += -fno-stack-protector -g0
|
||||||
|
|
||||||
# Default KBUILD_CFLAGS can have -pg option set when FTRACE is enabled. That
|
# Default KBUILD_CFLAGS can have -pg option set when FTRACE is enabled. That
|
||||||
|
@ -176,10 +176,10 @@ config S390
|
|||||||
select HAVE_ARCH_KCSAN
|
select HAVE_ARCH_KCSAN
|
||||||
select HAVE_ARCH_KMSAN
|
select HAVE_ARCH_KMSAN
|
||||||
select HAVE_ARCH_KFENCE
|
select HAVE_ARCH_KFENCE
|
||||||
|
select HAVE_ARCH_KSTACK_ERASE
|
||||||
select HAVE_ARCH_RANDOMIZE_KSTACK_OFFSET
|
select HAVE_ARCH_RANDOMIZE_KSTACK_OFFSET
|
||||||
select HAVE_ARCH_SECCOMP_FILTER
|
select HAVE_ARCH_SECCOMP_FILTER
|
||||||
select HAVE_ARCH_SOFT_DIRTY
|
select HAVE_ARCH_SOFT_DIRTY
|
||||||
select HAVE_ARCH_STACKLEAK
|
|
||||||
select HAVE_ARCH_TRACEHOOK
|
select HAVE_ARCH_TRACEHOOK
|
||||||
select HAVE_ARCH_TRANSPARENT_HUGEPAGE
|
select HAVE_ARCH_TRANSPARENT_HUGEPAGE
|
||||||
select HAVE_ARCH_VMAP_STACK
|
select HAVE_ARCH_VMAP_STACK
|
||||||
|
@ -124,7 +124,7 @@ _LPP_OFFSET = __LC_LPP
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
.macro STACKLEAK_ERASE
|
.macro STACKLEAK_ERASE
|
||||||
#ifdef CONFIG_GCC_PLUGIN_STACKLEAK
|
#ifdef CONFIG_KSTACK_ERASE
|
||||||
brasl %r14,stackleak_erase_on_task_stack
|
brasl %r14,stackleak_erase_on_task_stack
|
||||||
#endif
|
#endif
|
||||||
.endm
|
.endm
|
||||||
|
@ -204,13 +204,13 @@ config X86
|
|||||||
select HAVE_ARCH_KFENCE
|
select HAVE_ARCH_KFENCE
|
||||||
select HAVE_ARCH_KMSAN if X86_64
|
select HAVE_ARCH_KMSAN if X86_64
|
||||||
select HAVE_ARCH_KGDB
|
select HAVE_ARCH_KGDB
|
||||||
|
select HAVE_ARCH_KSTACK_ERASE
|
||||||
select HAVE_ARCH_MMAP_RND_BITS if MMU
|
select HAVE_ARCH_MMAP_RND_BITS if MMU
|
||||||
select HAVE_ARCH_MMAP_RND_COMPAT_BITS if MMU && COMPAT
|
select HAVE_ARCH_MMAP_RND_COMPAT_BITS if MMU && COMPAT
|
||||||
select HAVE_ARCH_COMPAT_MMAP_BASES if MMU && COMPAT
|
select HAVE_ARCH_COMPAT_MMAP_BASES if MMU && COMPAT
|
||||||
select HAVE_ARCH_PREL32_RELOCATIONS
|
select HAVE_ARCH_PREL32_RELOCATIONS
|
||||||
select HAVE_ARCH_SECCOMP_FILTER
|
select HAVE_ARCH_SECCOMP_FILTER
|
||||||
select HAVE_ARCH_THREAD_STRUCT_WHITELIST
|
select HAVE_ARCH_THREAD_STRUCT_WHITELIST
|
||||||
select HAVE_ARCH_STACKLEAK
|
|
||||||
select HAVE_ARCH_TRACEHOOK
|
select HAVE_ARCH_TRACEHOOK
|
||||||
select HAVE_ARCH_TRANSPARENT_HUGEPAGE
|
select HAVE_ARCH_TRANSPARENT_HUGEPAGE
|
||||||
select HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD if X86_64
|
select HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD if X86_64
|
||||||
|
@ -369,7 +369,7 @@ For 32-bit we have the following conventions - kernel is built with
|
|||||||
.endm
|
.endm
|
||||||
|
|
||||||
.macro STACKLEAK_ERASE_NOCLOBBER
|
.macro STACKLEAK_ERASE_NOCLOBBER
|
||||||
#ifdef CONFIG_GCC_PLUGIN_STACKLEAK
|
#ifdef CONFIG_KSTACK_ERASE
|
||||||
PUSH_AND_CLEAR_REGS
|
PUSH_AND_CLEAR_REGS
|
||||||
call stackleak_erase
|
call stackleak_erase
|
||||||
POP_REGS
|
POP_REGS
|
||||||
@ -388,7 +388,7 @@ For 32-bit we have the following conventions - kernel is built with
|
|||||||
#endif /* !CONFIG_X86_64 */
|
#endif /* !CONFIG_X86_64 */
|
||||||
|
|
||||||
.macro STACKLEAK_ERASE
|
.macro STACKLEAK_ERASE
|
||||||
#ifdef CONFIG_GCC_PLUGIN_STACKLEAK
|
#ifdef CONFIG_KSTACK_ERASE
|
||||||
call stackleak_erase
|
call stackleak_erase
|
||||||
#endif
|
#endif
|
||||||
.endm
|
.endm
|
||||||
|
@ -35,7 +35,7 @@ targets += purgatory.ro purgatory.chk
|
|||||||
PURGATORY_CFLAGS_REMOVE := -mcmodel=kernel
|
PURGATORY_CFLAGS_REMOVE := -mcmodel=kernel
|
||||||
PURGATORY_CFLAGS := -mcmodel=small -ffreestanding -fno-zero-initialized-in-bss -g0
|
PURGATORY_CFLAGS := -mcmodel=small -ffreestanding -fno-zero-initialized-in-bss -g0
|
||||||
PURGATORY_CFLAGS += -fpic -fvisibility=hidden
|
PURGATORY_CFLAGS += -fpic -fvisibility=hidden
|
||||||
PURGATORY_CFLAGS += $(DISABLE_STACKLEAK_PLUGIN) -DDISABLE_BRANCH_PROFILING
|
PURGATORY_CFLAGS += $(DISABLE_KSTACK_ERASE) -DDISABLE_BRANCH_PROFILING
|
||||||
PURGATORY_CFLAGS += -fno-stack-protector
|
PURGATORY_CFLAGS += -fno-stack-protector
|
||||||
|
|
||||||
# Default KBUILD_CFLAGS can have -pg option set when FTRACE is enabled. That
|
# Default KBUILD_CFLAGS can have -pg option set when FTRACE is enabled. That
|
||||||
|
@ -22,16 +22,16 @@ cflags-$(CONFIG_X86) += -m$(BITS) -D__KERNEL__ -std=gnu11 \
|
|||||||
|
|
||||||
# arm64 uses the full KBUILD_CFLAGS so it's necessary to explicitly
|
# arm64 uses the full KBUILD_CFLAGS so it's necessary to explicitly
|
||||||
# disable the stackleak plugin
|
# disable the stackleak plugin
|
||||||
cflags-$(CONFIG_ARM64) += -fpie $(DISABLE_STACKLEAK_PLUGIN) \
|
cflags-$(CONFIG_ARM64) += -fpie $(DISABLE_KSTACK_ERASE) \
|
||||||
-fno-unwind-tables -fno-asynchronous-unwind-tables
|
-fno-unwind-tables -fno-asynchronous-unwind-tables
|
||||||
cflags-$(CONFIG_ARM) += -DEFI_HAVE_STRLEN -DEFI_HAVE_STRNLEN \
|
cflags-$(CONFIG_ARM) += -DEFI_HAVE_STRLEN -DEFI_HAVE_STRNLEN \
|
||||||
-DEFI_HAVE_MEMCHR -DEFI_HAVE_STRRCHR \
|
-DEFI_HAVE_MEMCHR -DEFI_HAVE_STRRCHR \
|
||||||
-DEFI_HAVE_STRCMP -fno-builtin -fpic \
|
-DEFI_HAVE_STRCMP -fno-builtin -fpic \
|
||||||
$(call cc-option,-mno-single-pic-base) \
|
$(call cc-option,-mno-single-pic-base) \
|
||||||
$(DISABLE_STACKLEAK_PLUGIN)
|
$(DISABLE_KSTACK_ERASE)
|
||||||
cflags-$(CONFIG_RISCV) += -fpic -DNO_ALTERNATIVE -mno-relax \
|
cflags-$(CONFIG_RISCV) += -fpic -DNO_ALTERNATIVE -mno-relax \
|
||||||
$(DISABLE_STACKLEAK_PLUGIN)
|
$(DISABLE_KSTACK_ERASE)
|
||||||
cflags-$(CONFIG_LOONGARCH) += -fpie $(DISABLE_STACKLEAK_PLUGIN)
|
cflags-$(CONFIG_LOONGARCH) += -fpie $(DISABLE_KSTACK_ERASE)
|
||||||
|
|
||||||
cflags-$(CONFIG_EFI_PARAMS_FROM_FDT) += -I$(srctree)/scripts/dtc/libfdt
|
cflags-$(CONFIG_EFI_PARAMS_FROM_FDT) += -I$(srctree)/scripts/dtc/libfdt
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@ lkdtm-$(CONFIG_LKDTM) += perms.o
|
|||||||
lkdtm-$(CONFIG_LKDTM) += refcount.o
|
lkdtm-$(CONFIG_LKDTM) += refcount.o
|
||||||
lkdtm-$(CONFIG_LKDTM) += rodata_objcopy.o
|
lkdtm-$(CONFIG_LKDTM) += rodata_objcopy.o
|
||||||
lkdtm-$(CONFIG_LKDTM) += usercopy.o
|
lkdtm-$(CONFIG_LKDTM) += usercopy.o
|
||||||
lkdtm-$(CONFIG_LKDTM) += stackleak.o
|
lkdtm-$(CONFIG_LKDTM) += kstack_erase.o
|
||||||
lkdtm-$(CONFIG_LKDTM) += cfi.o
|
lkdtm-$(CONFIG_LKDTM) += cfi.o
|
||||||
lkdtm-$(CONFIG_LKDTM) += fortify.o
|
lkdtm-$(CONFIG_LKDTM) += fortify.o
|
||||||
lkdtm-$(CONFIG_PPC_64S_HASH_MMU) += powerpc.o
|
lkdtm-$(CONFIG_PPC_64S_HASH_MMU) += powerpc.o
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
// SPDX-License-Identifier: GPL-2.0
|
// SPDX-License-Identifier: GPL-2.0
|
||||||
/*
|
/*
|
||||||
* This code tests that the current task stack is properly erased (filled
|
* This code tests that the current task stack is properly erased (filled
|
||||||
* with STACKLEAK_POISON).
|
* with KSTACK_ERASE_POISON).
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
* Alexander Popov <alex.popov@linux.com>
|
* Alexander Popov <alex.popov@linux.com>
|
||||||
@ -9,9 +9,9 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "lkdtm.h"
|
#include "lkdtm.h"
|
||||||
#include <linux/stackleak.h>
|
#include <linux/kstack_erase.h>
|
||||||
|
|
||||||
#if defined(CONFIG_GCC_PLUGIN_STACKLEAK)
|
#if defined(CONFIG_KSTACK_ERASE)
|
||||||
/*
|
/*
|
||||||
* Check that stackleak tracks the lowest stack pointer and erases the stack
|
* Check that stackleak tracks the lowest stack pointer and erases the stack
|
||||||
* below this as expected.
|
* below this as expected.
|
||||||
@ -85,7 +85,7 @@ static void noinstr check_stackleak_irqoff(void)
|
|||||||
while (poison_low > task_stack_low) {
|
while (poison_low > task_stack_low) {
|
||||||
poison_low -= sizeof(unsigned long);
|
poison_low -= sizeof(unsigned long);
|
||||||
|
|
||||||
if (*(unsigned long *)poison_low == STACKLEAK_POISON)
|
if (*(unsigned long *)poison_low == KSTACK_ERASE_POISON)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
instrumentation_begin();
|
instrumentation_begin();
|
||||||
@ -96,7 +96,7 @@ static void noinstr check_stackleak_irqoff(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
instrumentation_begin();
|
instrumentation_begin();
|
||||||
pr_info("stackleak stack usage:\n"
|
pr_info("kstack erase stack usage:\n"
|
||||||
" high offset: %lu bytes\n"
|
" high offset: %lu bytes\n"
|
||||||
" current: %lu bytes\n"
|
" current: %lu bytes\n"
|
||||||
" lowest: %lu bytes\n"
|
" lowest: %lu bytes\n"
|
||||||
@ -121,7 +121,7 @@ static void noinstr check_stackleak_irqoff(void)
|
|||||||
instrumentation_end();
|
instrumentation_end();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void lkdtm_STACKLEAK_ERASING(void)
|
static void lkdtm_KSTACK_ERASE(void)
|
||||||
{
|
{
|
||||||
unsigned long flags;
|
unsigned long flags;
|
||||||
|
|
||||||
@ -129,19 +129,19 @@ static void lkdtm_STACKLEAK_ERASING(void)
|
|||||||
check_stackleak_irqoff();
|
check_stackleak_irqoff();
|
||||||
local_irq_restore(flags);
|
local_irq_restore(flags);
|
||||||
}
|
}
|
||||||
#else /* defined(CONFIG_GCC_PLUGIN_STACKLEAK) */
|
#else /* defined(CONFIG_KSTACK_ERASE) */
|
||||||
static void lkdtm_STACKLEAK_ERASING(void)
|
static void lkdtm_KSTACK_ERASE(void)
|
||||||
{
|
{
|
||||||
if (IS_ENABLED(CONFIG_HAVE_ARCH_STACKLEAK)) {
|
if (IS_ENABLED(CONFIG_HAVE_ARCH_KSTACK_ERASE)) {
|
||||||
pr_err("XFAIL: stackleak is not enabled (CONFIG_GCC_PLUGIN_STACKLEAK=n)\n");
|
pr_err("XFAIL: stackleak is not enabled (CONFIG_KSTACK_ERASE=n)\n");
|
||||||
} else {
|
} else {
|
||||||
pr_err("XFAIL: stackleak is not supported on this arch (HAVE_ARCH_STACKLEAK=n)\n");
|
pr_err("XFAIL: stackleak is not supported on this arch (HAVE_ARCH_KSTACK_ERASE=n)\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif /* defined(CONFIG_GCC_PLUGIN_STACKLEAK) */
|
#endif /* defined(CONFIG_KSTACK_ERASE) */
|
||||||
|
|
||||||
static struct crashtype crashtypes[] = {
|
static struct crashtype crashtypes[] = {
|
||||||
CRASHTYPE(STACKLEAK_ERASING),
|
CRASHTYPE(KSTACK_ERASE),
|
||||||
};
|
};
|
||||||
|
|
||||||
struct crashtype_category stackleak_crashtypes = {
|
struct crashtype_category stackleak_crashtypes = {
|
@ -3291,7 +3291,7 @@ static int proc_pid_ksm_stat(struct seq_file *m, struct pid_namespace *ns,
|
|||||||
}
|
}
|
||||||
#endif /* CONFIG_KSM */
|
#endif /* CONFIG_KSM */
|
||||||
|
|
||||||
#ifdef CONFIG_STACKLEAK_METRICS
|
#ifdef CONFIG_KSTACK_ERASE_METRICS
|
||||||
static int proc_stack_depth(struct seq_file *m, struct pid_namespace *ns,
|
static int proc_stack_depth(struct seq_file *m, struct pid_namespace *ns,
|
||||||
struct pid *pid, struct task_struct *task)
|
struct pid *pid, struct task_struct *task)
|
||||||
{
|
{
|
||||||
@ -3304,7 +3304,7 @@ static int proc_stack_depth(struct seq_file *m, struct pid_namespace *ns,
|
|||||||
prev_depth, depth);
|
prev_depth, depth);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#endif /* CONFIG_STACKLEAK_METRICS */
|
#endif /* CONFIG_KSTACK_ERASE_METRICS */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Thread groups
|
* Thread groups
|
||||||
@ -3411,7 +3411,7 @@ static const struct pid_entry tgid_base_stuff[] = {
|
|||||||
#ifdef CONFIG_LIVEPATCH
|
#ifdef CONFIG_LIVEPATCH
|
||||||
ONE("patch_state", S_IRUSR, proc_pid_patch_state),
|
ONE("patch_state", S_IRUSR, proc_pid_patch_state),
|
||||||
#endif
|
#endif
|
||||||
#ifdef CONFIG_STACKLEAK_METRICS
|
#ifdef CONFIG_KSTACK_ERASE_METRICS
|
||||||
ONE("stack_depth", S_IRUGO, proc_stack_depth),
|
ONE("stack_depth", S_IRUGO, proc_stack_depth),
|
||||||
#endif
|
#endif
|
||||||
#ifdef CONFIG_PROC_PID_ARCH_STATUS
|
#ifdef CONFIG_PROC_PID_ARCH_STATUS
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/* SPDX-License-Identifier: GPL-2.0 */
|
/* SPDX-License-Identifier: GPL-2.0 */
|
||||||
#ifndef _LINUX_STACKLEAK_H
|
#ifndef _LINUX_KSTACK_ERASE_H
|
||||||
#define _LINUX_STACKLEAK_H
|
#define _LINUX_KSTACK_ERASE_H
|
||||||
|
|
||||||
#include <linux/sched.h>
|
#include <linux/sched.h>
|
||||||
#include <linux/sched/task_stack.h>
|
#include <linux/sched/task_stack.h>
|
||||||
@ -9,10 +9,10 @@
|
|||||||
* Check that the poison value points to the unused hole in the
|
* Check that the poison value points to the unused hole in the
|
||||||
* virtual memory map for your platform.
|
* virtual memory map for your platform.
|
||||||
*/
|
*/
|
||||||
#define STACKLEAK_POISON -0xBEEF
|
#define KSTACK_ERASE_POISON -0xBEEF
|
||||||
#define STACKLEAK_SEARCH_DEPTH 128
|
#define KSTACK_ERASE_SEARCH_DEPTH 128
|
||||||
|
|
||||||
#ifdef CONFIG_GCC_PLUGIN_STACKLEAK
|
#ifdef CONFIG_KSTACK_ERASE
|
||||||
#include <asm/stacktrace.h>
|
#include <asm/stacktrace.h>
|
||||||
#include <linux/linkage.h>
|
#include <linux/linkage.h>
|
||||||
|
|
||||||
@ -50,7 +50,7 @@ stackleak_task_high_bound(const struct task_struct *tsk)
|
|||||||
static __always_inline unsigned long
|
static __always_inline unsigned long
|
||||||
stackleak_find_top_of_poison(const unsigned long low, const unsigned long high)
|
stackleak_find_top_of_poison(const unsigned long low, const unsigned long high)
|
||||||
{
|
{
|
||||||
const unsigned int depth = STACKLEAK_SEARCH_DEPTH / sizeof(unsigned long);
|
const unsigned int depth = KSTACK_ERASE_SEARCH_DEPTH / sizeof(unsigned long);
|
||||||
unsigned int poison_count = 0;
|
unsigned int poison_count = 0;
|
||||||
unsigned long poison_high = high;
|
unsigned long poison_high = high;
|
||||||
unsigned long sp = high;
|
unsigned long sp = high;
|
||||||
@ -58,7 +58,7 @@ stackleak_find_top_of_poison(const unsigned long low, const unsigned long high)
|
|||||||
while (sp > low && poison_count < depth) {
|
while (sp > low && poison_count < depth) {
|
||||||
sp -= sizeof(unsigned long);
|
sp -= sizeof(unsigned long);
|
||||||
|
|
||||||
if (*(unsigned long *)sp == STACKLEAK_POISON) {
|
if (*(unsigned long *)sp == KSTACK_ERASE_POISON) {
|
||||||
poison_count++;
|
poison_count++;
|
||||||
} else {
|
} else {
|
||||||
poison_count = 0;
|
poison_count = 0;
|
||||||
@ -72,7 +72,7 @@ stackleak_find_top_of_poison(const unsigned long low, const unsigned long high)
|
|||||||
static inline void stackleak_task_init(struct task_struct *t)
|
static inline void stackleak_task_init(struct task_struct *t)
|
||||||
{
|
{
|
||||||
t->lowest_stack = stackleak_task_low_bound(t);
|
t->lowest_stack = stackleak_task_low_bound(t);
|
||||||
# ifdef CONFIG_STACKLEAK_METRICS
|
# ifdef CONFIG_KSTACK_ERASE_METRICS
|
||||||
t->prev_lowest_stack = t->lowest_stack;
|
t->prev_lowest_stack = t->lowest_stack;
|
||||||
# endif
|
# endif
|
||||||
}
|
}
|
||||||
@ -82,7 +82,7 @@ asmlinkage void noinstr stackleak_erase_on_task_stack(void);
|
|||||||
asmlinkage void noinstr stackleak_erase_off_task_stack(void);
|
asmlinkage void noinstr stackleak_erase_off_task_stack(void);
|
||||||
void __no_caller_saved_registers noinstr stackleak_track_stack(void);
|
void __no_caller_saved_registers noinstr stackleak_track_stack(void);
|
||||||
|
|
||||||
#else /* !CONFIG_GCC_PLUGIN_STACKLEAK */
|
#else /* !CONFIG_KSTACK_ERASE */
|
||||||
static inline void stackleak_task_init(struct task_struct *t) { }
|
static inline void stackleak_task_init(struct task_struct *t) { }
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -1607,8 +1607,10 @@ struct task_struct {
|
|||||||
/* Used by BPF for per-TASK xdp storage */
|
/* Used by BPF for per-TASK xdp storage */
|
||||||
struct bpf_net_context *bpf_net_context;
|
struct bpf_net_context *bpf_net_context;
|
||||||
|
|
||||||
#ifdef CONFIG_GCC_PLUGIN_STACKLEAK
|
#ifdef CONFIG_KSTACK_ERASE
|
||||||
unsigned long lowest_stack;
|
unsigned long lowest_stack;
|
||||||
|
#endif
|
||||||
|
#ifdef CONFIG_KSTACK_ERASE_METRICS
|
||||||
unsigned long prev_lowest_stack;
|
unsigned long prev_lowest_stack;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -139,11 +139,11 @@ obj-$(CONFIG_WATCH_QUEUE) += watch_queue.o
|
|||||||
obj-$(CONFIG_RESOURCE_KUNIT_TEST) += resource_kunit.o
|
obj-$(CONFIG_RESOURCE_KUNIT_TEST) += resource_kunit.o
|
||||||
obj-$(CONFIG_SYSCTL_KUNIT_TEST) += sysctl-test.o
|
obj-$(CONFIG_SYSCTL_KUNIT_TEST) += sysctl-test.o
|
||||||
|
|
||||||
CFLAGS_stackleak.o += $(DISABLE_STACKLEAK_PLUGIN)
|
CFLAGS_kstack_erase.o += $(DISABLE_KSTACK_ERASE)
|
||||||
obj-$(CONFIG_GCC_PLUGIN_STACKLEAK) += stackleak.o
|
obj-$(CONFIG_KSTACK_ERASE) += kstack_erase.o
|
||||||
KASAN_SANITIZE_stackleak.o := n
|
KASAN_SANITIZE_kstack_erase.o := n
|
||||||
KCSAN_SANITIZE_stackleak.o := n
|
KCSAN_SANITIZE_kstack_erase.o := n
|
||||||
KCOV_INSTRUMENT_stackleak.o := n
|
KCOV_INSTRUMENT_kstack_erase.o := n
|
||||||
|
|
||||||
obj-$(CONFIG_SCF_TORTURE_TEST) += scftorture.o
|
obj-$(CONFIG_SCF_TORTURE_TEST) += scftorture.o
|
||||||
|
|
||||||
|
@ -93,7 +93,7 @@
|
|||||||
#include <linux/kcov.h>
|
#include <linux/kcov.h>
|
||||||
#include <linux/livepatch.h>
|
#include <linux/livepatch.h>
|
||||||
#include <linux/thread_info.h>
|
#include <linux/thread_info.h>
|
||||||
#include <linux/stackleak.h>
|
#include <linux/kstack_erase.h>
|
||||||
#include <linux/kasan.h>
|
#include <linux/kasan.h>
|
||||||
#include <linux/scs.h>
|
#include <linux/scs.h>
|
||||||
#include <linux/io_uring.h>
|
#include <linux/io_uring.h>
|
||||||
|
@ -6,14 +6,14 @@
|
|||||||
*
|
*
|
||||||
* Author: Alexander Popov <alex.popov@linux.com>
|
* Author: Alexander Popov <alex.popov@linux.com>
|
||||||
*
|
*
|
||||||
* STACKLEAK reduces the information which kernel stack leak bugs can
|
* KSTACK_ERASE reduces the information which kernel stack leak bugs can
|
||||||
* reveal and blocks some uninitialized stack variable attacks.
|
* reveal and blocks some uninitialized stack variable attacks.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <linux/stackleak.h>
|
#include <linux/kstack_erase.h>
|
||||||
#include <linux/kprobes.h>
|
#include <linux/kprobes.h>
|
||||||
|
|
||||||
#ifdef CONFIG_STACKLEAK_RUNTIME_DISABLE
|
#ifdef CONFIG_KSTACK_ERASE_RUNTIME_DISABLE
|
||||||
#include <linux/jump_label.h>
|
#include <linux/jump_label.h>
|
||||||
#include <linux/string_choices.h>
|
#include <linux/string_choices.h>
|
||||||
#include <linux/sysctl.h>
|
#include <linux/sysctl.h>
|
||||||
@ -68,7 +68,7 @@ late_initcall(stackleak_sysctls_init);
|
|||||||
#define skip_erasing() static_branch_unlikely(&stack_erasing_bypass)
|
#define skip_erasing() static_branch_unlikely(&stack_erasing_bypass)
|
||||||
#else
|
#else
|
||||||
#define skip_erasing() false
|
#define skip_erasing() false
|
||||||
#endif /* CONFIG_STACKLEAK_RUNTIME_DISABLE */
|
#endif /* CONFIG_KSTACK_ERASE_RUNTIME_DISABLE */
|
||||||
|
|
||||||
#ifndef __stackleak_poison
|
#ifndef __stackleak_poison
|
||||||
static __always_inline void __stackleak_poison(unsigned long erase_low,
|
static __always_inline void __stackleak_poison(unsigned long erase_low,
|
||||||
@ -91,7 +91,7 @@ static __always_inline void __stackleak_erase(bool on_task_stack)
|
|||||||
erase_low = stackleak_find_top_of_poison(task_stack_low,
|
erase_low = stackleak_find_top_of_poison(task_stack_low,
|
||||||
current->lowest_stack);
|
current->lowest_stack);
|
||||||
|
|
||||||
#ifdef CONFIG_STACKLEAK_METRICS
|
#ifdef CONFIG_KSTACK_ERASE_METRICS
|
||||||
current->prev_lowest_stack = erase_low;
|
current->prev_lowest_stack = erase_low;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -113,7 +113,7 @@ static __always_inline void __stackleak_erase(bool on_task_stack)
|
|||||||
else
|
else
|
||||||
erase_high = task_stack_high;
|
erase_high = task_stack_high;
|
||||||
|
|
||||||
__stackleak_poison(erase_low, erase_high, STACKLEAK_POISON);
|
__stackleak_poison(erase_low, erase_high, KSTACK_ERASE_POISON);
|
||||||
|
|
||||||
/* Reset the 'lowest_stack' value for the next syscall */
|
/* Reset the 'lowest_stack' value for the next syscall */
|
||||||
current->lowest_stack = task_stack_high;
|
current->lowest_stack = task_stack_high;
|
||||||
@ -161,11 +161,11 @@ void __used __no_caller_saved_registers noinstr stackleak_track_stack(void)
|
|||||||
unsigned long sp = current_stack_pointer;
|
unsigned long sp = current_stack_pointer;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Having CONFIG_STACKLEAK_TRACK_MIN_SIZE larger than
|
* Having CONFIG_KSTACK_ERASE_TRACK_MIN_SIZE larger than
|
||||||
* STACKLEAK_SEARCH_DEPTH makes the poison search in
|
* KSTACK_ERASE_SEARCH_DEPTH makes the poison search in
|
||||||
* stackleak_erase() unreliable. Let's prevent that.
|
* stackleak_erase() unreliable. Let's prevent that.
|
||||||
*/
|
*/
|
||||||
BUILD_BUG_ON(CONFIG_STACKLEAK_TRACK_MIN_SIZE > STACKLEAK_SEARCH_DEPTH);
|
BUILD_BUG_ON(CONFIG_KSTACK_ERASE_TRACK_MIN_SIZE > KSTACK_ERASE_SEARCH_DEPTH);
|
||||||
|
|
||||||
/* 'lowest_stack' should be aligned on the register width boundary */
|
/* 'lowest_stack' should be aligned on the register width boundary */
|
||||||
sp = ALIGN(sp, sizeof(unsigned long));
|
sp = ALIGN(sp, sizeof(unsigned long));
|
@ -337,7 +337,7 @@ obj-$(CONFIG_UBSAN) += ubsan.o
|
|||||||
UBSAN_SANITIZE_ubsan.o := n
|
UBSAN_SANITIZE_ubsan.o := n
|
||||||
KASAN_SANITIZE_ubsan.o := n
|
KASAN_SANITIZE_ubsan.o := n
|
||||||
KCSAN_SANITIZE_ubsan.o := n
|
KCSAN_SANITIZE_ubsan.o := n
|
||||||
CFLAGS_ubsan.o := -fno-stack-protector $(DISABLE_STACKLEAK_PLUGIN)
|
CFLAGS_ubsan.o := -fno-stack-protector $(DISABLE_KSTACK_ERASE)
|
||||||
|
|
||||||
obj-$(CONFIG_SBITMAP) += sbitmap.o
|
obj-$(CONFIG_SBITMAP) += sbitmap.o
|
||||||
|
|
||||||
|
@ -12,15 +12,15 @@ gcc-plugin-$(CONFIG_GCC_PLUGIN_STACKLEAK) += stackleak_plugin.so
|
|||||||
gcc-plugin-cflags-$(CONFIG_GCC_PLUGIN_STACKLEAK) \
|
gcc-plugin-cflags-$(CONFIG_GCC_PLUGIN_STACKLEAK) \
|
||||||
+= -DSTACKLEAK_PLUGIN
|
+= -DSTACKLEAK_PLUGIN
|
||||||
gcc-plugin-cflags-$(CONFIG_GCC_PLUGIN_STACKLEAK) \
|
gcc-plugin-cflags-$(CONFIG_GCC_PLUGIN_STACKLEAK) \
|
||||||
+= -fplugin-arg-stackleak_plugin-track-min-size=$(CONFIG_STACKLEAK_TRACK_MIN_SIZE)
|
+= -fplugin-arg-stackleak_plugin-track-min-size=$(CONFIG_KSTACK_ERASE_TRACK_MIN_SIZE)
|
||||||
gcc-plugin-cflags-$(CONFIG_GCC_PLUGIN_STACKLEAK) \
|
gcc-plugin-cflags-$(CONFIG_GCC_PLUGIN_STACKLEAK) \
|
||||||
+= -fplugin-arg-stackleak_plugin-arch=$(SRCARCH)
|
+= -fplugin-arg-stackleak_plugin-arch=$(SRCARCH)
|
||||||
gcc-plugin-cflags-$(CONFIG_GCC_PLUGIN_STACKLEAK_VERBOSE) \
|
gcc-plugin-cflags-$(CONFIG_GCC_PLUGIN_STACKLEAK_VERBOSE) \
|
||||||
+= -fplugin-arg-stackleak_plugin-verbose
|
+= -fplugin-arg-stackleak_plugin-verbose
|
||||||
ifdef CONFIG_GCC_PLUGIN_STACKLEAK
|
ifdef CONFIG_GCC_PLUGIN_STACKLEAK
|
||||||
DISABLE_STACKLEAK_PLUGIN += -fplugin-arg-stackleak_plugin-disable
|
DISABLE_KSTACK_ERASE += -fplugin-arg-stackleak_plugin-disable
|
||||||
endif
|
endif
|
||||||
export DISABLE_STACKLEAK_PLUGIN
|
export DISABLE_KSTACK_ERASE
|
||||||
|
|
||||||
# All the plugin CFLAGS are collected here in case a build target needs to
|
# All the plugin CFLAGS are collected here in case a build target needs to
|
||||||
# filter them out of the KBUILD_CFLAGS.
|
# filter them out of the KBUILD_CFLAGS.
|
||||||
|
@ -82,10 +82,10 @@ choice
|
|||||||
|
|
||||||
endchoice
|
endchoice
|
||||||
|
|
||||||
config GCC_PLUGIN_STACKLEAK
|
config KSTACK_ERASE
|
||||||
bool "Poison kernel stack before returning from syscalls"
|
bool "Poison kernel stack before returning from syscalls"
|
||||||
|
depends on HAVE_ARCH_KSTACK_ERASE
|
||||||
depends on GCC_PLUGINS
|
depends on GCC_PLUGINS
|
||||||
depends on HAVE_ARCH_STACKLEAK
|
|
||||||
help
|
help
|
||||||
This option makes the kernel erase the kernel stack before
|
This option makes the kernel erase the kernel stack before
|
||||||
returning from system calls. This has the effect of leaving
|
returning from system calls. This has the effect of leaving
|
||||||
@ -103,6 +103,10 @@ config GCC_PLUGIN_STACKLEAK
|
|||||||
are advised to test this feature on your expected workload before
|
are advised to test this feature on your expected workload before
|
||||||
deploying it.
|
deploying it.
|
||||||
|
|
||||||
|
config GCC_PLUGIN_STACKLEAK
|
||||||
|
def_bool KSTACK_ERASE
|
||||||
|
depends on GCC_PLUGINS
|
||||||
|
help
|
||||||
This plugin was ported from grsecurity/PaX. More information at:
|
This plugin was ported from grsecurity/PaX. More information at:
|
||||||
* https://grsecurity.net/
|
* https://grsecurity.net/
|
||||||
* https://pax.grsecurity.net/
|
* https://pax.grsecurity.net/
|
||||||
@ -117,37 +121,37 @@ config GCC_PLUGIN_STACKLEAK_VERBOSE
|
|||||||
instrumented. This is useful for comparing coverage between
|
instrumented. This is useful for comparing coverage between
|
||||||
builds.
|
builds.
|
||||||
|
|
||||||
config STACKLEAK_TRACK_MIN_SIZE
|
config KSTACK_ERASE_TRACK_MIN_SIZE
|
||||||
int "Minimum stack frame size of functions tracked by STACKLEAK"
|
int "Minimum stack frame size of functions tracked by KSTACK_ERASE"
|
||||||
default 100
|
default 100
|
||||||
range 0 4096
|
range 0 4096
|
||||||
depends on GCC_PLUGIN_STACKLEAK
|
depends on KSTACK_ERASE
|
||||||
help
|
help
|
||||||
The STACKLEAK gcc plugin instruments the kernel code for tracking
|
The KSTACK_ERASE option instruments the kernel code for tracking
|
||||||
the lowest border of the kernel stack (and for some other purposes).
|
the lowest border of the kernel stack (and for some other purposes).
|
||||||
It inserts the stackleak_track_stack() call for the functions with
|
It inserts the stackleak_track_stack() call for the functions with
|
||||||
a stack frame size greater than or equal to this parameter.
|
a stack frame size greater than or equal to this parameter.
|
||||||
If unsure, leave the default value 100.
|
If unsure, leave the default value 100.
|
||||||
|
|
||||||
config STACKLEAK_METRICS
|
config KSTACK_ERASE_METRICS
|
||||||
bool "Show STACKLEAK metrics in the /proc file system"
|
bool "Show KSTACK_ERASE metrics in the /proc file system"
|
||||||
depends on GCC_PLUGIN_STACKLEAK
|
depends on KSTACK_ERASE
|
||||||
depends on PROC_FS
|
depends on PROC_FS
|
||||||
help
|
help
|
||||||
If this is set, STACKLEAK metrics for every task are available in
|
If this is set, KSTACK_ERASE metrics for every task are available
|
||||||
the /proc file system. In particular, /proc/<pid>/stack_depth
|
in the /proc file system. In particular, /proc/<pid>/stack_depth
|
||||||
shows the maximum kernel stack consumption for the current and
|
shows the maximum kernel stack consumption for the current and
|
||||||
previous syscalls. Although this information is not precise, it
|
previous syscalls. Although this information is not precise, it
|
||||||
can be useful for estimating the STACKLEAK performance impact for
|
can be useful for estimating the KSTACK_ERASE performance impact
|
||||||
your workloads.
|
for your workloads.
|
||||||
|
|
||||||
config STACKLEAK_RUNTIME_DISABLE
|
config KSTACK_ERASE_RUNTIME_DISABLE
|
||||||
bool "Allow runtime disabling of kernel stack erasing"
|
bool "Allow runtime disabling of kernel stack erasing"
|
||||||
depends on GCC_PLUGIN_STACKLEAK
|
depends on KSTACK_ERASE
|
||||||
help
|
help
|
||||||
This option provides 'stack_erasing' sysctl, which can be used in
|
This option provides 'stack_erasing' sysctl, which can be used in
|
||||||
runtime to control kernel stack erasing for kernels built with
|
runtime to control kernel stack erasing for kernels built with
|
||||||
CONFIG_GCC_PLUGIN_STACKLEAK.
|
CONFIG_KSTACK_ERASE.
|
||||||
|
|
||||||
config INIT_ON_ALLOC_DEFAULT_ON
|
config INIT_ON_ALLOC_DEFAULT_ON
|
||||||
bool "Enable heap memory zeroing on allocation by default"
|
bool "Enable heap memory zeroing on allocation by default"
|
||||||
|
@ -1192,7 +1192,7 @@ static const char *uaccess_safe_builtin[] = {
|
|||||||
"__ubsan_handle_type_mismatch_v1",
|
"__ubsan_handle_type_mismatch_v1",
|
||||||
"__ubsan_handle_shift_out_of_bounds",
|
"__ubsan_handle_shift_out_of_bounds",
|
||||||
"__ubsan_handle_load_invalid_value",
|
"__ubsan_handle_load_invalid_value",
|
||||||
/* STACKLEAK */
|
/* KSTACK_ERASE */
|
||||||
"stackleak_track_stack",
|
"stackleak_track_stack",
|
||||||
/* TRACE_BRANCH_PROFILING */
|
/* TRACE_BRANCH_PROFILING */
|
||||||
"ftrace_likely_update",
|
"ftrace_likely_update",
|
||||||
|
@ -2,7 +2,7 @@ CONFIG_LKDTM=y
|
|||||||
CONFIG_DEBUG_LIST=y
|
CONFIG_DEBUG_LIST=y
|
||||||
CONFIG_SLAB_FREELIST_HARDENED=y
|
CONFIG_SLAB_FREELIST_HARDENED=y
|
||||||
CONFIG_FORTIFY_SOURCE=y
|
CONFIG_FORTIFY_SOURCE=y
|
||||||
CONFIG_GCC_PLUGIN_STACKLEAK=y
|
CONFIG_KSTACK_ERASE=y
|
||||||
CONFIG_HARDENED_USERCOPY=y
|
CONFIG_HARDENED_USERCOPY=y
|
||||||
CONFIG_RANDOMIZE_KSTACK_OFFSET_DEFAULT=y
|
CONFIG_RANDOMIZE_KSTACK_OFFSET_DEFAULT=y
|
||||||
CONFIG_INIT_ON_FREE_DEFAULT_ON=y
|
CONFIG_INIT_ON_FREE_DEFAULT_ON=y
|
||||||
|
Loading…
Reference in New Issue
Block a user