[PATCH] kunit: fix NULL dereference when glob filter matches no tests
From: Jiangshan Yi
Date: Mon Nov 16 2026 - 22:52:28 EST
When a suite glob matches a suite but its test glob matches none of the
suite's tests, kunit_filter_glob_tests() returns NULL.
kunit_filter_suites() only checks IS_ERR(), so the NULL passes into
kunit_filter_attr_tests() and is dereferenced by kmemdup() in memcpy().
Skip the suite when the glob filter returns NULL. Keep the existing NULL
check after the attribute filter, which covers suites whose tests are all
removed by attributes.
Fixes: 529534e8cba3 ("kunit: Add ability to filter attributes")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Jiangshan Yi <yijiangshan@xxxxxxxxxx>
---
lib/kunit/executor.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/lib/kunit/executor.c b/lib/kunit/executor.c
index c798a02470d8..3a281af3cda8 100644
--- a/lib/kunit/executor.c
+++ b/lib/kunit/executor.c
@@ -226,6 +226,9 @@ kunit_filter_suites(const struct kunit_suite_set *suite_set,
*err = PTR_ERR(filtered_suite);
goto free_filtered_suite;
}
+ /* Skip this suite if the glob filter matched no tests. */
+ if (!filtered_suite)
+ continue;
}
if (filter_count > 0 && parsed_filters != NULL) {
for (k = 0; k < filter_count; k++) {
--
2.25.1