]> git.apps.os.sepia.ceph.com Git - xfstests-dev.git/commitdiff
btrfs: verify the behavior of deleting non-existing device
authorQu Wenruo <wqu@suse.com>
Fri, 6 Aug 2021 11:33:33 +0000 (19:33 +0800)
committerEryu Guan <guaneryu@gmail.com>
Sun, 8 Aug 2021 14:09:03 +0000 (22:09 +0800)
There is a kernel regression for btrfs, that when passing
non-existing devid to "btrfs device remove" command, kernel will
crash due to NULL pointer dereference.

The test case is for such regression, it will:

- Create and mount an empty single-device btrfs
- Try to remove devid 3, which doesn't exist for above fs
- Make sure the command exits properly with expected error message

The kernel fix is titled "btrfs: fix NULL pointer dereference when
deleting device by invalid id".

Signed-off-by: Qu Wenruo <wqu@suse.com>
Reviewed-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: Eryu Guan <guaneryu@gmail.com>
tests/btrfs/244 [new file with mode: 0755]
tests/btrfs/244.out [new file with mode: 0644]

diff --git a/tests/btrfs/244 b/tests/btrfs/244
new file mode 100755 (executable)
index 0000000..fbefeed
--- /dev/null
@@ -0,0 +1,47 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2021 SUSE Linux Products GmbH.  All Rights Reserved.
+#
+# FS QA Test 244
+#
+# Make sure "btrfs device remove" won't crash when non-existing devid
+# is provided
+#
+. ./common/preamble
+_begin_fstest auto quick volume dangerous
+
+# Override the default cleanup function.
+# _cleanup()
+# {
+#      cd /
+#      rm -r -f $tmp.*
+# }
+
+# Import common functions.
+# . ./common/filter
+
+# real QA test starts here
+
+# Modify as appropriate.
+_supported_fs btrfs
+_require_scratch
+
+_scratch_mkfs >> $seqres.full 2>&1
+_scratch_mount
+
+# Above created fs only contains one device with devid 1, device remove 3
+# should just fail with proper error message showing devid 3 can't be found.
+# Although on unpatched kernel, this will trigger a NULL pointer dereference.
+$BTRFS_UTIL_PROG device remove 3 $SCRATCH_MNT
+ret=$?
+
+if [ $ret -ne 1 ]; then
+       echo "Unexpected return value from btrfs command, has $ret expected 1"
+fi
+
+# Fstests will automatically check the filesystem to make sure metadata is not
+# corrupted.
+
+# success, all done
+status=0
+exit
diff --git a/tests/btrfs/244.out b/tests/btrfs/244.out
new file mode 100644 (file)
index 0000000..629adf2
--- /dev/null
@@ -0,0 +1,2 @@
+QA output created by 244
+ERROR: error removing devid 3: No such file or directory