[v2,2/2] xfs: make sure the kernel and repair tools catch bad names
diff mbox series

Message ID 20191024003106.GD6706@magnolia
State New
Headers show
Series
  • Untitled series #192601
Related show

Commit Message

Darrick J. Wong Oct. 24, 2019, 12:31 a.m. UTC
From: Darrick J. Wong <darrick.wong@oracle.com>

Make sure we actually catch bad names in the kernel.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
v2: fix various things as pointed out by Eryu
---
 tests/xfs/749     |  106 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 tests/xfs/749.out |    3 ++
 tests/xfs/group   |    1 +
 3 files changed, 110 insertions(+)
 create mode 100755 tests/xfs/749
 create mode 100644 tests/xfs/749.out

Comments

Darrick J. Wong Oct. 24, 2019, 4:52 a.m. UTC | #1
On Wed, Oct 23, 2019 at 05:31:06PM -0700, Darrick J. Wong wrote:
> From: Darrick J. Wong <darrick.wong@oracle.com>
> 
> Make sure we actually catch bad names in the kernel.
> 
> Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
> ---
> v2: fix various things as pointed out by Eryu

Self NAK, I found some bugs in this test and withdraw this patch.

--D

> ---
>  tests/xfs/749     |  106 +++++++++++++++++++++++++++++++++++++++++++++++++++++
>  tests/xfs/749.out |    3 ++
>  tests/xfs/group   |    1 +
>  3 files changed, 110 insertions(+)
>  create mode 100755 tests/xfs/749
>  create mode 100644 tests/xfs/749.out
> 
> diff --git a/tests/xfs/749 b/tests/xfs/749
> new file mode 100755
> index 00000000..e8371351
> --- /dev/null
> +++ b/tests/xfs/749
> @@ -0,0 +1,106 @@
> +#! /bin/bash
> +# SPDX-License-Identifier: GPL-2.0-or-newer
> +# Copyright (c) 2019, Oracle and/or its affiliates.  All Rights Reserved.
> +#
> +# FS QA Test No. 749
> +#
> +# See if we catch corrupt directory names or attr names with nulls or slashes
> +# in them.
> +
> +seq=`basename $0`
> +seqres=$RESULT_DIR/$seq
> +echo "QA output created by $seq"
> +
> +here=`pwd`
> +tmp=/tmp/$$
> +status=1    # failure is the default!
> +trap "_cleanup; exit \$status" 0 1 2 3 15
> +
> +_cleanup()
> +{
> +	cd /
> +	$UMOUNT_PROG $mntpt > /dev/null 2>&1
> +	test -n "$loopdev" && _destroy_loop_device $loopdev > /dev/null 2>&1
> +	rm -r -f $imgfile $mntpt $tmp.*
> +}
> +
> +# get standard environment, filters and checks
> +. ./common/rc
> +. ./common/filter
> +. ./common/attr
> +
> +# real QA test starts here
> +_supported_fs xfs
> +_supported_os Linux
> +_require_test
> +_require_attrs
> +
> +rm -f $seqres.full
> +
> +imgfile=$TEST_DIR/img-$seq
> +mntpt=$TEST_DIR/mount-$seq
> +testdir=$mntpt/testdir
> +testfile=$mntpt/testfile
> +nullstr="too_many_beans"
> +slashstr="are_bad_for_you"
> +
> +# Format image file
> +$XFS_IO_PROG -f -c 'truncate 40m' $imgfile
> +loopdev=$(_create_loop_device $imgfile)
> +_mkfs_dev $loopdev >> $seqres.full
> +
> +# Mount image file
> +mkdir -p $mntpt
> +_mount $loopdev $mntpt
> +
> +# Create directory entries
> +mkdir -p $testdir
> +touch $testdir/$nullstr
> +touch $testdir/$slashstr
> +
> +# Create attrs
> +touch $testfile
> +$ATTR_PROG -s $nullstr -V heh $testfile >> $seqres.full
> +$ATTR_PROG -s $slashstr -V heh $testfile >> $seqres.full
> +
> +# Corrupt the entries
> +$UMOUNT_PROG $mntpt
> +_destroy_loop_device $loopdev
> +cp $imgfile $imgfile.old
> +sed -b \
> +	-e "s/$nullstr/too_many\x00beans/g" \
> +	-e "s/$slashstr/are_bad\/for_you/g" \
> +	-i $imgfile
> +test "$(md5sum < $imgfile)" != "$(md5sum < $imgfile.old)" ||
> +	_fail "sed failed to change the image file?"
> +rm -f $imgfile.old
> +loopdev=$(_create_loop_device $imgfile)
> +_mount $loopdev $mntpt
> +
> +# Try to access the corrupt metadata
> +ls $testdir >> $seqres.full 2> $tmp.err
> +$ATTR_PROG -l $testfile >> $seqres.full 2>> $tmp.err
> +cat $tmp.err >> $seqres.full
> +cat $tmp.err | _filter_test_dir | sed -e '/Could not list/d'
> +
> +# Does scrub complain about this?
> +if _supports_xfs_scrub $mntpt $loopdev; then
> +	$XFS_SCRUB_PROG -n $mntpt >> $seqres.full 2>&1
> +	res=$?
> +	test $((res & 1)) -eq 0 && \
> +		echo "scrub failed to report corruption ($res)"
> +fi
> +
> +# Does repair complain about this?
> +$UMOUNT_PROG $mntpt
> +$XFS_REPAIR_PROG -n $loopdev >> $seqres.full 2>&1
> +res=$?
> +test $res -eq 1 || \
> +	echo "repair failed to report corruption ($res)"
> +
> +_destroy_loop_device $loopdev
> +loopdev=
> +
> +# success, all done
> +status=0
> +exit
> diff --git a/tests/xfs/749.out b/tests/xfs/749.out
> new file mode 100644
> index 00000000..db3b1beb
> --- /dev/null
> +++ b/tests/xfs/749.out
> @@ -0,0 +1,3 @@
> +QA output created by 749
> +ls: cannot access 'TEST_DIR/mount-749/testdir': Structure needs cleaning
> +attr_list: Structure needs cleaning
> diff --git a/tests/xfs/group b/tests/xfs/group
> index f4ebcd8c..9600cb4e 100644
> --- a/tests/xfs/group
> +++ b/tests/xfs/group
> @@ -507,3 +507,4 @@
>  509 auto ioctl
>  510 auto ioctl quick
>  511 auto quick quota
> +749 auto quick fuzzers

