Skip to content

Commit cf6219e

Browse files
keesshuahkh
authored andcommitted
usercopy: Convert test_user_copy to KUnit test
Convert the runtime tests of hardened usercopy to standard KUnit tests. Additionally disable usercopy_test_invalid() for systems with separate address spaces (or no MMU) since it's not sensible to test for address confusion there (e.g. m68k). Co-developed-by: Vitor Massaru Iha <vitor@massaru.org> Signed-off-by: Vitor Massaru Iha <vitor@massaru.org> Link: https://lore.kernel.org/r/20200721174654.72132-1-vitor@massaru.org Tested-by: Ivan Orlov <ivan.orlov0322@gmail.com> Reviewed-by: David Gow <davidgow@google.com> Signed-off-by: Kees Cook <kees@kernel.org> Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
1 parent 51104c1 commit cf6219e

File tree

5 files changed

+340
-344
lines changed

5 files changed

+340
-344
lines changed

MAINTAINERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11962,6 +11962,7 @@ F: arch/*/configs/hardening.config
1196211962
F: include/linux/overflow.h
1196311963
F: include/linux/randomize_kstack.h
1196411964
F: kernel/configs/hardening.config
11965+
F: lib/usercopy_kunit.c
1196511966
F: mm/usercopy.c
1196611967
K: \b(add|choose)_random_kstack_offset\b
1196711968
K: \b__check_(object_size|heap_object)\b

lib/Kconfig.debug

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2505,18 +2505,6 @@ config TEST_VMALLOC
25052505

25062506
If unsure, say N.
25072507

2508-
config TEST_USER_COPY
2509-
tristate "Test user/kernel boundary protections"
2510-
depends on m
2511-
help
2512-
This builds the "test_user_copy" module that runs sanity checks
2513-
on the copy_to/from_user infrastructure, making sure basic
2514-
user/kernel boundary testing is working. If it fails to load,
2515-
a regression has been detected in the user/kernel memory boundary
2516-
protections.
2517-
2518-
If unsure, say N.
2519-
25202508
config TEST_BPF
25212509
tristate "Test BPF filter functionality"
25222510
depends on m && NET
@@ -2814,6 +2802,15 @@ config SIPHASH_KUNIT_TEST
28142802
This is intended to help people writing architecture-specific
28152803
optimized versions. If unsure, say N.
28162804

2805+
config USERCOPY_KUNIT_TEST
2806+
tristate "KUnit Test for user/kernel boundary protections"
2807+
depends on KUNIT
2808+
default KUNIT_ALL_TESTS
2809+
help
2810+
This builds the "usercopy_kunit" module that runs sanity checks
2811+
on the copy_to/from_user infrastructure, making sure basic
2812+
user/kernel boundary testing is working.
2813+
28172814
config TEST_UDELAY
28182815
tristate "udelay test driver"
28192816
help

lib/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ obj-$(CONFIG_TEST_LKM) += test_module.o
7878
obj-$(CONFIG_TEST_VMALLOC) += test_vmalloc.o
7979
obj-$(CONFIG_TEST_RHASHTABLE) += test_rhashtable.o
8080
obj-$(CONFIG_TEST_SORT) += test_sort.o
81-
obj-$(CONFIG_TEST_USER_COPY) += test_user_copy.o
8281
obj-$(CONFIG_TEST_STATIC_KEYS) += test_static_keys.o
8382
obj-$(CONFIG_TEST_STATIC_KEYS) += test_static_key_base.o
8483
obj-$(CONFIG_TEST_DYNAMIC_DEBUG) += test_dynamic_debug.o
@@ -388,6 +387,7 @@ CFLAGS_fortify_kunit.o += $(call cc-disable-warning, stringop-truncation)
388387
CFLAGS_fortify_kunit.o += $(DISABLE_STRUCTLEAK_PLUGIN)
389388
obj-$(CONFIG_FORTIFY_KUNIT_TEST) += fortify_kunit.o
390389
obj-$(CONFIG_SIPHASH_KUNIT_TEST) += siphash_kunit.o
390+
obj-$(CONFIG_USERCOPY_KUNIT_TEST) += usercopy_kunit.o
391391

392392
obj-$(CONFIG_GENERIC_LIB_DEVMEM_IS_ALLOWED) += devmem_is_allowed.o
393393

lib/test_user_copy.c

Lines changed: 0 additions & 331 deletions
This file was deleted.

0 commit comments

Comments
 (0)