generic: add a testcase to check the capability CAP_LINUX_IMMUTABLE
PATCH 1/1 generic: add a testcase to check the capability CAP_LINUX_IMMUTABLE
It should return error while changing IMMUTABLE_FL flag if the process has no capability CAP_LINUX_IMMUTABLE.
However, it's not true on overlayfs after kernel version v4.19 since the process's subjective cred is overridden with ofs->creator_cred before calling real vfs_ioctl.
The following patch for ovl fix the problem:
"ovl: check the capability before cred overridden"
Add this testcase to cover this bug.
--- common/config | 1 + tests/generic/545 | 61 +++++++++++++++++++++++++++++++++++++++++++ tests/generic/545.out | 5 ++++ tests/generic/group | 1 + 4 files changed, 68 insertions(+) create mode 100755 tests/generic/545 create mode 100755 tests/generic/545.out
common/config +1 -0
@@ -196,6 +196,7 @@ export SQLITE3_PROG="$(type -P sqlite3)" export TIMEOUT_PROG="$(type -P timeout)" export SETCAP_PROG="$(type -P setcap)" export GETCAP_PROG="$(type -P getcap)" +export CAPSH_PROG="$(type -P capsh)" export CHECKBASHISMS_PROG="$(type -P checkbashisms)" export XFS_INFO_PROG="$(type -P xfs_info)" export DUPEREMOVE_PROG="$(type -P duperemove)"
tests/generic/545 new file +61 -0
61 lines not on this page · raw message
tests/generic/545.out new file +5 -0
@@ -0,0 +1,5 @@ +QA output created by 545 +Format and mount +Create the original files +Try to add IMMUTABLE_FL flag +Operation not permitted
tests/generic/group +1 -0
@@ -547,3 +547,4 @@ 542 auto quick clone 543 auto quick clone 544 auto quick clone +545 auto quick clone
Signature · 1 line
2.19.1.856.g8858448bb
Quoted 41 lines · Jiufei Xue
It should return error while changing
IMMUTABLE_FLflag if the process has no capabilityCAP_LINUX_IMMUTABLE.However, it's not true on overlayfs after kernel version v4.19 since the process's subjective cred is overridden with
ofs->creator_credbefore calling realvfs_ioctl.The following patch for ovl fix the problem:
"ovl: check the capability before cred overridden"Add this testcase to cover this bug.
Signed-off-by Jiufei Xue <[email protected]>--- common/config | 1 + tests/generic/545 | 61 +++++++++++++++++++++++++++++++++++++++++++ tests/generic/545.out | 5 ++++ tests/generic/group | 1 + 4 files changed, 68 insertions(+) create mode 100755 tests/generic/545 create mode 100755 tests/generic/545.outcommon/config +1
-0@@ -196,6 +196,7 @@ export SQLITE3_PROG="$(type -P sqlite3)" export TIMEOUT_PROG="$(type -P timeout)" export SETCAP_PROG="$(type -P setcap)" export GETCAP_PROG="$(type -P getcap)" +export CAPSH_PROG="$(type -P capsh)" export CHECKBASHISMS_PROG="$(type -P checkbashisms)" export XFS_INFO_PROG="$(type -P xfs_info)" export DUPEREMOVE_PROG="$(type -P duperemove)"tests/generic/545 new file +0
-0
tests/generic/545 line 3
Quoted 3 lines
tests/generic/545 new file +3
-0@@ -0,0 +1,61 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (c) 2015, Oracle and/or its affiliates. All Rights Reserved.
Wrongly copied.
tests/generic/545 line 8
Quoted 5 lines
tests/generic/545 new file +5
-0+# +# FS QA Test No. 545 +# +# Check that we can't add IMMUTABLE_FL flag to file when the process has +# no capbility CAP_LINUX_IMMUTABLE
Better check APPEND_FL while at it. Trivial to add. Another think worth testing is chattr -i, so for example you could
touch foo bar
chattr +ia foo
capsh...
chattr +a bar # fail
chattr +i bar # fail
chattr -i foo # fail
chattr -a foo # fail
Order matters, because after Darrick's patches
chattr -/+a on immutable file should fail regardless of capabilities.
Quoted 30 lines
tests/generic/545 new file +30
-0+# +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() +{ + $CHATTR_PROG -i $testdir/file 2>&1 + cd / + rm -rf $tmp.* $testdir +} + +# get standard environment, filters and checks +. ./common/rc +. ./common/filter +. ./common/attr + +# real QA test starts here +_supported_os Linux +_require_chattr i +_require_command "$CAPSH_PROG" "capsh" + +rm -f $seqres.full + +echo "Format and mount"
tests/generic/545 line 48
Quoted 10 lines
tests/generic/545 new file +10
-0+testdir="$TEST_DIR/test-$seq" +rm -rf $testdir +mkdir $testdir + +echo "Create the original files" +blksz="$(_get_block_size $testdir)" +blks=1000 +sz=$((blksz * blks)) +_pwrite_byte 0x61 0 $sz $testdir/file >> $seqres.full +sync
touch $testdir/file is plenty enough
Quoted 29 lines
tests/generic/545 new file +13
-0+ +do_filter_output() +{ + err_str=`_filter_test_dir | grep "Operation not permitted"` + test -n "$err_str" && echo "Operation not permitted" +} + +echo "Try to add IMMUTABLE_FL flag" +$CAPSH_PROG --drop=cap_linux_immutable -- -c "$CHATTR_PROG +i $testdir/file" 2>&1 | do_filter_output + +# success, all done +status=0 +exittests/generic/545.out new file +5
-0@@ -0,0 +1,5 @@ +QA output created by 545 +Format and mount +Create the original files +Try to add IMMUTABLE_FL flag +Operation not permittedtests/generic/group +0
-0
tests/generic/group line 550
Quoted 4 lines
tests/generic/group +1
-0@@ -547,3 +547,4 @@ 542 auto quick clone 543 auto quick clone 544 auto quick clone +545 auto quick clone
Not 'clone'. Perhaps 'cap', although from the 5 tests that use setcap, only one uses this tag.
You may send another patch to amend that if you want.
Thanks,
Amir.