kunit_kcalloc() may fail. parse_filter_attr_test() uses the returned pointer without checking it, and then writes to parsed_filters[j], which can lead to a NULL pointer dereference under low-memory conditions.
Use KUNIT_ASSERT_NOT_ERR_OR_NULL() to abort the test on allocation failure, per KUnit guidance for unsafe-to-continue cases.
Fixes: 1c9fd080dffe ("kunit: fix uninitialized variables bug in attributes filtering") Fixes: 76066f93f1df ("kunit: add tests for filtering attributes") Signed-off-by: Guangshuo Li lgs201920130244@gmail.com --- lib/kunit/executor_test.c | 4 ++++ 1 file changed, 4 insertions(+)
diff --git a/lib/kunit/executor_test.c b/lib/kunit/executor_test.c index f0090c2729cd..084636ad8a72 100644 --- a/lib/kunit/executor_test.c +++ b/lib/kunit/executor_test.c @@ -127,6 +127,10 @@ static void parse_filter_attr_test(struct kunit *test)
parsed_filters = kunit_kcalloc(test, filter_count, sizeof(*parsed_filters), GFP_KERNEL); + + /* Abort test if allocation failed. */ + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, parsed_filters); + for (j = 0; j < filter_count; j++) { parsed_filters[j] = kunit_next_attr_filter(&filter, &err); KUNIT_ASSERT_EQ_MSG(test, err, 0, "failed to parse filter from '%s'", filters);
linux-kselftest-mirror@lists.linaro.org