* [PATCH] btrfs: tests: zoned: fix NULL check of the active bitmap
@ 2026-11-17 3:51 Yifan Feng
2026-11-17 4:35 ` Qu Wenruo
2026-11-17 5:00 ` Naohiro Aota
0 siblings, 2 replies; 3+ messages in thread
From: Yifan Feng @ 2026-11-17 3:51 UTC (permalink / raw)
To: David Sterba
Cc: Chris Mason, Naohiro Aota, Johannes Thumshirn, linux-btrfs,
linux-kernel, Yifan Feng
test_load_zone_info() allocates the active bitmap with bitmap_zalloc()
but then tests zone_info, which was already checked a few lines above.
A failed allocation is not detected, and the NULL bitmap is then used
by __set_bit() and by btrfs_load_block_group_by_raid_type().
Check the active bitmap instead.
Tested in QEMU with the bitmap size temporarily changed to UINT_MAX so
that the allocation fails. Without this patch the kernel oopses in
btrfs_test_zoned() with a NULL pointer dereference. With it the test
prints "cannot allocate active bitmap" and fails cleanly.
Found by searching for a NULL check that tests a different pointer than
the one just allocated, with the help of an AI coding assistant
(Claude).
Fixes: 1ba19a6ea9f2 ("btrfs: tests: zoned: add tests cases for zoned code")
Signed-off-by: Yifan Feng <evanfengff@gmail.com>
---
fs/btrfs/tests/zoned-tests.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/fs/btrfs/tests/zoned-tests.c b/fs/btrfs/tests/zoned-tests.c
index 2bc3b14baa41..bb9969210444 100644
--- a/fs/btrfs/tests/zoned-tests.c
+++ b/fs/btrfs/tests/zoned-tests.c
@@ -65,7 +65,7 @@ static int test_load_zone_info(struct btrfs_fs_info *fs_info,
}
active = bitmap_zalloc(test->num_stripes, GFP_KERNEL);
- if (!zone_info) {
+ if (!active) {
test_err("cannot allocate active bitmap");
return -ENOMEM;
}
base-commit: aebb7274476403040d582c61478df8f4a7bf9cd3
--
2.39.3 (Apple Git-146)
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] btrfs: tests: zoned: fix NULL check of the active bitmap
2026-11-17 3:51 [PATCH] btrfs: tests: zoned: fix NULL check of the active bitmap Yifan Feng
@ 2026-11-17 4:35 ` Qu Wenruo
2026-11-17 5:00 ` Naohiro Aota
1 sibling, 0 replies; 3+ messages in thread
From: Qu Wenruo @ 2026-11-17 4:35 UTC (permalink / raw)
To: Yifan Feng, David Sterba
Cc: Chris Mason, Naohiro Aota, Johannes Thumshirn, linux-btrfs, linux-kernel
在 2026/11/17 14:21, Yifan Feng 写道:
> test_load_zone_info() allocates the active bitmap with bitmap_zalloc()
> but then tests zone_info, which was already checked a few lines above.
> A failed allocation is not detected, and the NULL bitmap is then used
> by __set_bit() and by btrfs_load_block_group_by_raid_type().
>
> Check the active bitmap instead.
>
> Tested in QEMU with the bitmap size temporarily changed to UINT_MAX so
> that the allocation fails. Without this patch the kernel oopses in
> btrfs_test_zoned() with a NULL pointer dereference. With it the test
> prints "cannot allocate active bitmap" and fails cleanly.
Remove testing steps that no one cares.
>
> Found by searching for a NULL check that tests a different pointer than
> the one just allocated, with the help of an AI coding assistant
> (Claude).
Also no one cares how you found this one, especially it's almost 100%
generated by LLM.
>
> Fixes: 1ba19a6ea9f2 ("btrfs: tests: zoned: add tests cases for zoned code")
> Signed-off-by: Yifan Feng <evanfengff@gmail.com>
Although the code looks good to me.
Reviewed-by: <wqu@suse.com>
I'll remove the unnecessary commit messages during merge, so you don't
need to resend.
> ---
> fs/btrfs/tests/zoned-tests.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/fs/btrfs/tests/zoned-tests.c b/fs/btrfs/tests/zoned-tests.c
> index 2bc3b14baa41..bb9969210444 100644
> --- a/fs/btrfs/tests/zoned-tests.c
> +++ b/fs/btrfs/tests/zoned-tests.c
> @@ -65,7 +65,7 @@ static int test_load_zone_info(struct btrfs_fs_info *fs_info,
> }
>
> active = bitmap_zalloc(test->num_stripes, GFP_KERNEL);
> - if (!zone_info) {
> + if (!active) {
> test_err("cannot allocate active bitmap");
> return -ENOMEM;
> }
>
> base-commit: aebb7274476403040d582c61478df8f4a7bf9cd3
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] btrfs: tests: zoned: fix NULL check of the active bitmap
2026-11-17 3:51 [PATCH] btrfs: tests: zoned: fix NULL check of the active bitmap Yifan Feng
2026-11-17 4:35 ` Qu Wenruo
@ 2026-11-17 5:00 ` Naohiro Aota
1 sibling, 0 replies; 3+ messages in thread
From: Naohiro Aota @ 2026-11-17 5:00 UTC (permalink / raw)
To: Yifan Feng, David Sterba
Cc: Chris Mason, Naohiro Aota, Johannes Thumshirn, linux-btrfs, linux-kernel
On Tue Nov 17, 2026 at 12:51 PM JST, Yifan Feng wrote:
> test_load_zone_info() allocates the active bitmap with bitmap_zalloc()
> but then tests zone_info, which was already checked a few lines above.
> A failed allocation is not detected, and the NULL bitmap is then used
> by __set_bit() and by btrfs_load_block_group_by_raid_type().
>
> Check the active bitmap instead.
>
> Tested in QEMU with the bitmap size temporarily changed to UINT_MAX so
> that the allocation fails. Without this patch the kernel oopses in
> btrfs_test_zoned() with a NULL pointer dereference. With it the test
> prints "cannot allocate active bitmap" and fails cleanly.
>
> Found by searching for a NULL check that tests a different pointer than
> the one just allocated, with the help of an AI coding assistant
> (Claude).
>
> Fixes: 1ba19a6ea9f2 ("btrfs: tests: zoned: add tests cases for zoned code")
> Signed-off-by: Yifan Feng <evanfengff@gmail.com>
Reviewed-by: Naohiro Aota <naohiro.aota@wdc.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-17 5:01 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-17 3:51 [PATCH] btrfs: tests: zoned: fix NULL check of the active bitmap Yifan Feng
2026-11-17 4:35 ` Qu Wenruo
2026-11-17 5:00 ` Naohiro Aota
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®