Patch
diff mbox series

diff --git a/tests/xfs/749 b/tests/xfs/749
new file mode 100755
index 00000000..e8371351
--- /dev/null
+++ b/tests/xfs/749
@@ -0,0 +1,106 @@ 
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0-or-newer
+# Copyright (c) 2019, Oracle and/or its affiliates.  All Rights Reserved.
+#
+# FS QA Test No. 749
+#
+# See if we catch corrupt directory names or attr names with nulls or slashes
+# in them.
+
+seq=`basename $0`
+seqres=$RESULT_DIR/$seq
+echo "QA output created by $seq"
+
+here=`pwd`
+tmp=/tmp/$$
+status=1    # failure is the default!
+trap "_cleanup; exit \$status" 0 1 2 3 15
+
+_cleanup()
+{
+	cd /
+	$UMOUNT_PROG $mntpt > /dev/null 2>&1
+	test -n "$loopdev" && _destroy_loop_device $loopdev > /dev/null 2>&1
+	rm -r -f $imgfile $mntpt $tmp.*
+}
+
+# get standard environment, filters and checks
+. ./common/rc
+. ./common/filter
+. ./common/attr
+
+# real QA test starts here
+_supported_fs xfs
+_supported_os Linux
+_require_test
+_require_attrs
+
+rm -f $seqres.full
+
+imgfile=$TEST_DIR/img-$seq
+mntpt=$TEST_DIR/mount-$seq
+testdir=$mntpt/testdir
+testfile=$mntpt/testfile
+nullstr="too_many_beans"
+slashstr="are_bad_for_you"
+
+# Format image file
+$XFS_IO_PROG -f -c 'truncate 40m' $imgfile
+loopdev=$(_create_loop_device $imgfile)
+_mkfs_dev $loopdev >> $seqres.full
+
+# Mount image file
+mkdir -p $mntpt
+_mount $loopdev $mntpt
+
+# Create directory entries
+mkdir -p $testdir
+touch $testdir/$nullstr
+touch $testdir/$slashstr
+
+# Create attrs
+touch $testfile
+$ATTR_PROG -s $nullstr -V heh $testfile >> $seqres.full
+$ATTR_PROG -s $slashstr -V heh $testfile >> $seqres.full
+
+# Corrupt the entries
+$UMOUNT_PROG $mntpt
+_destroy_loop_device $loopdev
+cp $imgfile $imgfile.old
+sed -b \
+	-e "s/$nullstr/too_many\x00beans/g" \
+	-e "s/$slashstr/are_bad\/for_you/g" \
+	-i $imgfile
+test "$(md5sum < $imgfile)" != "$(md5sum < $imgfile.old)" ||
+	_fail "sed failed to change the image file?"
+rm -f $imgfile.old
+loopdev=$(_create_loop_device $imgfile)
+_mount $loopdev $mntpt
+
+# Try to access the corrupt metadata
+ls $testdir >> $seqres.full 2> $tmp.err
+$ATTR_PROG -l $testfile >> $seqres.full 2>> $tmp.err
+cat $tmp.err >> $seqres.full
+cat $tmp.err | _filter_test_dir | sed -e '/Could not list/d'
+
+# Does scrub complain about this?
+if _supports_xfs_scrub $mntpt $loopdev; then
+	$XFS_SCRUB_PROG -n $mntpt >> $seqres.full 2>&1
+	res=$?
+	test $((res & 1)) -eq 0 && \
+		echo "scrub failed to report corruption ($res)"
+fi
+
+# Does repair complain about this?
+$UMOUNT_PROG $mntpt
+$XFS_REPAIR_PROG -n $loopdev >> $seqres.full 2>&1
+res=$?
+test $res -eq 1 || \
+	echo "repair failed to report corruption ($res)"
+
+_destroy_loop_device $loopdev
+loopdev=
+
+# success, all done
+status=0
+exit
diff --git a/tests/xfs/749.out b/tests/xfs/749.out
new file mode 100644
index 00000000..db3b1beb
--- /dev/null
+++ b/tests/xfs/749.out
@@ -0,0 +1,3 @@ 
+QA output created by 749
+ls: cannot access 'TEST_DIR/mount-749/testdir': Structure needs cleaning
+attr_list: Structure needs cleaning
diff --git a/tests/xfs/group b/tests/xfs/group
index f4ebcd8c..9600cb4e 100644
--- a/tests/xfs/group
+++ b/tests/xfs/group
@@ -507,3 +507,4 @@ 
 509 auto ioctl
 510 auto ioctl quick
 511 auto quick quota
+749 auto quick fuzzers