Skip to contentSkip to conversation

kunit: test: Use an action wrapper instead of a cast

PATCH In review David Gow 2 participants 2 messages Dec 6, 2023 – Dec 8, 2023

Subsystems (2)
lore
Share & tools
lore

David Gow

author
#0 lore raw

PATCH 1/1 kunit: test: Use an action wrapper instead of a cast

We missed one of the casts of kfree() to kunit_action_t in kunit-test, which was only enabled when debugfs was in use. This could potentially break CFI.

Use the existing wrapper function instead.

---
 lib/kunit/kunit-test.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/kunit/kunit-test.c +1 -1
index 3e9c5192d095..ee6927c60979 100644
@@ -559,7 +559,7 @@ static void kunit_log_test(struct kunit *test)
 	KUNIT_EXPECT_TRUE(test, test->log->append_newlines);
 
 	full_log = string_stream_get_string(test->log);
-	kunit_add_action(test, (kunit_action_t *)kfree, full_log);
+	kunit_add_action(test, kfree_wrapper, full_log);
 	KUNIT_EXPECT_NOT_ERR_OR_NULL(test,
 				     strstr(full_log, "put this in log."));
 	KUNIT_EXPECT_NOT_ERR_OR_NULL(test,
Signature · 1 line
2.43.0.rc2.451.g8631bc7472-goog
Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · David Gow

We missed one of the casts of kfree() to kunit_action_t in kunit-test, which was only enabled when debugfs was in use. This could potentially break CFI.

Use the existing wrapper function instead.

Hello!

This looks good to me. All ready to go.

Thanks!
-Rae

Quoted 20 lines
---
 lib/kunit/kunit-test.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/kunit/kunit-test.c +1 -2
index 3e9c5192d095..ee6927c60979 100644
@@ -559,7 +559,7 @@ static void kunit_log_test(struct kunit *test)
        KUNIT_EXPECT_TRUE(test, test->log->append_newlines);
 
        full_log = string_stream_get_string(test->log);
-       kunit_add_action(test, (kunit_action_t *)kfree, full_log);
+       kunit_add_action(test, kfree_wrapper, full_log);
        KUNIT_EXPECT_NOT_ERR_OR_NULL(test,
                                     strstr(full_log, "put this in log."));
        KUNIT_EXPECT_NOT_ERR_OR_NULL(test,
--

2.43.0.rc2.451.g8631bc7472-goog