Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

mm, slub, kasan: enable user tracking by default with KASAN=y

It's recommended to have slub's user tracking enabled with CONFIG_KASAN,
because:

a) User tracking disables slab merging which improves
detecting out-of-bounds accesses.
b) User tracking metadata acts as redzone which also improves
detecting out-of-bounds accesses.
c) User tracking provides additional information about object.
This information helps to understand bugs.

Currently it is not enabled by default. Besides recompiling the kernel
with KASAN and reinstalling it, user also have to change the boot cmdline,
which is not very handy.

Enable slub user tracking by default with KASAN=y, since there is no good
reason to not do this.

[akpm@linux-foundation.org: little fixes, per David]
Signed-off-by: Andrey Ryabinin <aryabinin@virtuozzo.com>
Cc: Christoph Lameter <cl@linux.com>
Cc: Pekka Enberg <penberg@kernel.org>
Cc: David Rientjes <rientjes@google.com>
Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Andrey Ryabinin and committed by
Linus Torvalds
89d3c87e 10f70262

+5 -5
+1 -2
Documentation/kasan.txt
··· 28 28 version 5.0 or later. 29 29 30 30 Currently KASAN works only with the SLUB memory allocator. 31 - For better bug detection and nicer report, enable CONFIG_STACKTRACE and put 32 - at least 'slub_debug=U' in the boot cmdline. 31 + For better bug detection and nicer reporting, enable CONFIG_STACKTRACE. 33 32 34 33 To disable instrumentation for specific files or directories, add a line 35 34 similar to the following to the respective kernel Makefile:
+1 -2
lib/Kconfig.kasan
··· 15 15 global variables requires gcc 5.0 or later. 16 16 This feature consumes about 1/8 of available memory and brings about 17 17 ~x3 performance slowdown. 18 - For better error detection enable CONFIG_STACKTRACE, 19 - and add slub_debug=U to boot cmdline. 18 + For better error detection enable CONFIG_STACKTRACE. 20 19 21 20 choice 22 21 prompt "Instrumentation type"
+3 -1
mm/slub.c
··· 459 459 /* 460 460 * Debug settings: 461 461 */ 462 - #ifdef CONFIG_SLUB_DEBUG_ON 462 + #if defined(CONFIG_SLUB_DEBUG_ON) 463 463 static int slub_debug = DEBUG_DEFAULT_FLAGS; 464 + #elif defined(CONFIG_KASAN) 465 + static int slub_debug = SLAB_STORE_USER; 464 466 #else 465 467 static int slub_debug; 466 468 #endif