test modules
Subsystems (2)
v3 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 v3 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.
---
v3:
- use KBUILD_MODNAME; Rusty Russell
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) KBUILD_MODNAME ": " 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
Re: [PATCH v3 1/2] test: add minimal module for verification testing
Quoted 2 lines · Kees Cook
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
"module singing" sounds like a horrible idea! Is the author even musical? I've only heard it said David Howls.
But if my ack for the patch helps:
Cheers,
Rusty.
Quoted 95 lines
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.
Signed-off-by Kees Cook <[email protected]>---
v3:
- useKBUILD_MODNAME; Rusty Russell
v2:
- usepr_warn, better comment, add headers explicitly, move tolib/; akpm.--- lib/Kconfig.debug | 14 ++++++++++++++ lib/Makefile | 1 + lib/test_module.c | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+) create mode 100644 lib/test_module.clib/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 += -DDEBUGlib/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) KBUILD_MODNAME ": " 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
Andrew Morton
maintainerRe: [PATCH v3 1/2] test: add minimal module for verification testing
Quoted 6 lines · On Thu, 05 Dec 2013 13:12:17 +1030 Rusty Russell <[email protected]> wrote:
Quoted 2 lines · Kees Cook
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
"module singing" sounds like a horrible idea! Is the author even musical? I've only heard it said David Howls.
You're such a killjoy.
btw, git log | grep Singed
Re: [PATCH v3 1/2] test: add minimal module for verification testing
Quoted 6 lines · Andrew Morton
Quoted 4 lines · On Thu, 05 Dec 2013 13:12:17 +1030 Rusty Russell <[email protected]> wrote:
Quoted 2 lines · Kees Cook
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
Quoted 6 lines
Quoted 2 lines
"module singing" sounds like a horrible idea! Is the author even musical? I've only heard it said David Howls.
You're such a killjoy.
btw, git log | grep Singed
I had my ego singed off by Linus once, so I completely understand.
Cheers,
Rusty.
Re: [PATCH v3 1/2] test: add minimal module for verification testing
In reply to Rusty RussellQuoted 5 lines · Rusty Russell
Quoted 2 lines · Kees Cook
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
"module singing" sounds like a horrible idea! Is the author even
Haha, ugh. Yay for typos :)
Quoted 1 line
musical? I've only heard it said David Howls.
*rimshot*
Quoted 3 lines
But if my ack for the patch helps:
Acked-by Rusty Russell <[email protected]>
Thanks!
-Kees
Signature · 2 lines
Kees Cook Chrome OS Security
PATCH v3 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.
---
v3:
- use KBUILD_MODNAME; Rusty Russell
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