generic: test MADV_POPULATE_READ with IO errors
[xfstests-dev.git] / tests / generic / 673
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2022 Oracle.  All Rights Reserved.
4 #
5 # FS QA Test No. 673
6 #
7 # Functional test for dropping suid and sgid bits as part of a reflink.
8 #
9 . ./common/preamble
10 _begin_fstest auto clone quick
11
12 # Import common functions.
13 . ./common/filter
14 . ./common/reflink
15
16 # real QA test starts here
17
18 # Modify as appropriate.
19 _supported_fs generic
20 _require_user
21 _require_scratch_reflink
22
23 _scratch_mkfs >> $seqres.full
24 _scratch_mount
25 chmod a+rw $SCRATCH_MNT/
26
27 setup_testfile() {
28         rm -f $SCRATCH_MNT/a $SCRATCH_MNT/b
29         _pwrite_byte 0x58 0 1m $SCRATCH_MNT/a >> $seqres.full
30         _pwrite_byte 0x57 0 1m $SCRATCH_MNT/b >> $seqres.full
31         chmod a+r $SCRATCH_MNT/b
32         sync
33 }
34
35 commit_and_check() {
36         local user="$1"
37
38         md5sum $SCRATCH_MNT/a | _filter_scratch
39         stat -c '%a %A %n' $SCRATCH_MNT/a | _filter_scratch
40
41         local cmd="$XFS_IO_PROG -c 'reflink $SCRATCH_MNT/b 0 0 1m' $SCRATCH_MNT/a"
42         if [ -n "$user" ]; then
43                 su - "$user" -c "$cmd" >> $seqres.full
44         else
45                 $SHELL -c "$cmd" >> $seqres.full
46         fi
47
48         _scratch_cycle_mount
49         md5sum $SCRATCH_MNT/a | _filter_scratch
50         stat -c '%a %A %n' $SCRATCH_MNT/a | _filter_scratch
51
52         # Blank line in output
53         echo
54 }
55
56 # Commit to a non-exec file by an unprivileged user clears suid and sgid
57 echo "Test 1 - qa_user, non-exec file"
58 setup_testfile
59 chmod a+rws $SCRATCH_MNT/a
60 commit_and_check "$qa_user"
61
62 # Commit to a group-exec file by an unprivileged user clears suid and sgid.
63 echo "Test 2 - qa_user, group-exec file"
64 setup_testfile
65 chmod g+x,a+rws $SCRATCH_MNT/a
66 commit_and_check "$qa_user"
67
68 # Commit to a user-exec file by an unprivileged user clears suid and sgid.
69 echo "Test 3 - qa_user, user-exec file"
70 setup_testfile
71 chmod u+x,a+rws,g-x $SCRATCH_MNT/a
72 commit_and_check "$qa_user"
73
74 # Commit to a all-exec file by an unprivileged user clears suid and sgid.
75 echo "Test 4 - qa_user, all-exec file"
76 setup_testfile
77 chmod a+rwxs $SCRATCH_MNT/a
78 commit_and_check "$qa_user"
79
80 # Commit to a non-exec file by root leaves suid and sgid.
81 echo "Test 5 - root, non-exec file"
82 setup_testfile
83 chmod a+rws $SCRATCH_MNT/a
84 commit_and_check
85
86 # Commit to a group-exec file by root leaves suid and sgid.
87 echo "Test 6 - root, group-exec file"
88 setup_testfile
89 chmod g+x,a+rws $SCRATCH_MNT/a
90 commit_and_check
91
92 # Commit to a user-exec file by root leaves suid and sgid.
93 echo "Test 7 - root, user-exec file"
94 setup_testfile
95 chmod u+x,a+rws,g-x $SCRATCH_MNT/a
96 commit_and_check
97
98 # Commit to a all-exec file by root leaves suid and sgid.
99 echo "Test 8 - root, all-exec file"
100 setup_testfile
101 chmod a+rwxs $SCRATCH_MNT/a
102 commit_and_check
103
104 #Commit to a non-exec file by an unprivileged user leaves sgid.
105 echo "Test 9 - qa_user, non-exec file, only sgid"
106 setup_testfile
107 chmod a+rw,g+rws $SCRATCH_MNT/a
108 commit_and_check "$qa_user"
109
110 #Commit to a group-exec file by an unprivileged user clears sgid
111 echo "Test 10 - qa_user, group-exec file, only sgid"
112 setup_testfile
113 chmod a+rw,g+rwxs $SCRATCH_MNT/a
114 commit_and_check "$qa_user"
115
116 #Commit to a user-exec file by an unprivileged user clears sgid
117 echo "Test 11 - qa_user, user-exec file, only sgid"
118 setup_testfile
119 chmod a+rw,u+x,g+rws $SCRATCH_MNT/a
120 commit_and_check "$qa_user"
121
122 #Commit to a all-exec file by an unprivileged user clears sgid.
123 echo "Test 12 - qa_user, all-exec file, only sgid"
124 setup_testfile
125 chmod a+rwx,g+rwxs $SCRATCH_MNT/a
126 commit_and_check "$qa_user"
127
128 # success, all done
129 status=0
130 exit