Improved FS_IOC_FSSETXATTR tests
cover Improved FS_IOC_FSSETXATTR tests
Eryu,
Overlayfs gained support for FS_IOC_FSSETXATTR ioctl in v5.2-rc4 with buggy capability check. The fix is trivial so it should land upstream soon.
This series adds a generic test to cover the bug in overlayfs v5.2-rc4. It also adds a proper _require directive to test filesystem support for FS_IOC_FSSETXATTR and let the tests that use this ioctl require filesystem support for it.
The only existing generic test that needed this requirement is the recently added generic/553 copy_range immutable file test. When run on overlayfs over xfs/ext4/btrfs, generic/553 would fail instead of _notrun with kernel v5.2-rc3.
But the requirement fix is not only for overlayfs, other filesystems that support FS_IOC_SETFLAGS but not FS_IOC_FSSETXATTR (e.g. ext2), need those fixes to _notrun generic/553.
Thanks,
Amir.
Amir Goldstein (3):
fstests: print out xfs_io parameter when command fails
fstests: check for filesystem FS_IOC_FSSETXATTR support
generic: check CAP_LINUX_IMMUTABLE capability with FS_IOC_FSSETXATTR
common/rc | 30 ++++++++++----- doc/requirement-checking.txt | 2 +- tests/generic/553 | 3 +- tests/generic/555 | 74 ++++++++++++++++++++++++++++++++++++ tests/generic/555.out | 9 +++++ tests/generic/group | 1 + tests/xfs/260 | 2 +- tests/xfs/431 | 2 +- 8 files changed, 108 insertions(+), 15 deletions(-) create mode 100755 tests/generic/555 create mode 100644 tests/generic/555.out
Signature · 1 line
2.17.1
PATCH 1/3 fstests: print out xfs_io parameter when command fails
In _require_xfs_io_command, when command fails for one of the generic reasons, if command was tested with params, print out the params of the failed command.
--- common/rc | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-)
common/rc +10 -10
@@ -2084,7 +2084,7 @@ _require_xfs_io_command() local command=$1 shift local param="$*" - local param_checked=0 + local param_checked="" local opts="" local testfile=$TEST_DIR/$$.xfs_io
@@ -2101,7 +2101,7 @@ _require_xfs_io_command() ;; "falloc" ) testio=`$XFS_IO_PROG -F -f -c "falloc $param 0 1m" $testfile 2>&1` - param_checked=1 + param_checked="$param" ;; "fpunch" | "fcollapse" | "zero" | "fzero" | "finsert" | "funshare") local blocksize=$(_get_block_size $TEST_DIR)
@@ -2119,7 +2119,7 @@ _require_xfs_io_command() fi testio=`$XFS_IO_PROG -F -f -c "pwrite 0 20k" -c "fsync" \ -c "fiemap -v $param" $testfile 2>&1` - param_checked=1 + param_checked="$param" ;; "flink") local testlink=$TEST_DIR/$$.link.xfs_io
@@ -2159,7 +2159,7 @@ _require_xfs_io_command() fi testio=`$XFS_IO_PROG -f $opts -c \ "pwrite $pwrite_opts $param 0 4k" $testfile 2>&1` - param_checked=1 + param_checked="$pwrite_opts $param" ;; "scrub"|"repair") testio=`$XFS_IO_PROG -x -c "$command probe" $TEST_DIR 2>&1`
@@ -2179,19 +2179,19 @@ _require_xfs_io_command() rm -f $testfile 2>&1 > /dev/null echo $testio | grep -q "not found" && \ - _notrun "xfs_io $command support is missing" + _notrun "xfs_io $command $param_checked support is missing" echo $testio | grep -q "Operation not supported\|Inappropriate ioctl" && \ - _notrun "xfs_io $command failed (old kernel/wrong fs?)" + _notrun "xfs_io $command $param_checked failed (old kernel/wrong fs?)" echo $testio | grep -q "Invalid" && \ - _notrun "xfs_io $command failed (old kernel/wrong fs/bad args?)" + _notrun "xfs_io $command $param_checked failed (old kernel/wrong fs/bad args?)" echo $testio | grep -q "foreign file active" && \ - _notrun "xfs_io $command not supported on $FSTYP" + _notrun "xfs_io $command $param_checked not supported on $FSTYP" echo $testio | grep -q "Function not implemented" && \ - _notrun "xfs_io $command support is missing (missing syscall?)" + _notrun "xfs_io $command $param_checked support is missing (missing syscall?)" [ -n "$param" ] || return - if [ $param_checked -eq 0 ]; then + if [ -z "$param_checked" ]; then $XFS_IO_PROG -c "help $command" | grep -q "^ $param --" || \ _notrun "xfs_io $command doesn't support $param" else
Signature · 1 line
2.17.1
PATCH 2/3 fstests: check for filesystem FS_IOC_FSSETXATTR support
In reply to Amir GoldsteinWith "_require_xfs_io_command chattr <letter>", check that flag can be set/cleared using FS_IOC_FSSETXATTR ioctl, similar to "_require_chattr <letter>" and FS_IOC_SETFLAGS ioctl.
Update the documentation and the tests that use "_require_xfs_io_command chattr" to test filesystem support and not only xfs_io support.
--- common/rc | 10 ++++++++++ doc/requirement-checking.txt | 2 +- tests/generic/553 | 3 +-- tests/xfs/260 | 2 +- tests/xfs/431 | 2 +- 5 files changed, 14 insertions(+), 5 deletions(-)
common/rc +10 -0
@@ -2090,6 +2090,16 @@ _require_xfs_io_command() local testfile=$TEST_DIR/$$.xfs_io local testio case $command in + "chattr") + if [ -z "$param" ]; then + param=s + fi + # Test xfs_io chattr support AND + # filesystem FS_IOC_FSSETXATTR support + testio=`$XFS_IO_PROG -F -f -c "chattr +$param" $testfile 2>&1` + $XFS_IO_PROG -F -f -r -c "chattr -$param" $testfile 2>&1 + param_checked="+$param" + ;; "chproj") testio=`$XFS_IO_PROG -F -f -c "chproj 0" $testfile 2>&1` ;;
doc/requirement-checking.txt +1 -1
@@ -69,7 +69,7 @@ _require_xfs_io_command <name> [<switch>] switch. For example: _require_xfs_io_command "falloc" - _require_xfs_io_command "chattr" "+/-x" + _require_xfs_io_command "chattr" "x" The first requires that xfs_io support the falloc command and the second that it supports the chattr command and that the chattr command supports
tests/generic/553 +1 -2
@@ -34,9 +34,8 @@ _supported_fs generic rm -f $seqres.full _require_test -_require_chattr i _require_xfs_io_command "copy_range" -_require_xfs_io_command "chattr" +_require_xfs_io_command "chattr" "i" rm -rf $workdir mkdir $workdir
tests/xfs/260 +1 -1
@@ -33,7 +33,7 @@ _supported_os Linux _require_scratch_dax _require_test_program "feature" _require_test_program "t_mmap_dio" -_require_xfs_io_command "chattr" "+/-x" +_require_xfs_io_command "chattr" "x" _require_xfs_io_command "falloc" prep_files()
tests/xfs/431 +1 -1
@@ -38,7 +38,7 @@ rm -f $seqres.full # Modify as appropriate. _supported_fs xfs _supported_os Linux -_require_xfs_io_command "chattr" +_require_xfs_io_command "chattr" "t" _require_xfs_io_command "fsync" _require_xfs_io_command "pwrite" _require_scratch
Signature · 1 line
2.17.1
PATCH 3/3 generic: check CAP_LINUX_IMMUTABLE capability with FS_IOC_FSSETXATTR
In reply to Amir GoldsteinThis is a flavor of test generic/545 with FS_IOC_FSSETXATTR ioctl instead of FS_IOC_SETFLAGS ioctl.
Overlayfs gained support for FS_IOC_FSSETXATTR ioctl in v5.2-rc4 with buggy capability check. This change fixed the problem:
ovl: fix wrong flags check in FS_IOC_FS[SG]ETXATTR ioctls
--- tests/generic/555 | 74 +++++++++++++++++++++++++++++++++++++++++++ tests/generic/555.out | 9 ++++++ tests/generic/group | 1 + 3 files changed, 84 insertions(+) create mode 100755 tests/generic/555 create mode 100644 tests/generic/555.out
tests/generic/555 new file +74 -0
@@ -0,0 +1,74 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (C) 2019 CTERA Networks. All Rights Reserved. +# +# FS QA Test No. 555 +# +# Check that we can't set FS_XFLAG_APPEND and FS_XFLAG_IMMUTABLE inode +# flags without capbility CAP_LINUX_IMMUTABLE. +# +# This test uses xfs_io chattr, rather than the (e2fsprogs) chattr +# program to exercise the FS_IOC_FSSETXATTR ioctl. +# +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() +{ + # Cleanup of flags on both file in case test is aborted + # (i.e. CTRL-C), so we have no immutable/append-only files + $XFS_IO_PROG -f -r -c "chattr -ia" $workdir/file1 >/dev/null 2>&1 + $XFS_IO_PROG -f -r -c "chattr -ia" $workdir/file2 >/dev/null 2>&1 + + cd / + rm -rf $tmp.* $workdir +} + +# get standard environment, filters and checks +. ./common/rc +. ./common/filter +. ./common/attr + +# real QA test starts here +_supported_os Linux +_supported_fs generic + +_require_test +_require_xfs_io_command "chattr" "ia" +_require_command "$CAPSH_PROG" "capsh" + +workdir="$TEST_DIR/test-$seq" +rm -rf $workdir +mkdir $workdir + +echo "Create the original files" +touch $workdir/file1 +touch $workdir/file2 + +do_filter_output() +{ + grep -o "Operation not permitted" +} + +echo "Try to xfs_io chattr +ia with capabilities CAP_LINUX_IMMUTABLE" +$XFS_IO_PROG -f -c "chattr +ia" $workdir/file1 + +echo "Try to xfs_io chattr +ia/-ia without capability CAP_LINUX_IMMUTABLE" +$CAPSH_PROG --drop=cap_linux_immutable -- -c "$XFS_IO_PROG -f -c 'chattr +a' $workdir/file2" 2>&1 | do_filter_output +$CAPSH_PROG --drop=cap_linux_immutable -- -c "$XFS_IO_PROG -f -c 'chattr +i' $workdir/file2" 2>&1 | do_filter_output + +$CAPSH_PROG --drop=cap_linux_immutable -- -c "$XFS_IO_PROG -f -r -c 'chattr -i' $workdir/file1" 2>&1 | do_filter_output +$CAPSH_PROG --drop=cap_linux_immutable -- -c "$XFS_IO_PROG -f -r -c 'chattr -a' $workdir/file1" 2>&1 | do_filter_output + +echo "Try to xfs_io chattr -ia with capability CAP_LINUX_IMMUTABLE" +$XFS_IO_PROG -f -r -c "chattr -ia" $workdir/file1 + +# success, all done +status=0 +exit
tests/generic/555.out new file +9 -0
@@ -0,0 +1,9 @@ +QA output created by 555 +Create the original files +Try to xfs_io chattr +ia with capabilities CAP_LINUX_IMMUTABLE +Try to xfs_io chattr +ia/-ia without capability CAP_LINUX_IMMUTABLE +Operation not permitted +Operation not permitted +Operation not permitted +Operation not permitted +Try to xfs_io chattr -ia with capability CAP_LINUX_IMMUTABLE
tests/generic/group +1 -0
@@ -557,3 +557,4 @@ 552 auto quick log 553 auto quick copy_range 554 auto quick copy_range swap +555 auto quick cap
Signature · 1 line
2.17.1