* [PATCH v2] fstests: btrfs: a new test case to verify scrub and rescue=idatacsums
@ 2025-05-12 9:39 Qu Wenruo
2025-05-12 11:16 ` Filipe Manana
2025-05-13 2:53 ` Anand Jain
0 siblings, 2 replies; 3+ messages in thread
From: Qu Wenruo @ 2025-05-12 9:39 UTC (permalink / raw)
To: linux-btrfs, fstests; +Cc: Johannes Thumshirn
There is a kernel bug report that scrub will trigger a NULL pointer
dereference when rescue=idatacsums mount option is provided.
Add a test case for such situation, to verify kernel can gracefully
reject scrub when there is no csum tree.
Signed-off-by: Qu Wenruo <wqu@suse.com>
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
---
Changelog:
v2:
- Strictly require the scrub to fail
Suggested by Filipe
---
tests/btrfs/336 | 35 +++++++++++++++++++++++++++++++++++
tests/btrfs/336.out | 2 ++
2 files changed, 37 insertions(+)
create mode 100755 tests/btrfs/336
create mode 100644 tests/btrfs/336.out
diff --git a/tests/btrfs/336 b/tests/btrfs/336
new file mode 100755
index 00000000..f6691bae
--- /dev/null
+++ b/tests/btrfs/336
@@ -0,0 +1,35 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (C) 2025 SUSE Linux Products GmbH. All Rights Reserved.
+#
+# FS QA Test 336
+#
+# Make sure read-only scrub won't cause NULL pointer dereference with
+# rescue=idatacsums mount option
+#
+. ./common/preamble
+_begin_fstest auto scrub quick
+
+_fixed_by_kernel_commit 6aecd91a5c5b \
+ "btrfs: avoid NULL pointer dereference if no valid extent tree"
+
+_require_scratch
+_scratch_mkfs >> $seqres.full
+
+_try_scratch_mount "-o ro,rescue=ignoredatacsums" > /dev/null 2>&1 ||
+ _notrun "rescue=ignoredatacsums mount option not supported"
+
+# For unpatched kernel this will cause NULL pointer dereference and crash the kernel.
+$BTRFS_UTIL_PROG scrub start -Br $SCRATCH_MNT >> $seqres.full 2>&1
+# For patched kernel scrub will be gracefully rejected.
+if [ $? -eq 0 ]; then
+ echo "read-only scrub should fail but didn't"
+fi
+
+_scratch_unmount
+
+echo "Silence is golden"
+
+# success, all done
+status=0
+exit
diff --git a/tests/btrfs/336.out b/tests/btrfs/336.out
new file mode 100644
index 00000000..9263628e
--- /dev/null
+++ b/tests/btrfs/336.out
@@ -0,0 +1,2 @@
+QA output created by 336
+Silence is golden
--
2.47.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2] fstests: btrfs: a new test case to verify scrub and rescue=idatacsums
2025-05-12 9:39 [PATCH v2] fstests: btrfs: a new test case to verify scrub and rescue=idatacsums Qu Wenruo
@ 2025-05-12 11:16 ` Filipe Manana
2025-05-13 2:53 ` Anand Jain
1 sibling, 0 replies; 3+ messages in thread
From: Filipe Manana @ 2025-05-12 11:16 UTC (permalink / raw)
To: Qu Wenruo; +Cc: linux-btrfs, fstests, Johannes Thumshirn
On Mon, May 12, 2025 at 10:40 AM Qu Wenruo <wqu@suse.com> wrote:
>
> There is a kernel bug report that scrub will trigger a NULL pointer
> dereference when rescue=idatacsums mount option is provided.
>
> Add a test case for such situation, to verify kernel can gracefully
> reject scrub when there is no csum tree.
>
> Signed-off-by: Qu Wenruo <wqu@suse.com>
> Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Reviewed-by: Filipe Manana <fdmanana@suse.com>
Looks good now, thanks.
> ---
> Changelog:
> v2:
> - Strictly require the scrub to fail
> Suggested by Filipe
> ---
> tests/btrfs/336 | 35 +++++++++++++++++++++++++++++++++++
> tests/btrfs/336.out | 2 ++
> 2 files changed, 37 insertions(+)
> create mode 100755 tests/btrfs/336
> create mode 100644 tests/btrfs/336.out
>
> diff --git a/tests/btrfs/336 b/tests/btrfs/336
> new file mode 100755
> index 00000000..f6691bae
> --- /dev/null
> +++ b/tests/btrfs/336
> @@ -0,0 +1,35 @@
> +#! /bin/bash
> +# SPDX-License-Identifier: GPL-2.0
> +# Copyright (C) 2025 SUSE Linux Products GmbH. All Rights Reserved.
> +#
> +# FS QA Test 336
> +#
> +# Make sure read-only scrub won't cause NULL pointer dereference with
> +# rescue=idatacsums mount option
> +#
> +. ./common/preamble
> +_begin_fstest auto scrub quick
> +
> +_fixed_by_kernel_commit 6aecd91a5c5b \
> + "btrfs: avoid NULL pointer dereference if no valid extent tree"
> +
> +_require_scratch
> +_scratch_mkfs >> $seqres.full
> +
> +_try_scratch_mount "-o ro,rescue=ignoredatacsums" > /dev/null 2>&1 ||
> + _notrun "rescue=ignoredatacsums mount option not supported"
> +
> +# For unpatched kernel this will cause NULL pointer dereference and crash the kernel.
> +$BTRFS_UTIL_PROG scrub start -Br $SCRATCH_MNT >> $seqres.full 2>&1
> +# For patched kernel scrub will be gracefully rejected.
> +if [ $? -eq 0 ]; then
> + echo "read-only scrub should fail but didn't"
> +fi
> +
> +_scratch_unmount
> +
> +echo "Silence is golden"
> +
> +# success, all done
> +status=0
> +exit
> diff --git a/tests/btrfs/336.out b/tests/btrfs/336.out
> new file mode 100644
> index 00000000..9263628e
> --- /dev/null
> +++ b/tests/btrfs/336.out
> @@ -0,0 +1,2 @@
> +QA output created by 336
> +Silence is golden
> --
> 2.47.1
>
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] fstests: btrfs: a new test case to verify scrub and rescue=idatacsums
2025-05-12 9:39 [PATCH v2] fstests: btrfs: a new test case to verify scrub and rescue=idatacsums Qu Wenruo
2025-05-12 11:16 ` Filipe Manana
@ 2025-05-13 2:53 ` Anand Jain
1 sibling, 0 replies; 3+ messages in thread
From: Anand Jain @ 2025-05-13 2:53 UTC (permalink / raw)
To: Qu Wenruo, linux-btrfs, fstests; +Cc: Johannes Thumshirn
Reviewed-by: Anand Jain <anand.jain@oracle.com>
Applied. Thanks.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-05-13 2:53 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-12 9:39 [PATCH v2] fstests: btrfs: a new test case to verify scrub and rescue=idatacsums Qu Wenruo
2025-05-12 11:16 ` Filipe Manana
2025-05-13 2:53 ` Anand Jain
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox