diff options
author | Darrick J. Wong <djwong@kernel.org> | 2022-04-19 10:32:21 -0700 |
---|---|---|
committer | Zorro Lang <zlang@kernel.org> | 2022-04-27 02:54:00 +0800 |
commit | e81417a0964a36aed4392326f3736c116296f451 (patch) | |
tree | 3c7e9943e449a7b428727e10246faec5894acd1c | |
parent | 7f27a290aca8e45ec1f39b631cb6acf923917ca4 (diff) | |
download | xfstests-dev-e81417a0964a36aed4392326f3736c116296f451.tar.gz |
generic: ensure we drop suid after fallocate
fallocate changes file contents, so make sure that we drop privileges
and file capabilities after each fallocate operation.
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Zorro Lang <zlang@redhat.com>
Signed-off-by: Zorro Lang <zlang@kernel.org>
-rwxr-xr-x | tests/generic/683 | 127 | ||||
-rw-r--r-- | tests/generic/683.out | 33 | ||||
-rwxr-xr-x | tests/generic/684 | 127 | ||||
-rw-r--r-- | tests/generic/684.out | 33 | ||||
-rwxr-xr-x | tests/generic/685 | 127 | ||||
-rw-r--r-- | tests/generic/685.out | 33 | ||||
-rwxr-xr-x | tests/generic/686 | 127 | ||||
-rw-r--r-- | tests/generic/686.out | 33 | ||||
-rwxr-xr-x | tests/generic/687 | 127 | ||||
-rw-r--r-- | tests/generic/687.out | 33 | ||||
-rwxr-xr-x | tests/generic/688 | 77 | ||||
-rwxr-xr-x | tests/generic/688.out | 13 |
12 files changed, 890 insertions, 0 deletions
diff --git a/tests/generic/683 b/tests/generic/683 new file mode 100755 index 0000000000..c512989b9c --- /dev/null +++ b/tests/generic/683 @@ -0,0 +1,127 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (c) 2022 Oracle. All Rights Reserved. +# +# FS QA Test No. 683 +# +# Functional test for dropping suid and sgid bits as part of a fallocate. +# +. ./common/preamble +_begin_fstest auto clone quick + +# Override the default cleanup function. +_cleanup() +{ + cd / + rm -r -f $tmp.* $junk_dir +} + +# Import common functions. +. ./common/filter +. ./common/reflink + +# real QA test starts here + +# Modify as appropriate. +_supported_fs generic +_require_user +_require_test +verb=falloc +_require_xfs_io_command $verb + +junk_dir=$TEST_DIR/$seq +junk_file=$junk_dir/a +mkdir -p $junk_dir/ +chmod a+rw $junk_dir/ + +setup_testfile() { + rm -f $junk_file + _pwrite_byte 0x58 0 192k $junk_file >> $seqres.full + sync +} + +commit_and_check() { + local user="$1" + local command="$2" + local start="$3" + local end="$4" + + stat -c '%a %A %n' $junk_file | _filter_test_dir + + local cmd="$XFS_IO_PROG -c '$command $start $end' $junk_file" + if [ -n "$user" ]; then + su - "$user" -c "$cmd" >> $seqres.full + else + $SHELL -c "$cmd" >> $seqres.full + fi + + stat -c '%a %A %n' $junk_file | _filter_test_dir + + # Blank line in output + echo +} + +nr=0 +# Commit to a non-exec file by an unprivileged user clears suid but +# leaves sgid. +nr=$((nr + 1)) +echo "Test $nr - qa_user, non-exec file $verb" +setup_testfile +chmod a+rws $junk_file +commit_and_check "$qa_user" "$verb" 64k 64k + +# Commit to a group-exec file by an unprivileged user clears suid and +# sgid. +nr=$((nr + 1)) +echo "Test $nr - qa_user, group-exec file $verb" +setup_testfile +chmod g+x,a+rws $junk_file +commit_and_check "$qa_user" "$verb" 64k 64k + +# Commit to a user-exec file by an unprivileged user clears suid but +# not sgid. +nr=$((nr + 1)) +echo "Test $nr - qa_user, user-exec file $verb" +setup_testfile +chmod u+x,a+rws,g-x $junk_file +commit_and_check "$qa_user" "$verb" 64k 64k + +# Commit to a all-exec file by an unprivileged user clears suid and +# sgid. +nr=$((nr + 1)) +echo "Test $nr - qa_user, all-exec file $verb" +setup_testfile +chmod a+rwxs $junk_file +commit_and_check "$qa_user" "$verb" 64k 64k + +# Commit to a non-exec file by root clears suid but leaves sgid. +nr=$((nr + 1)) +echo "Test $nr - root, non-exec file $verb" +setup_testfile +chmod a+rws $junk_file +commit_and_check "" "$verb" 64k 64k + +# Commit to a group-exec file by root clears suid and sgid. +nr=$((nr + 1)) +echo "Test $nr - root, group-exec file $verb" +setup_testfile +chmod g+x,a+rws $junk_file +commit_and_check "" "$verb" 64k 64k + +# Commit to a user-exec file by root clears suid but not sgid. +nr=$((nr + 1)) +echo "Test $nr - root, user-exec file $verb" +setup_testfile +chmod u+x,a+rws,g-x $junk_file +commit_and_check "" "$verb" 64k 64k + +# Commit to a all-exec file by root clears suid and sgid. +nr=$((nr + 1)) +echo "Test $nr - root, all-exec file $verb" +setup_testfile +chmod a+rwxs $junk_file +commit_and_check "" "$verb" 64k 64k + +# success, all done +status=0 +exit diff --git a/tests/generic/683.out b/tests/generic/683.out new file mode 100644 index 0000000000..9d1c9f80fe --- /dev/null +++ b/tests/generic/683.out @@ -0,0 +1,33 @@ +QA output created by 683 +Test 1 - qa_user, non-exec file falloc +6666 -rwSrwSrw- TEST_DIR/683/a +666 -rw-rw-rw- TEST_DIR/683/a + +Test 2 - qa_user, group-exec file falloc +6676 -rwSrwsrw- TEST_DIR/683/a +676 -rw-rwxrw- TEST_DIR/683/a + +Test 3 - qa_user, user-exec file falloc +6766 -rwsrwSrw- TEST_DIR/683/a +766 -rwxrw-rw- TEST_DIR/683/a + +Test 4 - qa_user, all-exec file falloc +6777 -rwsrwsrwx TEST_DIR/683/a +777 -rwxrwxrwx TEST_DIR/683/a + +Test 5 - root, non-exec file falloc +6666 -rwSrwSrw- TEST_DIR/683/a +6666 -rwSrwSrw- TEST_DIR/683/a + +Test 6 - root, group-exec file falloc +6676 -rwSrwsrw- TEST_DIR/683/a +6676 -rwSrwsrw- TEST_DIR/683/a + +Test 7 - root, user-exec file falloc +6766 -rwsrwSrw- TEST_DIR/683/a +6766 -rwsrwSrw- TEST_DIR/683/a + +Test 8 - root, all-exec file falloc +6777 -rwsrwsrwx TEST_DIR/683/a +6777 -rwsrwsrwx TEST_DIR/683/a + diff --git a/tests/generic/684 b/tests/generic/684 new file mode 100755 index 0000000000..d59f4239d8 --- /dev/null +++ b/tests/generic/684 @@ -0,0 +1,127 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (c) 2022 Oracle. All Rights Reserved. +# +# FS QA Test No. 684 +# +# Functional test for dropping suid and sgid bits as part of a fpunch. +# +. ./common/preamble +_begin_fstest auto clone quick + +# Override the default cleanup function. +_cleanup() +{ + cd / + rm -r -f $tmp.* $junk_dir +} + +# Import common functions. +. ./common/filter +. ./common/reflink + +# real QA test starts here + +# Modify as appropriate. +_supported_fs generic +_require_user +_require_test +verb=fpunch +_require_xfs_io_command $verb + +junk_dir=$TEST_DIR/$seq +junk_file=$junk_dir/a +mkdir -p $junk_dir/ +chmod a+rw $junk_dir/ + +setup_testfile() { + rm -f $junk_file + _pwrite_byte 0x58 0 192k $junk_file >> $seqres.full + sync +} + +commit_and_check() { + local user="$1" + local command="$2" + local start="$3" + local end="$4" + + stat -c '%a %A %n' $junk_file | _filter_test_dir + + local cmd="$XFS_IO_PROG -c '$command $start $end' $junk_file" + if [ -n "$user" ]; then + su - "$user" -c "$cmd" >> $seqres.full + else + $SHELL -c "$cmd" >> $seqres.full + fi + + stat -c '%a %A %n' $junk_file | _filter_test_dir + + # Blank line in output + echo +} + +nr=0 +# Commit to a non-exec file by an unprivileged user clears suid but +# leaves sgid. +nr=$((nr + 1)) +echo "Test $nr - qa_user, non-exec file $verb" +setup_testfile +chmod a+rws $junk_file +commit_and_check "$qa_user" "$verb" 64k 64k + +# Commit to a group-exec file by an unprivileged user clears suid and +# sgid. +nr=$((nr + 1)) +echo "Test $nr - qa_user, group-exec file $verb" +setup_testfile +chmod g+x,a+rws $junk_file +commit_and_check "$qa_user" "$verb" 64k 64k + +# Commit to a user-exec file by an unprivileged user clears suid but +# not sgid. +nr=$((nr + 1)) +echo "Test $nr - qa_user, user-exec file $verb" +setup_testfile +chmod u+x,a+rws,g-x $junk_file +commit_and_check "$qa_user" "$verb" 64k 64k + +# Commit to a all-exec file by an unprivileged user clears suid and +# sgid. +nr=$((nr + 1)) +echo "Test $nr - qa_user, all-exec file $verb" +setup_testfile +chmod a+rwxs $junk_file +commit_and_check "$qa_user" "$verb" 64k 64k + +# Commit to a non-exec file by root clears suid but leaves sgid. +nr=$((nr + 1)) +echo "Test $nr - root, non-exec file $verb" +setup_testfile +chmod a+rws $junk_file +commit_and_check "" "$verb" 64k 64k + +# Commit to a group-exec file by root clears suid and sgid. +nr=$((nr + 1)) +echo "Test $nr - root, group-exec file $verb" +setup_testfile +chmod g+x,a+rws $junk_file +commit_and_check "" "$verb" 64k 64k + +# Commit to a user-exec file by root clears suid but not sgid. +nr=$((nr + 1)) +echo "Test $nr - root, user-exec file $verb" +setup_testfile +chmod u+x,a+rws,g-x $junk_file +commit_and_check "" "$verb" 64k 64k + +# Commit to a all-exec file by root clears suid and sgid. +nr=$((nr + 1)) +echo "Test $nr - root, all-exec file $verb" +setup_testfile +chmod a+rwxs $junk_file +commit_and_check "" "$verb" 64k 64k + +# success, all done +status=0 +exit diff --git a/tests/generic/684.out b/tests/generic/684.out new file mode 100644 index 0000000000..df5b37889e --- /dev/null +++ b/tests/generic/684.out @@ -0,0 +1,33 @@ +QA output created by 684 +Test 1 - qa_user, non-exec file fpunch +6666 -rwSrwSrw- TEST_DIR/684/a +666 -rw-rw-rw- TEST_DIR/684/a + +Test 2 - qa_user, group-exec file fpunch +6676 -rwSrwsrw- TEST_DIR/684/a +676 -rw-rwxrw- TEST_DIR/684/a + +Test 3 - qa_user, user-exec file fpunch +6766 -rwsrwSrw- TEST_DIR/684/a +766 -rwxrw-rw- TEST_DIR/684/a + +Test 4 - qa_user, all-exec file fpunch +6777 -rwsrwsrwx TEST_DIR/684/a +777 -rwxrwxrwx TEST_DIR/684/a + +Test 5 - root, non-exec file fpunch +6666 -rwSrwSrw- TEST_DIR/684/a +6666 -rwSrwSrw- TEST_DIR/684/a + +Test 6 - root, group-exec file fpunch +6676 -rwSrwsrw- TEST_DIR/684/a +6676 -rwSrwsrw- TEST_DIR/684/a + +Test 7 - root, user-exec file fpunch +6766 -rwsrwSrw- TEST_DIR/684/a +6766 -rwsrwSrw- TEST_DIR/684/a + +Test 8 - root, all-exec file fpunch +6777 -rwsrwsrwx TEST_DIR/684/a +6777 -rwsrwsrwx TEST_DIR/684/a + diff --git a/tests/generic/685 b/tests/generic/685 new file mode 100755 index 0000000000..2e990465c3 --- /dev/null +++ b/tests/generic/685 @@ -0,0 +1,127 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (c) 2022 Oracle. All Rights Reserved. +# +# FS QA Test No. 685 +# +# Functional test for dropping suid and sgid bits as part of a fzero. +# +. ./common/preamble +_begin_fstest auto clone quick + +# Override the default cleanup function. +_cleanup() +{ + cd / + rm -r -f $tmp.* $junk_dir +} + +# Import common functions. +. ./common/filter +. ./common/reflink + +# real QA test starts here + +# Modify as appropriate. +_supported_fs generic +_require_user +_require_test +verb=fzero +_require_xfs_io_command $verb + +junk_dir=$TEST_DIR/$seq +junk_file=$junk_dir/a +mkdir -p $junk_dir/ +chmod a+rw $junk_dir/ + +setup_testfile() { + rm -f $junk_file + _pwrite_byte 0x58 0 192k $junk_file >> $seqres.full + sync +} + +commit_and_check() { + local user="$1" + local command="$2" + local start="$3" + local end="$4" + + stat -c '%a %A %n' $junk_file | _filter_test_dir + + local cmd="$XFS_IO_PROG -c '$command $start $end' $junk_file" + if [ -n "$user" ]; then + su - "$user" -c "$cmd" >> $seqres.full + else + $SHELL -c "$cmd" >> $seqres.full + fi + + stat -c '%a %A %n' $junk_file | _filter_test_dir + + # Blank line in output + echo +} + +nr=0 +# Commit to a non-exec file by an unprivileged user clears suid but +# leaves sgid. +nr=$((nr + 1)) +echo "Test $nr - qa_user, non-exec file $verb" +setup_testfile +chmod a+rws $junk_file +commit_and_check "$qa_user" "$verb" 64k 64k + +# Commit to a group-exec file by an unprivileged user clears suid and +# sgid. +nr=$((nr + 1)) +echo "Test $nr - qa_user, group-exec file $verb" +setup_testfile +chmod g+x,a+rws $junk_file +commit_and_check "$qa_user" "$verb" 64k 64k + +# Commit to a user-exec file by an unprivileged user clears suid but +# not sgid. +nr=$((nr + 1)) +echo "Test $nr - qa_user, user-exec file $verb" +setup_testfile +chmod u+x,a+rws,g-x $junk_file +commit_and_check "$qa_user" "$verb" 64k 64k + +# Commit to a all-exec file by an unprivileged user clears suid and +# sgid. +nr=$((nr + 1)) +echo "Test $nr - qa_user, all-exec file $verb" +setup_testfile +chmod a+rwxs $junk_file +commit_and_check "$qa_user" "$verb" 64k 64k + +# Commit to a non-exec file by root clears suid but leaves sgid. +nr=$((nr + 1)) +echo "Test $nr - root, non-exec file $verb" +setup_testfile +chmod a+rws $junk_file +commit_and_check "" "$verb" 64k 64k + +# Commit to a group-exec file by root clears suid and sgid. +nr=$((nr + 1)) +echo "Test $nr - root, group-exec file $verb" +setup_testfile +chmod g+x,a+rws $junk_file +commit_and_check "" "$verb" 64k 64k + +# Commit to a user-exec file by root clears suid but not sgid. +nr=$((nr + 1)) +echo "Test $nr - root, user-exec file $verb" +setup_testfile +chmod u+x,a+rws,g-x $junk_file +commit_and_check "" "$verb" 64k 64k + +# Commit to a all-exec file by root clears suid and sgid. +nr=$((nr + 1)) +echo "Test $nr - root, all-exec file $verb" +setup_testfile +chmod a+rwxs $junk_file +commit_and_check "" "$verb" 64k 64k + +# success, all done +status=0 +exit diff --git a/tests/generic/685.out b/tests/generic/685.out new file mode 100644 index 0000000000..90b7a0de5d --- /dev/null +++ b/tests/generic/685.out @@ -0,0 +1,33 @@ +QA output created by 685 +Test 1 - qa_user, non-exec file fzero +6666 -rwSrwSrw- TEST_DIR/685/a +666 -rw-rw-rw- TEST_DIR/685/a + +Test 2 - qa_user, group-exec file fzero +6676 -rwSrwsrw- TEST_DIR/685/a +676 -rw-rwxrw- TEST_DIR/685/a + +Test 3 - qa_user, user-exec file fzero +6766 -rwsrwSrw- TEST_DIR/685/a +766 -rwxrw-rw- TEST_DIR/685/a + +Test 4 - qa_user, all-exec file fzero +6777 -rwsrwsrwx TEST_DIR/685/a +777 -rwxrwxrwx TEST_DIR/685/a + +Test 5 - root, non-exec file fzero +6666 -rwSrwSrw- TEST_DIR/685/a +6666 -rwSrwSrw- TEST_DIR/685/a + +Test 6 - root, group-exec file fzero +6676 -rwSrwsrw- TEST_DIR/685/a +6676 -rwSrwsrw- TEST_DIR/685/a + +Test 7 - root, user-exec file fzero +6766 -rwsrwSrw- TEST_DIR/685/a +6766 -rwsrwSrw- TEST_DIR/685/a + +Test 8 - root, all-exec file fzero +6777 -rwsrwsrwx TEST_DIR/685/a +6777 -rwsrwsrwx TEST_DIR/685/a + diff --git a/tests/generic/686 b/tests/generic/686 new file mode 100755 index 0000000000..71c3aebb35 --- /dev/null +++ b/tests/generic/686 @@ -0,0 +1,127 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (c) 2022 Oracle. All Rights Reserved. +# +# FS QA Test No. 686 +# +# Functional test for dropping suid and sgid bits as part of a finsert. +# +. ./common/preamble +_begin_fstest auto clone quick + +# Override the default cleanup function. +_cleanup() +{ + cd / + rm -r -f $tmp.* $junk_dir +} + +# Import common functions. +. ./common/filter +. ./common/reflink + +# real QA test starts here + +# Modify as appropriate. +_supported_fs generic +_require_user +_require_test +verb=finsert +_require_xfs_io_command $verb + +junk_dir=$TEST_DIR/$seq +junk_file=$junk_dir/a +mkdir -p $junk_dir/ +chmod a+rw $junk_dir/ + +setup_testfile() { + rm -f $junk_file + _pwrite_byte 0x58 0 192k $junk_file >> $seqres.full + sync +} + +commit_and_check() { + local user="$1" + local command="$2" + local start="$3" + local end="$4" + + stat -c '%a %A %n' $junk_file | _filter_test_dir + + local cmd="$XFS_IO_PROG -c '$command $start $end' $junk_file" + if [ -n "$user" ]; then + su - "$user" -c "$cmd" >> $seqres.full + else + $SHELL -c "$cmd" >> $seqres.full + fi + + stat -c '%a %A %n' $junk_file | _filter_test_dir + + # Blank line in output + echo +} + +nr=0 +# Commit to a non-exec file by an unprivileged user clears suid but +# leaves sgid. +nr=$((nr + 1)) +echo "Test $nr - qa_user, non-exec file $verb" +setup_testfile +chmod a+rws $junk_file +commit_and_check "$qa_user" "$verb" 64k 64k + +# Commit to a group-exec file by an unprivileged user clears suid and +# sgid. +nr=$((nr + 1)) +echo "Test $nr - qa_user, group-exec file $verb" +setup_testfile +chmod g+x,a+rws $junk_file +commit_and_check "$qa_user" "$verb" 64k 64k + +# Commit to a user-exec file by an unprivileged user clears suid but +# not sgid. +nr=$((nr + 1)) +echo "Test $nr - qa_user, user-exec file $verb" +setup_testfile +chmod u+x,a+rws,g-x $junk_file +commit_and_check "$qa_user" "$verb" 64k 64k + +# Commit to a all-exec file by an unprivileged user clears suid and +# sgid. +nr=$((nr + 1)) +echo "Test $nr - qa_user, all-exec file $verb" +setup_testfile +chmod a+rwxs $junk_file +commit_and_check "$qa_user" "$verb" 64k 64k + +# Commit to a non-exec file by root clears suid but leaves sgid. +nr=$((nr + 1)) +echo "Test $nr - root, non-exec file $verb" +setup_testfile +chmod a+rws $junk_file +commit_and_check "" "$verb" 64k 64k + +# Commit to a group-exec file by root clears suid and sgid. +nr=$((nr + 1)) +echo "Test $nr - root, group-exec file $verb" +setup_testfile +chmod g+x,a+rws $junk_file +commit_and_check "" "$verb" 64k 64k + +# Commit to a user-exec file by root clears suid but not sgid. +nr=$((nr + 1)) +echo "Test $nr - root, user-exec file $verb" +setup_testfile +chmod u+x,a+rws,g-x $junk_file +commit_and_check "" "$verb" 64k 64k + +# Commit to a all-exec file by root clears suid and sgid. +nr=$((nr + 1)) +echo "Test $nr - root, all-exec file $verb" +setup_testfile +chmod a+rwxs $junk_file +commit_and_check "" "$verb" 64k 64k + +# success, all done +status=0 +exit diff --git a/tests/generic/686.out b/tests/generic/686.out new file mode 100644 index 0000000000..6a1179f1ed --- /dev/null +++ b/tests/generic/686.out @@ -0,0 +1,33 @@ +QA output created by 686 +Test 1 - qa_user, non-exec file finsert +6666 -rwSrwSrw- TEST_DIR/686/a +666 -rw-rw-rw- TEST_DIR/686/a + +Test 2 - qa_user, group-exec file finsert +6676 -rwSrwsrw- TEST_DIR/686/a +676 -rw-rwxrw- TEST_DIR/686/a + +Test 3 - qa_user, user-exec file finsert +6766 -rwsrwSrw- TEST_DIR/686/a +766 -rwxrw-rw- TEST_DIR/686/a + +Test 4 - qa_user, all-exec file finsert +6777 -rwsrwsrwx TEST_DIR/686/a +777 -rwxrwxrwx TEST_DIR/686/a + +Test 5 - root, non-exec file finsert +6666 -rwSrwSrw- TEST_DIR/686/a +6666 -rwSrwSrw- TEST_DIR/686/a + +Test 6 - root, group-exec file finsert +6676 -rwSrwsrw- TEST_DIR/686/a +6676 -rwSrwsrw- TEST_DIR/686/a + +Test 7 - root, user-exec file finsert +6766 -rwsrwSrw- TEST_DIR/686/a +6766 -rwsrwSrw- TEST_DIR/686/a + +Test 8 - root, all-exec file finsert +6777 -rwsrwsrwx TEST_DIR/686/a +6777 -rwsrwsrwx TEST_DIR/686/a + diff --git a/tests/generic/687 b/tests/generic/687 new file mode 100755 index 0000000000..7bdfcd5c09 --- /dev/null +++ b/tests/generic/687 @@ -0,0 +1,127 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (c) 2022 Oracle. All Rights Reserved. +# +# FS QA Test No. 687 +# +# Functional test for dropping suid and sgid bits as part of a fcollapse. +# +. ./common/preamble +_begin_fstest auto clone quick + +# Override the default cleanup function. +_cleanup() +{ + cd / + rm -r -f $tmp.* $junk_dir +} + +# Import common functions. +. ./common/filter +. ./common/reflink + +# real QA test starts here + +# Modify as appropriate. +_supported_fs generic +_require_user +_require_test +verb=fcollapse +_require_xfs_io_command $verb + +junk_dir=$TEST_DIR/$seq +junk_file=$junk_dir/a +mkdir -p $junk_dir/ +chmod a+rw $junk_dir/ + +setup_testfile() { + rm -f $junk_file + _pwrite_byte 0x58 0 192k $junk_file >> $seqres.full + sync +} + +commit_and_check() { + local user="$1" + local command="$2" + local start="$3" + local end="$4" + + stat -c '%a %A %n' $junk_file | _filter_test_dir + + local cmd="$XFS_IO_PROG -c '$command $start $end' $junk_file" + if [ -n "$user" ]; then + su - "$user" -c "$cmd" >> $seqres.full + else + $SHELL -c "$cmd" >> $seqres.full + fi + + stat -c '%a %A %n' $junk_file | _filter_test_dir + + # Blank line in output + echo +} + +nr=0 +# Commit to a non-exec file by an unprivileged user clears suid but +# leaves sgid. +nr=$((nr + 1)) +echo "Test $nr - qa_user, non-exec file $verb" +setup_testfile +chmod a+rws $junk_file +commit_and_check "$qa_user" "$verb" 64k 64k + +# Commit to a group-exec file by an unprivileged user clears suid and +# sgid. +nr=$((nr + 1)) +echo "Test $nr - qa_user, group-exec file $verb" +setup_testfile +chmod g+x,a+rws $junk_file +commit_and_check "$qa_user" "$verb" 64k 64k + +# Commit to a user-exec file by an unprivileged user clears suid but +# not sgid. +nr=$((nr + 1)) +echo "Test $nr - qa_user, user-exec file $verb" +setup_testfile +chmod u+x,a+rws,g-x $junk_file +commit_and_check "$qa_user" "$verb" 64k 64k + +# Commit to a all-exec file by an unprivileged user clears suid and +# sgid. +nr=$((nr + 1)) +echo "Test $nr - qa_user, all-exec file $verb" +setup_testfile +chmod a+rwxs $junk_file +commit_and_check "$qa_user" "$verb" 64k 64k + +# Commit to a non-exec file by root clears suid but leaves sgid. +nr=$((nr + 1)) +echo "Test $nr - root, non-exec file $verb" +setup_testfile +chmod a+rws $junk_file +commit_and_check "" "$verb" 64k 64k + +# Commit to a group-exec file by root clears suid and sgid. +nr=$((nr + 1)) +echo "Test $nr - root, group-exec file $verb" +setup_testfile +chmod g+x,a+rws $junk_file +commit_and_check "" "$verb" 64k 64k + +# Commit to a user-exec file by root clears suid but not sgid. +nr=$((nr + 1)) +echo "Test $nr - root, user-exec file $verb" +setup_testfile +chmod u+x,a+rws,g-x $junk_file +commit_and_check "" "$verb" 64k 64k + +# Commit to a all-exec file by root clears suid and sgid. +nr=$((nr + 1)) +echo "Test $nr - root, all-exec file $verb" +setup_testfile +chmod a+rwxs $junk_file +commit_and_check "" "$verb" 64k 64k + +# success, all done +status=0 +exit diff --git a/tests/generic/687.out b/tests/generic/687.out new file mode 100644 index 0000000000..7f945d7287 --- /dev/null +++ b/tests/generic/687.out @@ -0,0 +1,33 @@ +QA output created by 687 +Test 1 - qa_user, non-exec file fcollapse +6666 -rwSrwSrw- TEST_DIR/687/a +666 -rw-rw-rw- TEST_DIR/687/a + +Test 2 - qa_user, group-exec file fcollapse +6676 -rwSrwsrw- TEST_DIR/687/a +676 -rw-rwxrw- TEST_DIR/687/a + +Test 3 - qa_user, user-exec file fcollapse +6766 -rwsrwSrw- TEST_DIR/687/a +766 -rwxrw-rw- TEST_DIR/687/a + +Test 4 - qa_user, all-exec file fcollapse +6777 -rwsrwsrwx TEST_DIR/687/a +777 -rwxrwxrwx TEST_DIR/687/a + +Test 5 - root, non-exec file fcollapse +6666 -rwSrwSrw- TEST_DIR/687/a +6666 -rwSrwSrw- TEST_DIR/687/a + +Test 6 - root, group-exec file fcollapse +6676 -rwSrwsrw- TEST_DIR/687/a +6676 -rwSrwsrw- TEST_DIR/687/a + +Test 7 - root, user-exec file fcollapse +6766 -rwsrwSrw- TEST_DIR/687/a +6766 -rwsrwSrw- TEST_DIR/687/a + +Test 8 - root, all-exec file fcollapse +6777 -rwsrwsrwx TEST_DIR/687/a +6777 -rwsrwsrwx TEST_DIR/687/a + diff --git a/tests/generic/688 b/tests/generic/688 new file mode 100755 index 0000000000..905c46ac62 --- /dev/null +++ b/tests/generic/688 @@ -0,0 +1,77 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (c) 2022 Oracle. All Rights Reserved. +# +# FS QA Test No. 688 +# +# Functional test for dropping capability bits as part of an fallocate. +# +. ./common/preamble +_begin_fstest auto prealloc quick + +# Override the default cleanup function. +_cleanup() +{ + cd / + rm -r -f $tmp.* $junk_dir +} + +# Import common functions. +. ./common/filter + +# real QA test starts here + +# Modify as appropriate. +_supported_fs generic +_require_user +_require_command "$GETCAP_PROG" getcap +_require_command "$SETCAP_PROG" setcap +_require_xfs_io_command falloc +_require_test + +junk_dir=$TEST_DIR/$seq +junk_file=$junk_dir/a +mkdir -p $junk_dir/ +chmod a+rw $junk_dir/ + +setup_testfile() { + rm -f $junk_file + touch $junk_file + chmod a+rwx $junk_file + $SETCAP_PROG cap_setgid,cap_setuid+ep $junk_file + sync +} + +commit_and_check() { + local user="$1" + + stat -c '%a %A %n' $junk_file | _filter_test_dir + _getcap -v $junk_file | _filter_test_dir + + local cmd="$XFS_IO_PROG -c 'falloc 0 64k' $junk_file" + if [ -n "$user" ]; then + su - "$user" -c "$cmd" >> $seqres.full + else + $SHELL -c "$cmd" >> $seqres.full + fi + + stat -c '%a %A %n' $junk_file | _filter_test_dir + _getcap -v $junk_file | _filter_test_dir + + # Blank line in output + echo +} + +# Commit by an unprivileged user clears capability bits. +echo "Test 1 - qa_user" +setup_testfile +commit_and_check "$qa_user" + +# Commit by root leaves capability bits. +echo "Test 2 - root" +setup_testfile +commit_and_check + +# success, all done +status=0 +exit diff --git a/tests/generic/688.out b/tests/generic/688.out new file mode 100755 index 0000000000..7a921981c4 --- /dev/null +++ b/tests/generic/688.out @@ -0,0 +1,13 @@ +QA output created by 688 +Test 1 - qa_user +777 -rwxrwxrwx TEST_DIR/688/a +TEST_DIR/688/a cap_setgid,cap_setuid=ep +777 -rwxrwxrwx TEST_DIR/688/a +TEST_DIR/688/a + +Test 2 - root +777 -rwxrwxrwx TEST_DIR/688/a +TEST_DIR/688/a cap_setgid,cap_setuid=ep +777 -rwxrwxrwx TEST_DIR/688/a +TEST_DIR/688/a + |