generic: test MADV_POPULATE_READ with IO errors
[xfstests-dev.git] / tests / generic / 684
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2022 Oracle.  All Rights Reserved.
4 #
5 # FS QA Test No. 684
6 #
7 # Functional test for dropping suid and sgid bits as part of a fpunch.
8 #
9 . ./common/preamble
10 _begin_fstest auto clone quick
11
12 # Override the default cleanup function.
13 _cleanup()
14 {
15         cd /
16         rm -r -f $tmp.* $junk_dir
17 }
18
19 # Import common functions.
20 . ./common/filter
21 . ./common/reflink
22
23 # real QA test starts here
24
25 # Modify as appropriate.
26 _supported_fs generic
27 _require_user
28 _require_test
29 verb=fpunch
30 _require_xfs_io_command $verb
31
32 junk_dir=$TEST_DIR/$seq
33 junk_file=$junk_dir/a
34 mkdir -p $junk_dir/
35 chmod a+rw $junk_dir/
36
37 setup_testfile() {
38         rm -f $junk_file
39         _pwrite_byte 0x58 0 192k $junk_file >> $seqres.full
40         sync
41 }
42
43 commit_and_check() {
44         local user="$1"
45         local command="$2"
46         local start="$3"
47         local end="$4"
48
49         stat -c '%a %A %n' $junk_file | _filter_test_dir
50
51         local cmd="$XFS_IO_PROG -c '$command $start $end' $junk_file"
52         if [ -n "$user" ]; then
53                 su - "$user" -c "$cmd" >> $seqres.full
54         else
55                 $SHELL -c "$cmd" >> $seqres.full
56         fi
57
58         stat -c '%a %A %n' $junk_file | _filter_test_dir
59
60         # Blank line in output
61         echo
62 }
63
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"
66 setup_testfile
67 chmod a+rws $junk_file
68 commit_and_check "$qa_user" "$verb" 64k 64k
69
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"
72 setup_testfile
73 chmod g+x,a+rws $junk_file
74 commit_and_check "$qa_user" "$verb" 64k 64k
75
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"
78 setup_testfile
79 chmod u+x,a+rws,g-x $junk_file
80 commit_and_check "$qa_user" "$verb" 64k 64k
81
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"
84 setup_testfile
85 chmod a+rwxs $junk_file
86 commit_and_check "$qa_user" "$verb" 64k 64k
87
88 # Commit to a non-exec file by root leaves suid and sgid.
89 echo "Test 5 - root, non-exec file $verb"
90 setup_testfile
91 chmod a+rws $junk_file
92 commit_and_check "" "$verb" 64k 64k
93
94 # Commit to a group-exec file by root leaves suid and sgid.
95 echo "Test 6 - root, group-exec file $verb"
96 setup_testfile
97 chmod g+x,a+rws $junk_file
98 commit_and_check "" "$verb" 64k 64k
99
100 # Commit to a user-exec file by root leaves suid and sgid.
101 echo "Test 7 - root, user-exec file $verb"
102 setup_testfile
103 chmod u+x,a+rws,g-x $junk_file
104 commit_and_check "" "$verb" 64k 64k
105
106 # Commit to a all-exec file by root leaves suid and sgid.
107 echo "Test 8 - root, all-exec file $verb"
108 setup_testfile
109 chmod a+rwxs $junk_file
110 commit_and_check "" "$verb" 64k 64k
111
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"
114 setup_testfile
115 chmod a+rw,g+rws $junk_file
116 commit_and_check "$qa_user" "$verb" 64k 64k
117
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"
120 setup_testfile
121 chmod a+rw,g+rwxs $junk_file
122 commit_and_check "$qa_user" "$verb" 64k 64k
123
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"
126 setup_testfile
127 chmod a+rw,u+x,g+rws $junk_file
128 commit_and_check "$qa_user" "$verb" 64k 64k
129
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"
132 setup_testfile
133 chmod a+rwx,g+rwxs $junk_file
134 commit_and_check "$qa_user" "$verb" 64k 64k
135
136 # success, all done
137 status=0
138 exit