selftest: Taint kernel when test module loaded
authorDavid Gow <davidgow@google.com>
Fri, 8 Jul 2022 04:48:47 +0000 (12:48 +0800)
committerShuah Khan <skhan@linuxfoundation.org>
Mon, 11 Jul 2022 22:58:11 +0000 (16:58 -0600)
commit8370b400f5abad168bcc541fa2574e7bd6b3bf2c
treebbdad05203afe0c7b2080343589e7a101480cf50
parent74829ddf5977567d77440150d72d4c0c5c427446
selftest: Taint kernel when test module loaded

Make any kselftest test module (using the kselftest_module framework)
taint the kernel with TAINT_TEST on module load.

Also mark the module as a test module using MODULE_INFO(test, "Y") so
that other tools can tell this is a test module. We can't rely solely
on this, though, as these test modules are also often built-in.

Finally, update the kselftest documentation to mention that the kernel
should be tainted, and how to do so manually (as below).

Note that several selftests use kernel modules which are not based on
the kselftest_module framework, and so will not automatically taint the
kernel.

This can be done in two ways:
- Moving the module to the tools/testing directory. All modules under
  this directory will taint the kernel.
- Adding the 'test' module property with:
  MODULE_INFO(test, "Y")

Similarly, selftests which do not load modules into the kernel generally
should not taint the kernel (or possibly should only do so on failure),
as it's assumed that testing from user-space should be safe. Regardless,
they can write to /proc/sys/kernel/tainted if required.

Reviewed-by: Luis Chamberlain <mcgrof@kernel.org>
Acked-by: Brendan Higgins <brendanhiggins@google.com>
Signed-off-by: David Gow <davidgow@google.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
Documentation/dev-tools/kselftest.rst
tools/testing/selftests/kselftest_module.h