Skip to content

Commit 73228c7

Browse files
Patricia Alfonsotorvalds
authored andcommitted
KASAN: port KASAN Tests to KUnit
Transfer all previous tests for KASAN to KUnit so they can be run more easily. Using kunit_tool, developers can run these tests with their other KUnit tests and see "pass" or "fail" with the appropriate KASAN report instead of needing to parse each KASAN report to test KASAN functionalities. All KASAN reports are still printed to dmesg. Stack tests do not work properly when KASAN_STACK is enabled so those tests use a check for "if IS_ENABLED(CONFIG_KASAN_STACK)" so they only run if stack instrumentation is enabled. If KASAN_STACK is not enabled, KUnit will print a statement to let the user know this test was not run with KASAN_STACK enabled. copy_user_test and kasan_rcu_uaf cannot be run in KUnit so there is a separate test file for those tests, which can be run as before as a module. [trishalfonso@google.com: v14] Link: https://lkml.kernel.org/r/20200915035828.570483-4-davidgow@google.com Signed-off-by: Patricia Alfonso <trishalfonso@google.com> Signed-off-by: David Gow <davidgow@google.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Tested-by: Andrey Konovalov <andreyknvl@google.com> Reviewed-by: Brendan Higgins <brendanhiggins@google.com> Reviewed-by: Andrey Konovalov <andreyknvl@google.com> Reviewed-by: Dmitry Vyukov <dvyukov@google.com> Cc: Andrey Ryabinin <aryabinin@virtuozzo.com> Cc: Ingo Molnar <mingo@redhat.com> Cc: Juri Lelli <juri.lelli@redhat.com> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Cc: Shuah Khan <shuah@kernel.org> Cc: Vincent Guittot <vincent.guittot@linaro.org> Link: https://lkml.kernel.org/r/20200910070331.3358048-4-davidgow@google.com Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 83c4e7a commit 73228c7

File tree

4 files changed

+386
-438
lines changed

4 files changed

+386
-438
lines changed

lib/Kconfig.kasan

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -166,12 +166,24 @@ config KASAN_VMALLOC
166166
for KASAN to detect more sorts of errors (and to support vmapped
167167
stacks), but at the cost of higher memory usage.
168168

169-
config TEST_KASAN
170-
tristate "Module for testing KASAN for bug detection"
171-
depends on m
169+
config KASAN_KUNIT_TEST
170+
tristate "KUnit-compatible tests of KASAN bug detection capabilities" if !KUNIT_ALL_TESTS
171+
depends on KASAN && KUNIT
172+
default KUNIT_ALL_TESTS
172173
help
173-
This is a test module doing various nasty things like
174-
out of bounds accesses, use after free. It is useful for testing
174+
This is a KUnit test suite doing various nasty things like
175+
out of bounds and use after free accesses. It is useful for testing
175176
kernel debugging features like KASAN.
176177

178+
For more information on KUnit and unit tests in general, please refer
179+
to the KUnit documentation in Documentation/dev-tools/kunit
180+
181+
config TEST_KASAN_MODULE
182+
tristate "KUnit-incompatible tests of KASAN bug detection capabilities"
183+
depends on m && KASAN
184+
help
185+
This is a part of the KASAN test suite that is incompatible with
186+
KUnit. Currently includes tests that do bad copy_from/to_user
187+
accesses.
188+
177189
endif # KASAN

lib/Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,11 @@ CFLAGS_test_bitops.o += -Werror
6565
obj-$(CONFIG_TEST_SYSCTL) += test_sysctl.o
6666
obj-$(CONFIG_TEST_HASH) += test_hash.o test_siphash.o
6767
obj-$(CONFIG_TEST_IDA) += test_ida.o
68-
obj-$(CONFIG_TEST_KASAN) += test_kasan.o
68+
obj-$(CONFIG_KASAN_KUNIT_TEST) += test_kasan.o
6969
CFLAGS_test_kasan.o += -fno-builtin
7070
CFLAGS_test_kasan.o += $(call cc-disable-warning, vla)
71+
obj-$(CONFIG_TEST_KASAN_MODULE) += test_kasan_module.o
72+
CFLAGS_test_kasan_module.o += -fno-builtin
7173
obj-$(CONFIG_TEST_UBSAN) += test_ubsan.o
7274
CFLAGS_test_ubsan.o += $(call cc-disable-warning, vla)
7375
UBSAN_SANITIZE_test_ubsan.o := y

0 commit comments

Comments
 (0)