[PATCH 2/3] kunit: fix NULL pointer dereference when filtering on module
From: Miao Tianzhong
Date: Thu Dec 03 2026 - 21:57:08 EST
kunit_filter_attr_tests() evaluates the attribute filter for the test,
suite and default attribute values. A test case that has no module_name
(or a suite whose first test case has none) produces a NULL attribute
value, and attr_string_filter() passes it to strcmp(), which dereferences
NULL and panics the kernel.
Treat a NULL string attribute as an empty string, which matches the
default value used for the module attribute.
Fixes: 529534e8cba3 ("kunit: Add ability to filter attributes")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Miao Tianzhong <3514767322@xxxxxx>
---
lib/kunit/attributes.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/lib/kunit/attributes.c b/lib/kunit/attributes.c
index 9d368a2844d8..1b26374a018f 100644
--- a/lib/kunit/attributes.c
+++ b/lib/kunit/attributes.c
@@ -158,6 +158,9 @@ static int attr_string_filter(void *attr, const char *input, int *err)
{
char *str = attr;
+ if (!str)
+ str = "";
+
if (!strncmp(input, "<", 1)) {
*err = -EINVAL;
pr_err("kunit executor: invalid filter input: %s\n", input);
--
2.56.1