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

module: panic: Taint the kernel when selftest modules load

Taint the kernel with TAINT_TEST whenever a test module loads, by adding
a new "TEST" module property, and setting it for all modules in the
tools/testing directory. This property can also be set manually, for
tests which live outside the tools/testing directory with:
MODULE_INFO(test, "Y");

Reviewed-by: Luis Chamberlain <mcgrof@kernel.org>
Reviewed-by: Aaron Tomlin <atomlin@redhat.com>
Acked-by: Brendan Higgins <brendanhiggins@google.com>
Signed-off-by: David Gow <davidgow@google.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>

authored by

David Gow and committed by
Shuah Khan
74829ddf 77ce8ba3

+10
+7
kernel/module/main.c
··· 1988 1988 /* Set up license info based on the info section */ 1989 1989 set_license(mod, get_modinfo(info, "license")); 1990 1990 1991 + if (get_modinfo(info, "test")) { 1992 + if (!test_taint(TAINT_TEST)) 1993 + pr_warn("%s: loading test module taints kernel.\n", 1994 + mod->name); 1995 + add_taint_module(mod, TAINT_TEST, LOCKDEP_STILL_OK); 1996 + } 1997 + 1991 1998 return 0; 1992 1999 } 1993 2000
+3
scripts/mod/modpost.c
··· 2191 2191 2192 2192 if (strstarts(mod->name, "drivers/staging")) 2193 2193 buf_printf(b, "\nMODULE_INFO(staging, \"Y\");\n"); 2194 + 2195 + if (strstarts(mod->name, "tools/testing")) 2196 + buf_printf(b, "\nMODULE_INFO(test, \"Y\");\n"); 2194 2197 } 2195 2198 2196 2199 static void add_exported_symbols(struct buffer *buf, struct module *mod)