linux/drivers/misc/lkdtm
Ard Biesheuvel 026c6fa1a5 lkdtm: avoid printk() in recursive_loop()
The recursive_loop() function is intended as a diagnostic to ensure that
exhausting the stack is caught and mitigated. Currently, it uses
pr_info() to ensure that the function has side effects that the compiler
cannot simply optimize away, so that the stack footprint does not get
reduced inadvertently.

The typical mitigation for stack overflow is to kill the task, and this
overflow may occur inside the call to pr_info(), which means it could be
holding the console lock when this happens. This means that the console
lock is never going to be released again, preventing the diagnostic
prints related to the stack overflow handling from being visible on the
console.

So let's replace the call to pr_info() with a call to
memzero_explicit(), which is not a 'magic' function name like memset()
or memcpy(), which the compiler may replace with plain loads and stores.
To ensure that the stack frames are nested rather than tail-called, put
the call to memzero_explicit() after the recursive call.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Kees Cook <keescook@chromium.org>
Link: https://lore.kernel.org/r/20211007081235.382697-1-ardb@kernel.org
2021-12-16 15:54:37 -08:00
..
bugs.c lkdtm: avoid printk() in recursive_loop() 2021-12-16 15:54:37 -08:00
cfi.c lkdtm: Add CONFIG hints in errors where possible 2021-06-24 15:32:08 +02:00
core.c lkdtm: Note that lkdtm_kernel_info should be removed in the future 2021-12-16 15:54:36 -08:00
fortify.c lkdtm/fortify: Consolidate FORTIFY_SOURCE tests 2021-08-18 22:28:51 +02:00
heap.c lkdtm/heap: Avoid __alloc_size hint warning for VMALLOC_LINEAR_OVERFLOW 2021-08-18 22:28:51 +02:00
lkdtm.h lkdtm/bugs: Check that a per-task stack canary exists 2021-10-25 09:13:46 +02:00
Makefile drivers/misc/lkdtm: disable LTO for rodata.o 2021-01-14 08:21:09 -08:00
perms.c lkdtm: Avoid more compiler optimizations for bad writes 2020-06-29 18:41:39 +02:00
powerpc.c lkdtm/powerpc: Add SLB multihit test 2020-12-04 01:01:34 +11:00
refcount.c lkdtm: Remove references to CONFIG_REFCOUNT_FULL 2019-11-25 09:15:46 +01:00
rodata.c lkdtm: don't move ctors to .rodata 2020-12-09 15:51:14 +01:00
stackleak.c lkdtm: Add CONFIG hints in errors where possible 2021-06-24 15:32:08 +02:00
usercopy.c lkdtm: Add CONFIG hints in errors where possible 2021-06-24 15:32:08 +02:00