test modules
Subsystems (2)
v2 cover test modules
This is a pair of test modules I'd like to see in the tree. Instead of putting these in lkdtm, where I've been adding various tests that trigger crashes, these don't make sense there since they need to be either distinctly separate, or their pass/fail state don't need to crash the machine.
These live in lib/ for now, along with a few other in-kernel test modules, and use the slightly more common "test_" naming convention, instead of "test-". We should likely standardize on the former:
$ find . -name 'test_*.c' | grep -v /tools/ | wc -l 4 $ find . -name 'test-*.c' | grep -v /tools/ | wc -l 2
The first is entirely a no-op module, designed to allow simple testing of the module loading and verification interface. It's useful to have a module that has no other uses or dependencies so it can be reliably used for just testing module loading and verification.
The second is a module that exercises the user memory access functions, in an effort to make sure that we can quickly catch any regressions in boundary checking (e.g. like what was recently fixed on ARM).
Thanks,
-Kees
PATCH v2 1/2 test: add minimal module for verification testing
When doing module loading verification tests (for example, with module singing, or LSM hooks), it is very handy to have a module that can be built on all systems under test, isn't auto-loaded at boot, and has no device or similar dependencies. This creates the "test_module.ko" module for that purpose, which only reports its load and unload to printk.
---
v2:
- use pr_warn, better comment, add headers explicitly, move to lib/; akpm.
--- lib/Kconfig.debug | 14 ++++++++++++++ lib/Makefile | 1 + lib/test_module.c | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+) create mode 100644 lib/test_module.c
lib/Kconfig.debug +14 -0
@@ -1578,6 +1578,20 @@ config DMA_API_DEBUG This option causes a performance degredation. Use only if you want to debug device drivers. If unsure, say N. +config TEST_MODULE + tristate "Test module loading with 'hello world' module" + default n + depends on m + help + This builds the "test_module" module that emits "Hello, world" + on printk when loaded. It is designed to be used for basic + evaluation of the module loading subsystem (for example when + validating module verification). It lacks any extra dependencies, + and will not normally be loaded by the system unless explicitly + requested by name. + + If unsure, say N. + source "samples/Kconfig" source "lib/Kconfig.kgdb"
lib/Makefile +1 -0
@@ -31,6 +31,7 @@ obj-y += string_helpers.o obj-$(CONFIG_TEST_STRING_HELPERS) += test-string_helpers.o obj-y += kstrtox.o obj-$(CONFIG_TEST_KSTRTOX) += test-kstrtox.o +obj-$(CONFIG_TEST_MODULE) += test_module.o ifeq ($(CONFIG_DEBUG_KOBJECT),y) CFLAGS_kobject.o += -DDEBUG
lib/test_module.c new file +33 -0
@@ -0,0 +1,33 @@ +/* +* This module emits "Hello, world" on printk when loaded. +* +* It is designed to be used for basic evaluation of the module loading +* subsystem (for example when validating module signing/verification). It +* lacks any extra dependencies, and will not normally be loaded by the +* system unless explicitly requested by name. +*/ + +#define pr_fmt (fmt) "test_module: " fmt + +#include <linux/init.h> +#include <linux/module.h> +#include <linux/printk.h> + +static int __init test_module_init (void ) +{ +pr_warn ("Hello, world\n" ); + +return 0 ; +} + +module_init (test_module_init); + +static void __exit test_module_exit(void) +{ +pr_warn ("Goodbye\n" ); +} + +module_exit (test_module_exit); + +MODULE_AUTHOR ("Kees Cook <[email protected]>" ); +MODULE_LICENSE ("GPL" );
Signature · 1 line
1.7.9.5
PATCH v2 2/2 test: check copy_to/from_user boundary validation
In reply to Kees CookTo help avoid an architecture failing to correctly check kernel/user boundaries when handling copy_to_user, copy_from_user, put_user, or get_user, perform some simple tests and fail to load if any of them behave unexpectedly.
Specifically, this is to make sure there is a way to notice if things like what was fixed in 8404663f81d212918ff85f493649a7991209fa04 ("ARM:
7527/1: uaccess: explicitly check __user pointer when !CPU_USE_DOMAINS") ever regresses again, for any architecture.
Additionally, adds new "user" selftest target, which loads this module.
---
v2:
- add sched.h for archs that define TASK_SIZE with more complexity
- add to selftests, move to lib/; akpm.
- clean up test macro, drop needless pr_warn; Joe Perches.
--- lib/Kconfig.debug | 13 ++++ lib/Makefile | 1 + lib/test_user_copy.c | 108 +++++++++++++++++++++++++++++++++ tools/testing/selftests/Makefile | 1 + tools/testing/selftests/user/Makefile | 13 ++++ 5 files changed, 136 insertions(+) create mode 100644 lib/test_user_copy.c create mode 100644 tools/testing/selftests/user/Makefile
lib/Kconfig.debug +13 -0
@@ -1592,6 +1592,19 @@ config TEST_MODULE If unsure, say N. +config TEST_USER_COPY + tristate "Test user/kernel boundary protections" + default n + depends on m + help + This builds the "test_user_copy" module that runs sanity checks + on the copy_to/from_user infrastructure, making sure basic + user/kernel boundary testing is working. If it fails to load, + a regression has been detected in the user/kernel memory boundary + protections. + + If unsure, say N. + source "samples/Kconfig" source "lib/Kconfig.kgdb"
lib/Makefile +1 -0
@@ -32,6 +32,7 @@ obj-$(CONFIG_TEST_STRING_HELPERS) += test-string_helpers.o obj-y += kstrtox.o obj-$(CONFIG_TEST_KSTRTOX) += test-kstrtox.o obj-$(CONFIG_TEST_MODULE) += test_module.o +obj-$(CONFIG_TEST_USER_COPY) += test_user_copy.o ifeq ($(CONFIG_DEBUG_KOBJECT),y) CFLAGS_kobject.o += -DDEBUG
lib/test_user_copy.c new file +108 -0
108 lines not on this page · raw message
tools/testing/selftests/Makefile +1 -0
@@ -9,6 +9,7 @@ TARGETS += ptrace TARGETS += timers TARGETS += vm TARGETS += powerpc +TARGETS += user all: for TARGET in $(TARGETS); do \
tools/testing/selftests/user/Makefile new file +13 -0
@@ -0,0 +1,13 @@ +# Makefile for user memory selftests + +# No binaries, but make sure arg-less "make" doesn't trigger "run_tests" +all: + +run_tests: all + @if /sbin/modprobe test_user_copy ; then \ + rmmod test_user_copy; \ + echo "user_copy: ok"; \ + else \ + echo "user_copy: [FAIL]"; \ + exit 1; \ + fi
Signature · 1 line
1.7.9.5