btrfs: tests: zoned: fix NULL check of the active bitmap
PATCH 1/1 btrfs: tests: zoned: fix NULL check of the active bitmap
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).
--- fs/btrfs/tests/zoned-tests.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/btrfs/tests/zoned-tests.c +1 -1
@@ -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
Signature · 1 line
2.39.3 (Apple Git-146)
Quoted 11 lines · Yifan Feng
test_load_zone_info()allocates the active bitmap withbitmap_zalloc()but then testszone_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 bybtrfs_load_block_group_by_raid_type().Check the active bitmap instead.
Tested in QEMU with the bitmap size temporarily changed to
UINT_MAXso that the allocation fails. Without this patch the kernel oopses inbtrfs_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.
Quoted 4 lines
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.
Quoted 3 lines
Fixes 1ba19a6ea9f2 ("btrfs: tests: zoned: add tests cases for zoned code")Signed-off-by Yifan Feng <[email protected]>
Although the code looks good to me.
I'll remove the unnecessary commit messages during merge, so you don't need to resend.
Quoted 19 lines
--- fs/btrfs/tests/zoned-tests.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)fs/btrfs/tests/zoned-tests.c +1
-1@@ -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
Quoted 12 lines · Yifan Feng
test_load_zone_info()allocates the active bitmap withbitmap_zalloc()but then testszone_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 bybtrfs_load_block_group_by_raid_type().Check the active bitmap instead.
Tested in QEMU with the bitmap size temporarily changed to
UINT_MAXso that the allocation fails. Without this patch the kernel oopses inbtrfs_test_zoned()with a NULL pointer dereference. With it the test prints "cannot allocate active bitmap" and fails cleanly.
Quoted 6 lines
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 <[email protected]>