Skip to content

Commit 0c592fe

Browse files
committed
btrfs-progs: tests: add fuzzing of superblock struct members
Use btrfs-sb-mod and do some arbitrary changes to super blocks. Then run 'btrfs check'. Check will fail to read the filesystem most of the time and cannot do any actual repair but must not crash. Signed-off-by: David Sterba <dsterba@suse.com>
1 parent a36ca79 commit 0c592fe

File tree

3 files changed

+78
-2
lines changed

3 files changed

+78
-2
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ test-mkfs: btrfs mkfs.btrfs
556556
@echo " TEST mkfs-tests.sh"
557557
$(Q)bash tests/mkfs-tests.sh
558558

559-
test-fuzz: btrfs btrfs-image
559+
test-fuzz: btrfs btrfs-image btrfs-sb-mod
560560
@echo " TEST fuzz-tests.sh"
561561
$(Q)bash tests/fuzz-tests.sh
562562

tests/common

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ check_prereq()
413413
{
414414
# Internal tools for testing, not shipped with the package
415415
case "$1" in
416-
btrfs-corrupt-block|btrfs-find-root|btrfs-select-super|fssum)
416+
btrfs-corrupt-block|btrfs-find-root|btrfs-select-super|fssum|btrfs-sb-mod)
417417
if ! [ -f "$INTERNAL_BIN/$1" ]; then
418418
_fail "Failed prerequisites: $INTERNAL_BIN/$1";
419419
fi
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#!/bin/bash
2+
# Change fields in super block and do test run of 'btrfs check'
3+
4+
source "$TEST_TOP/common" || exit
5+
source "$TEST_TOP/common.convert" || exit
6+
7+
check_prereq btrfs-sb-mod
8+
9+
setup_root_helper
10+
prepare_test_dev
11+
12+
run_check_mkfs_test_dev
13+
run_check_mount_test_dev
14+
#populate_fs
15+
generate_dataset "small"
16+
generate_dataset "sparse"
17+
run_check_umount_test_dev
18+
19+
# See btrfs-sb-mod --help
20+
fields=(
21+
bytenr
22+
flags
23+
magic
24+
generation
25+
root
26+
chunk_root
27+
log_root
28+
total_bytes
29+
bytes_used
30+
root_dir_objectid
31+
num_devices
32+
sectorsize
33+
nodesize
34+
stripesize
35+
sys_chunk_array_size
36+
chunk_root_generation
37+
compat_flags
38+
compat_ro_flags
39+
incompat_flags
40+
csum_type
41+
root_level
42+
chunk_root_level
43+
log_root_level
44+
cache_generation
45+
uuid_tree_generation
46+
dev_item.devid
47+
dev_item.total_bytes
48+
dev_item.bytes_used
49+
dev_item.io_align
50+
dev_item.io_width
51+
dev_item.sector_size
52+
dev_item.type
53+
dev_item.generation
54+
dev_item.start_offset
55+
dev_item.dev_group
56+
dev_item.seek_speed
57+
dev_item.bandwidth)
58+
59+
# Attempted changes:
60+
#
61+
# - off by one
62+
# - LSB bit flips
63+
# - 32bit boundary bit flips
64+
# - off by sector
65+
# - off by node
66+
# - endianness swap
67+
for field in "${fields[@]}"; do
68+
for op in -1 +1 ^2 ^4 ^256 ^2147483648 ^4294967296 ^8589934592 +4096 -4096 +16384 -16384 @; do
69+
run_check $SUDO_HELPER truncate -s 0 image.test
70+
run_check $SUDO_HELPER cp --reflink=auto --sparse=auto "$TEST_DEV" image.test
71+
run_check $SUDO_HELPER "$TOP/btrfs-sb-mod" image.test "$field" "$op"
72+
run_mayfail $SUDO_HELPER "$TOP/btrfs" check image.test
73+
done
74+
done
75+
76+
run_check $SUDO_HELPER rm -f -- image.test

0 commit comments

Comments
 (0)