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

selftests/lkdtm: Disable CONFIG_UBSAN_TRAP in test config

The lkdtm selftest config fragment enables CONFIG_UBSAN_TRAP to make the
ARRAY_BOUNDS test kill the calling process when an out-of-bound access
is detected by UBSAN. However, after this [1] commit, UBSAN is triggered
under many new scenarios that weren't detected before, such as in struct
definitions with fixed-size trailing arrays used as flexible arrays. As
a result, CONFIG_UBSAN_TRAP=y has become a very aggressive option to
enable except for specific situations.

`make kselftest-merge` applies CONFIG_UBSAN_TRAP=y to the kernel config
for all selftests, which makes many of them fail because of system hangs
during boot.

This change removes the config option from the lkdtm kselftest and
configures the ARRAY_BOUNDS test to look for UBSAN reports rather than
relying on the calling process being killed.

[1] commit 2d47c6956ab3 ("ubsan: Tighten UBSAN_BOUNDS on GCC")'

Signed-off-by: Ricardo Cañuelo <ricardo.canuelo@collabora.com>
Reviewed-by: Kees Cook <keescook@chromium.org>
Link: https://lore.kernel.org/r/20230802063252.1917997-1-ricardo.canuelo@collabora.com
Signed-off-by: Kees Cook <keescook@chromium.org>

authored by

Ricardo Cañuelo and committed by
Kees Cook
cf77bf69 eac80dd4

+1 -2
-1
tools/testing/selftests/lkdtm/config
··· 9 9 CONFIG_INIT_ON_ALLOC_DEFAULT_ON=y 10 10 CONFIG_UBSAN=y 11 11 CONFIG_UBSAN_BOUNDS=y 12 - CONFIG_UBSAN_TRAP=y 13 12 CONFIG_STACKPROTECTOR_STRONG=y 14 13 CONFIG_SLUB_DEBUG=y 15 14 CONFIG_SLUB_DEBUG_ON=y
+1 -1
tools/testing/selftests/lkdtm/tests.txt
··· 8 8 #EXHAUST_STACK Corrupts memory on failure 9 9 #CORRUPT_STACK Crashes entire system on success 10 10 #CORRUPT_STACK_STRONG Crashes entire system on success 11 - ARRAY_BOUNDS 11 + ARRAY_BOUNDS call trace:|UBSAN: array-index-out-of-bounds 12 12 CORRUPT_LIST_ADD list_add corruption 13 13 CORRUPT_LIST_DEL list_del corruption 14 14 STACK_GUARD_PAGE_LEADING