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 fpunch.
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
64 # Commit to a non-exec file by an unprivileged user clears suid and sgid.
65 echo "Test 1 - qa_user, non-exec file $verb"
67 chmod a+rws $junk_file
68 commit_and_check "$qa_user" "$verb" 64k 64k
70 # Commit to a group-exec file by an unprivileged user clears suid and sgid.
71 echo "Test 2 - qa_user, group-exec file $verb"
73 chmod g+x,a+rws $junk_file
74 commit_and_check "$qa_user" "$verb" 64k 64k
76 # Commit to a user-exec file by an unprivileged user clears suid and sgid.
77 echo "Test 3 - qa_user, user-exec file $verb"
79 chmod u+x,a+rws,g-x $junk_file
80 commit_and_check "$qa_user" "$verb" 64k 64k
82 # Commit to a all-exec file by an unprivileged user clears suid and sgid.
83 echo "Test 4 - qa_user, all-exec file $verb"
85 chmod a+rwxs $junk_file
86 commit_and_check "$qa_user" "$verb" 64k 64k
88 # Commit to a non-exec file by root leaves suid and sgid.
89 echo "Test 5 - root, non-exec file $verb"
91 chmod a+rws $junk_file
92 commit_and_check "" "$verb" 64k 64k
94 # Commit to a group-exec file by root leaves suid and sgid.
95 echo "Test 6 - root, group-exec file $verb"
97 chmod g+x,a+rws $junk_file
98 commit_and_check "" "$verb" 64k 64k
100 # Commit to a user-exec file by root leaves suid and sgid.
101 echo "Test 7 - root, user-exec file $verb"
103 chmod u+x,a+rws,g-x $junk_file
104 commit_and_check "" "$verb" 64k 64k
106 # Commit to a all-exec file by root leaves suid and sgid.
107 echo "Test 8 - root, all-exec file $verb"
109 chmod a+rwxs $junk_file
110 commit_and_check "" "$verb" 64k 64k
112 # Commit to a non-exec file by an unprivileged user leaves sgid.
113 echo "Test 9 - qa_user, non-exec file $verb, only sgid"
115 chmod a+rw,g+rws $junk_file
116 commit_and_check "$qa_user" "$verb" 64k 64k
118 # Commit to a group-exec file by an unprivileged user clears sgid
119 echo "Test 10 - qa_user, group-exec file $verb, only sgid"
121 chmod a+rw,g+rwxs $junk_file
122 commit_and_check "$qa_user" "$verb" 64k 64k
124 # Commit to a user-exec file by an unprivileged user clears sgid
125 echo "Test 11 - qa_user, user-exec file $verb, only sgid"
127 chmod a+rw,u+x,g+rws $junk_file
128 commit_and_check "$qa_user" "$verb" 64k 64k
130 # Commit to a all-exec file by an unprivileged user clears sgid.
131 echo "Test 12 - qa_user, all-exec file $verb, only sgid"
133 chmod a+rwx,g+rwxs $junk_file
134 commit_and_check "$qa_user" "$verb" 64k 64k