* [PATCH] ext4: Fix potential null dereference in ext4 test
@ 2025-03-07 11:54 Charles Han
2025-03-10 9:35 ` Kemeng Shi
2025-03-21 5:08 ` Theodore Ts'o
0 siblings, 2 replies; 4+ messages in thread
From: Charles Han @ 2025-03-07 11:54 UTC (permalink / raw)
To: tytso, adilger.kernel, shikemeng; +Cc: linux-ext4, linux-kernel, 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")
Signed-off-by: Charles Han <hanchunchao@inspur.com>
---
fs/ext4/mballoc-test.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/fs/ext4/mballoc-test.c b/fs/ext4/mballoc-test.c
index bb2a223b207c..d634c12f1984 100644
--- a/fs/ext4/mballoc-test.c
+++ b/fs/ext4/mballoc-test.c
@@ -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);
--
2.43.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] ext4: Fix potential null dereference in ext4 test
@ 2025-03-08 12:32 Qasim Ijaz
0 siblings, 0 replies; 4+ messages in thread
From: Qasim Ijaz @ 2025-03-08 12:32 UTC (permalink / raw)
To: Charles Han; +Cc: adilger.kernel, tytso, linux-ext4, linux-kernel
On Fri, Mar 07, 2025 at 07:54:31PM +0800, Charles Han wrote:
> 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")
> Signed-off-by: Charles Han <hanchunchao@inspur.com>
> ---
> 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:
Link: <https://lore.kernel.org/linux-ext4/20250305124012.28500-1-qasdev00@gmail.com/T/#u>
Thanks,
Qasim
>
> diff --git a/fs/ext4/mballoc-test.c b/fs/ext4/mballoc-test.c
> index bb2a223b207c..d634c12f1984 100644
> --- a/fs/ext4/mballoc-test.c
> +++ b/fs/ext4/mballoc-test.c
> @@ -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);
> --
> 2.43.0
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] ext4: Fix potential null dereference in ext4 test
2025-03-07 11:54 Charles Han
@ 2025-03-10 9:35 ` Kemeng Shi
2025-03-21 5:08 ` Theodore Ts'o
1 sibling, 0 replies; 4+ messages in thread
From: Kemeng Shi @ 2025-03-10 9:35 UTC (permalink / raw)
To: Charles Han, tytso, adilger.kernel; +Cc: linux-ext4, linux-kernel
on 3/7/2025 7:54 PM, Charles Han wrote:
> 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")
> Signed-off-by: Charles Han <hanchunchao@inspur.com>
> ---
> fs/ext4/mballoc-test.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/fs/ext4/mballoc-test.c b/fs/ext4/mballoc-test.c
> index bb2a223b207c..d634c12f1984 100644
> --- a/fs/ext4/mballoc-test.c
> +++ b/fs/ext4/mballoc-test.c
> @@ -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);
>
Good catch, looks good to me.
Reviewed-by: Kemeng Shi <shikemeng@huaweicloud.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] ext4: Fix potential null dereference in ext4 test
2025-03-07 11:54 Charles Han
2025-03-10 9:35 ` Kemeng Shi
@ 2025-03-21 5:08 ` Theodore Ts'o
1 sibling, 0 replies; 4+ messages in thread
From: Theodore Ts'o @ 2025-03-21 5:08 UTC (permalink / raw)
To: Charles Han; +Cc: adilger.kernel, shikemeng, linux-ext4, linux-kernel
On Fri, Mar 07, 2025 at 07:54:31PM +0800, Charles Han wrote:
> kunit_kzalloc() may return a NULL pointer, dereferencing it without
> NULL check may lead to NULL dereference.
> Add a NULL check for test_state
Thanks, others have submitted the same fix. It's now fixed in my tree
and linux-next.
- Ted
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-03-21 5:09 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-08 12:32 [PATCH] ext4: Fix potential null dereference in ext4 test Qasim Ijaz
-- strict thread matches above, loose matches on Subject: below --
2025-03-07 11:54 Charles Han
2025-03-10 9:35 ` Kemeng Shi
2025-03-21 5:08 ` Theodore Ts'o
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox