Skip to contentSkip to conversation

ext4: Fix potential null dereference in ext4 test

PATCH Qasim Ijaz 1 participant 1 message Mar 8, 2025

lore
Share & tools
lore

Qasim Ijaz

author
#0 lore raw
Quoted 10 lines · Charles Han

kunit_kzalloc() may return a NULL pointer, dereferencing it without NULL check may lead to NULL dereference.
Add a NULL check for test_state

Fixes b7098e1fa7bc ("ext4: Add unit test for mb_free_blocks")
Fixes ac96b56a2fbd ("ext4: Add unit test for mb_mark_used")
---
 fs/ext4/mballoc-test.c | 2 ++
 1 file changed, 2 insertions(+)

Hi Charles,

I already submitted a patch for this on 5th March, link below:

Thanks,
Qasim

Quoted 24 lines
fs/ext4/mballoc-test.c +2 -0
index bb2a223b207c..d634c12f1984 100644
@@ -796,6 +796,7 @@ static void test_mb_mark_used(struct kunit *test)
 	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, buddy);
 	grp = kunit_kzalloc(test, offsetof(struct ext4_group_info,
 				bb_counters[MB_NUM_ORDERS(sb)]), GFP_KERNEL);
+	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, grp);
 
 	ret = ext4_mb_load_buddy(sb, TEST_GOAL_GROUP, &e4b);
 	KUNIT_ASSERT_EQ(test, ret, 0);
@@ -860,6 +861,7 @@ static void test_mb_free_blocks(struct kunit *test)
 	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, buddy);
 	grp = kunit_kzalloc(test, offsetof(struct ext4_group_info,
 				bb_counters[MB_NUM_ORDERS(sb)]), GFP_KERNEL);
+	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, grp);
 
 	ret = ext4_mb_load_buddy(sb, TEST_GOAL_GROUP, &e4b);
 	KUNIT_ASSERT_EQ(test, ret, 0);
Signature · 1 line
2.43.0