2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2022 Oracle. All Rights Reserved.
7 # Functional test for dropping suid and sgid bits as part of a fzero.
10 _begin_fstest auto clone quick
12 # Override the default cleanup function.
16 rm -r -f $tmp.* $junk_dir
19 # Import common functions.
23 # real QA test starts here
25 # Modify as appropriate.
30 _require_xfs_io_command $verb
32 junk_dir=$TEST_DIR/$seq
39 _pwrite_byte 0x58 0 192k $junk_file >> $seqres.full
49 stat -c '%a %A %n' $junk_file | _filter_test_dir
51 local cmd="$XFS_IO_PROG -c '$command $start $end' $junk_file"
52 if [ -n "$user" ]; then
53 su - "$user" -c "$cmd" >> $seqres.full
55 $SHELL -c "$cmd" >> $seqres.full
58 stat -c '%a %A %n' $junk_file | _filter_test_dir
60 # Blank line in output
65 # Commit to a non-exec file by an unprivileged user clears suid but
68 echo "Test $nr - qa_user, non-exec file $verb"
70 chmod a+rws $junk_file
71 commit_and_check "$qa_user" "$verb" 64k 64k
73 # Commit to a group-exec file by an unprivileged user clears suid and
76 echo "Test $nr - qa_user, group-exec file $verb"
78 chmod g+x,a+rws $junk_file
79 commit_and_check "$qa_user" "$verb" 64k 64k
81 # Commit to a user-exec file by an unprivileged user clears suid but
84 echo "Test $nr - qa_user, user-exec file $verb"
86 chmod u+x,a+rws,g-x $junk_file
87 commit_and_check "$qa_user" "$verb" 64k 64k
89 # Commit to a all-exec file by an unprivileged user clears suid and
92 echo "Test $nr - qa_user, all-exec file $verb"
94 chmod a+rwxs $junk_file
95 commit_and_check "$qa_user" "$verb" 64k 64k
97 # Commit to a non-exec file by root clears suid but leaves sgid.
99 echo "Test $nr - root, non-exec file $verb"
101 chmod a+rws $junk_file
102 commit_and_check "" "$verb" 64k 64k
104 # Commit to a group-exec file by root clears suid and sgid.
106 echo "Test $nr - root, group-exec file $verb"
108 chmod g+x,a+rws $junk_file
109 commit_and_check "" "$verb" 64k 64k
111 # Commit to a user-exec file by root clears suid but not sgid.
113 echo "Test $nr - root, user-exec file $verb"
115 chmod u+x,a+rws,g-x $junk_file
116 commit_and_check "" "$verb" 64k 64k
118 # Commit to a all-exec file by root clears suid and sgid.
120 echo "Test $nr - root, all-exec file $verb"
122 chmod a+rwxs $junk_file
123 commit_and_check "" "$verb" 64k 64k