Skip to contentSkip to conversation

kunit-taint-the-kernel-when-kunit-tests-are-run.patch removed from -mm tree

merged Andrew Morton 1 participant 1 message Jul 13, 2022

lore
Share & tools
lore

Andrew Morton

author tree notice Applied
#0 lore raw

The quilt patch titled
Subject: kunit: taint the kernel when KUnit tests are run
has been removed from the -mm tree. Its filename was
kunit-taint-the-kernel-when-kunit-tests-are-run.patch

This patch was dropped because it was merged into mainline or a subsystem tree

------------------------------------------------------
From: David Gow <[email protected]>
Subject: kunit: taint the kernel when KUnit tests are run
Date: Fri, 8 Jul 2022 12:48:46 +0800

Make KUnit trigger the new TAINT_TEST taint when any KUnit test is run. Due to KUnit tests not being intended to run on production systems, and potentially causing problems (or security issues like leaking kernel addresses), the kernel's state should not be considered safe for production use after KUnit tests are run.

This both marks KUnit modules as test modules using MODULE_INFO() and manually taints the kernel when tests are run (which catches builtin tests).

Cc Aaron Tomlin <[email protected]>
Cc Andy Shevchenko <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc Guilherme G. Piccoli <[email protected]>
Cc Jani Nikula <[email protected]>
Cc John Ogness <[email protected]>
Cc Jonathan Corbet <[email protected]>
Cc Kees Cook <[email protected]>
Cc Lucas De Marchi <[email protected]>
Cc Masahiro Yamada <[email protected]>
Cc Michal Marek <[email protected]>
Cc Nathan Chancellor <[email protected]>
Cc Nick Desaulniers <[email protected]>
Cc Sebastian Reichel <[email protected]>
Cc Shuah Khan <[email protected]>

---

 include/kunit/test.h |    3 ++-
 lib/kunit/test.c     |    4 ++++
 2 files changed, 6 insertions(+), 1 deletion(-)
include/kunit/test.h renamed from include/kunit/test.h~kunit-taint-the-kernel-when-kunit-tests-are-run +2 -1
@@ -277,7 +277,8 @@ static inline int kunit_run_all_tests(vo
 	{								\
 		return __kunit_test_suites_exit(__suites);		\
 	}								\
-	module_exit(kunit_test_suites_exit)
+	module_exit(kunit_test_suites_exit)				\
+	MODULE_INFO(test, "Y");
 #else
 #define kunit_test_suites_for_module(__suites)
 #endif /* MODULE */
lib/kunit/test.c renamed from lib/kunit/test.c~kunit-taint-the-kernel-when-kunit-tests-are-run +4 -0
@@ -11,6 +11,7 @@
 #include <kunit/test-bug.h>
 #include <linux/kernel.h>
 #include <linux/moduleparam.h>
+#include <linux/panic.h>
 #include <linux/sched/debug.h>
 #include <linux/sched.h>
 
@@ -501,6 +502,9 @@ int kunit_run_tests(struct kunit_suite *
 	struct kunit_result_stats suite_stats = { 0 };
 	struct kunit_result_stats total_stats = { 0 };
 
+	/* Taint the kernel so we know we've run tests. */
+	add_taint(TAINT_TEST, LOCKDEP_STILL_OK);
+
 	if (suite->suite_init) {
 		suite->suite_init_err = suite->suite_init(suite);
 		if (suite->suite_init_err) {

_

Patches currently in -mm which might be from [email protected] are

selftest-taint-kernel-when-test-module-loaded.patch