Skip to content

Commit 57fbad1

Browse files
committed
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 <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Kees Cook <[email protected]>
1 parent fc07839 commit 57fbad1

File tree

37 files changed

+101
-95
lines changed

37 files changed

+101
-95
lines changed

Documentation/admin-guide/sysctl/kernel.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1465,15 +1465,15 @@ stack_erasing
14651465
=============
14661466

14671467
This parameter can be used to control kernel stack erasing at the end
1468-
of syscalls for kernels built with ``CONFIG_GCC_PLUGIN_STACKLEAK``.
1468+
of syscalls for kernels built with ``CONFIG_KSTACK_ERASE``.
14691469

14701470
That erasing reduces the information which kernel stack leak bugs
14711471
can reveal and blocks some uninitialized stack variable attacks.
14721472
The tradeoff is the performance impact: on a single CPU system kernel
14731473
compilation sees a 1% slowdown, other systems and workloads may vary.
14741474

14751475
= ====================================================================
1476-
0 Kernel stack erasing is disabled, STACKLEAK_METRICS are not updated.
1476+
0 Kernel stack erasing is disabled, KSTACK_ERASE_METRICS are not updated.
14771477
1 Kernel stack erasing is enabled (default), it is performed before
14781478
returning to the userspace at the end of syscalls.
14791479
= ====================================================================

Documentation/arch/x86/x86_64/mm.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,5 +176,5 @@ Be very careful vs. KASLR when changing anything here. The KASLR address
176176
range must not overlap with anything except the KASAN shadow area, which is
177177
correct as KASAN disables KASLR.
178178

179-
For both 4- and 5-level layouts, the STACKLEAK_POISON value in the last 2MB
179+
For both 4- and 5-level layouts, the KSTACK_ERASE_POISON value in the last 2MB
180180
hole: ffffffffffff4111

Documentation/security/self-protection.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ Memory poisoning
303303

304304
When releasing memory, it is best to poison the contents, to avoid reuse
305305
attacks that rely on the old contents of memory. E.g., clear stack on a
306-
syscall return (``CONFIG_GCC_PLUGIN_STACKLEAK``), wipe heap memory on a
306+
syscall return (``CONFIG_KSTACK_ERASE``), wipe heap memory on a
307307
free. This frustrates many uninitialized variable attacks, stack content
308308
exposures, heap content exposures, and use-after-free attacks.
309309

Documentation/translations/zh_CN/security/self-protection.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ KALLSYSM,则会直接打印原始地址。
259259
--------
260260

261261
在释放内存时,最好对内存内容进行清除处理,以防止攻击者重用内存中以前
262-
的内容。例如,在系统调用返回时清除堆栈(CONFIG_GCC_PLUGIN_STACKLEAK),
262+
的内容。例如,在系统调用返回时清除堆栈(CONFIG_KSTACK_ERASE),
263263
在释放堆内容是清除其内容。这有助于防止许多未初始化变量攻击、堆栈内容
264264
泄露、堆内容泄露以及使用后释放攻击(user-after-free)。
265265

MAINTAINERS

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9992,8 +9992,6 @@ L: [email protected]
99929992
S: Maintained
99939993
T: git git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux.git for-next/hardening
99949994
F: Documentation/kbuild/gcc-plugins.rst
9995-
F: include/linux/stackleak.h
9996-
F: kernel/stackleak.c
99979995
F: scripts/Makefile.gcc-plugins
99989996
F: scripts/gcc-plugins/
99999997

@@ -13087,10 +13085,12 @@ T: git git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux.git for-next/har
1308713085
F: Documentation/ABI/testing/sysfs-kernel-oops_count
1308813086
F: Documentation/ABI/testing/sysfs-kernel-warn_count
1308913087
F: arch/*/configs/hardening.config
13088+
F: include/linux/kstack_erase.h
1309013089
F: include/linux/overflow.h
1309113090
F: include/linux/randomize_kstack.h
1309213091
F: include/linux/ucopysize.h
1309313092
F: kernel/configs/hardening.config
13093+
F: kernel/kstack_erase.c
1309413094
F: lib/tests/randstruct_kunit.c
1309513095
F: lib/tests/usercopy_kunit.c
1309613096
F: mm/usercopy.c

arch/Kconfig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -630,11 +630,11 @@ config SECCOMP_CACHE_DEBUG
630630

631631
If unsure, say N.
632632

633-
config HAVE_ARCH_STACKLEAK
633+
config HAVE_ARCH_KSTACK_ERASE
634634
bool
635635
help
636636
An architecture should select this if it has the code which
637-
fills the used part of the kernel stack with the STACKLEAK_POISON
637+
fills the used part of the kernel stack with the KSTACK_ERASE_POISON
638638
value before returning from system calls.
639639

640640
config HAVE_STACKPROTECTOR

arch/arm/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,11 @@ config ARM
8787
select HAVE_ARCH_KGDB if !CPU_ENDIAN_BE32 && MMU
8888
select HAVE_ARCH_KASAN if MMU && !XIP_KERNEL
8989
select HAVE_ARCH_KASAN_VMALLOC if HAVE_ARCH_KASAN
90+
select HAVE_ARCH_KSTACK_ERASE
9091
select HAVE_ARCH_MMAP_RND_BITS if MMU
9192
select HAVE_ARCH_PFN_VALID
9293
select HAVE_ARCH_SECCOMP
9394
select HAVE_ARCH_SECCOMP_FILTER if AEABI && !OABI_COMPAT
94-
select HAVE_ARCH_STACKLEAK
9595
select HAVE_ARCH_THREAD_STRUCT_WHITELIST
9696
select HAVE_ARCH_TRACEHOOK
9797
select HAVE_ARCH_TRANSPARENT_HUGEPAGE if ARM_LPAE

arch/arm/boot/compressed/Makefile

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

1010
HEAD = head.o
1111
OBJS += misc.o decompress.o
12-
CFLAGS_decompress.o += $(DISABLE_STACKLEAK_PLUGIN)
12+
CFLAGS_decompress.o += $(DISABLE_KSTACK_ERASE)
1313
ifeq ($(CONFIG_DEBUG_UNCOMPRESS),y)
1414
OBJS += debug.o
1515
AFLAGS_head.o += -DDEBUG

arch/arm/kernel/entry-common.S

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ no_work_pending:
119119

120120
ct_user_enter save = 0
121121

122-
#ifdef CONFIG_GCC_PLUGIN_STACKLEAK
122+
#ifdef CONFIG_KSTACK_ERASE
123123
bl stackleak_erase_on_task_stack
124124
#endif
125125
restore_user_regs fast = 0, offset = 0

arch/arm64/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,12 +187,12 @@ config ARM64
187187
select HAVE_ARCH_KCSAN if EXPERT
188188
select HAVE_ARCH_KFENCE
189189
select HAVE_ARCH_KGDB
190+
select HAVE_ARCH_KSTACK_ERASE
190191
select HAVE_ARCH_MMAP_RND_BITS
191192
select HAVE_ARCH_MMAP_RND_COMPAT_BITS if COMPAT
192193
select HAVE_ARCH_PREL32_RELOCATIONS
193194
select HAVE_ARCH_RANDOMIZE_KSTACK_OFFSET
194195
select HAVE_ARCH_SECCOMP_FILTER
195-
select HAVE_ARCH_STACKLEAK
196196
select HAVE_ARCH_THREAD_STRUCT_WHITELIST
197197
select HAVE_ARCH_TRACEHOOK
198198
select HAVE_ARCH_TRANSPARENT_HUGEPAGE

0 commit comments

Comments
 (0)