ext4: resize fs after set reserved GDT blocks equals 100
PATCH v4 1/1 ext4: resize fs after set reserved GDT blocks equals 100
Set reserved GDT blocks equals 100, then resize fs, will trigger null pointer.
Regression test for commit b55c3cd102a6 ext4: add reserved GDT blocks check.
--- tests/ext4/057 | 46 ++++++++++++++++++++++++++++++++++++++++++++++ tests/ext4/057.out | 2 ++ 2 files changed, 48 insertions(+) create mode 100755 tests/ext4/057 create mode 100644 tests/ext4/057.out
tests/ext4/057 new file +46 -0
@@ -0,0 +1,46 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (c) 2022 HUAWEI. All Rights Reserved. +# +# FS QA Test 057 +# +# Set reserved GDT blocks equals 100, then resize fs, will trigger null pointer. +# +# Regression test for commit +# b55c3cd102a6 ext4: add reserved GDT blocks check +# +. ./common/preamble +_begin_fstest auto resize quick + +# real QA test starts here + +# Modify as appropriate. +_supported_fs ext4 +_fixed_by_kernel_commit b55c3cd102a6 \ + "ext4: add reserved GDT blocks check" + +_require_command "$TUNE2FS_PROG" tune2fs +_require_command "$RESIZE2FS_PROG" resize2fs +_require_command "$DEBUGFS_PROG" debugfs +_require_scratch_size $((1024 * 1024)) #kB +_require_scratch_nocheck + +# set fs size 512M +dev_size=$((512 * 1024 * 1024)) +MKFS_OPTIONS="-O ^resize_inode $MKFS_OPTIONS" _scratch_mkfs_sized $dev_size \ + >>$seqres.full 2>&1 || _fail "mkfs failed" + +$DEBUGFS_PROG -w -R "set_super_value s_reserved_gdt_blocks 100" $SCRATCH_DEV \ + >>$seqres.full 2>&1 + +$DEBUGFS_PROG -R "show_super_stats -h" $SCRATCH_DEV 2>/dev/null | \ + grep "Reserved GDT blocks" + +_scratch_mount + +# resize fs will trigger NULL pointer in ext4_flex_group_add +$RESIZE2FS_PROG $SCRATCH_DEV 1G >> $seqres.full 2>&1 + +# success, all done +status=0 +exit
tests/ext4/057.out new file +2 -0
@@ -0,0 +1,2 @@ +QA output created by 057 +Reserved GDT blocks: 100
Signature · 1 line
2.13.6
Quoted 20 lines · Sun Ke
Set reserved GDT blocks equals 100, then resize fs, will trigger null pointer.
Regression test for commit
b55c3cd102a6ext4: add reserved GDT blocks check.Signed-off-by Sun Ke <[email protected]>--- tests/ext4/057 | 46 ++++++++++++++++++++++++++++++++++++++++++++++ tests/ext4/057.out | 2 ++ 2 files changed, 48 insertions(+) create mode 100755 tests/ext4/057 create mode 100644 tests/ext4/057.outtests/ext4/057 new file +0
-0
tests/ext4/057 line 7
Quoted 7 lines
tests/ext4/057 new file +7
-0@@ -0,0 +1,46 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (c) 2022 HUAWEI. All Rights Reserved. +# +# FS QA Test 057 +# +# Set reserved GDT blocks equals 100, then resize fs, will trigger null pointer.
The number "100" isn't important, it just hope to get reserved GDT blocks even if you disable resize_inode feature. So you'd better to reflect these two conditions, rather than the number "100". E.g:
# A regression test for b55c3cd102a6 ("ext4: add reserved GDT blocks check"). # Make sure there's not kernel crash, if resize an ext4 which resize_inode
# feature is disabled but has reserved GDT blocks.
tests/ext4/057 line 17
Quoted 10 lines
tests/ext4/057 new file +10
-0+# +# Regression test for commit +# b55c3cd102a6 ext4: add reserved GDT blocks check +# +. ./common/preamble +_begin_fstest auto resize quick + +# real QA test starts here + +# Modify as appropriate.
^^^^
Remove this useless comment
tests/ext4/057 line 22
Quoted 5 lines
tests/ext4/057 new file +5
-0+_supported_fs ext4 +_fixed_by_kernel_commit b55c3cd102a6 \ + "ext4: add reserved GDT blocks check" + +_require_command "$TUNE2FS_PROG" tune2fs
If you don't need this command anymore, remove this line.
tests/ext4/057 line 26
Quoted 4 lines
tests/ext4/057 new file +4
-0+_require_command "$RESIZE2FS_PROG" resize2fs +_require_command "$DEBUGFS_PROG" debugfs +_require_scratch_size $((1024 * 1024)) #kB +_require_scratch_nocheck
Generally we don't use _require_scratch_size and _require_scratch together, You can use a simple one line:
_require_scratch_size_nocheck $((1024 * 1024))
tests/ext4/057 line 28
Quoted 2 lines
tests/ext4/057 new file +2
-0+ +# set fs size 512M
If you'd like to have some comments:
# Initalize a 512M ext4 fs with resize_inode feature disabled
tests/ext4/057 line 32
Quoted 4 lines
tests/ext4/057 new file +4
-0+dev_size=$((512 * 1024 * 1024)) +MKFS_OPTIONS="-O ^resize_inode $MKFS_OPTIONS" _scratch_mkfs_sized $dev_size \ + >>$seqres.full 2>&1 || _fail "mkfs failed" +
# Force some reserved GDT blocks to trigger the bug
tests/ext4/057 line 41
Quoted 9 lines
tests/ext4/057 new file +9
-0+$DEBUGFS_PROG -w -R "set_super_value s_reserved_gdt_blocks 100" $SCRATCH_DEV \ + >>$seqres.full 2>&1 + +$DEBUGFS_PROG -R "show_super_stats -h" $SCRATCH_DEV 2>/dev/null | \ + grep "Reserved GDT blocks" + +_scratch_mount + +# resize fs will trigger NULL pointer in ext4_flex_group_add
# Expect no crash from this resize operation
Quoted 16 lines
tests/ext4/057 new file +5
-0+$RESIZE2FS_PROG $SCRATCH_DEV 1G >> $seqres.full 2>&1 + +# success, all done +status=0 +exittests/ext4/057.out new file +2
-0@@ -0,0 +1,2 @@ +QA output created by 057 +Reserved GDT blocks: 100Signature · 1 line
2.13.6