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 reflink.
10 _begin_fstest auto clone quick
12 # Import common functions.
16 # real QA test starts here
18 # Modify as appropriate.
21 _require_scratch_reflink
23 _scratch_mkfs >> $seqres.full
25 chmod a+rw $SCRATCH_MNT/
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
38 md5sum $SCRATCH_MNT/a | _filter_scratch
39 stat -c '%a %A %n' $SCRATCH_MNT/a | _filter_scratch
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
45 $SHELL -c "$cmd" >> $seqres.full
49 md5sum $SCRATCH_MNT/a | _filter_scratch
50 stat -c '%a %A %n' $SCRATCH_MNT/a | _filter_scratch
52 # Blank line in output
56 # Commit to a non-exec file by an unprivileged user clears suid and sgid
57 echo "Test 1 - qa_user, non-exec file"
59 chmod a+rws $SCRATCH_MNT/a
60 commit_and_check "$qa_user"
62 # Commit to a group-exec file by an unprivileged user clears suid and sgid.
63 echo "Test 2 - qa_user, group-exec file"
65 chmod g+x,a+rws $SCRATCH_MNT/a
66 commit_and_check "$qa_user"
68 # Commit to a user-exec file by an unprivileged user clears suid and sgid.
69 echo "Test 3 - qa_user, user-exec file"
71 chmod u+x,a+rws,g-x $SCRATCH_MNT/a
72 commit_and_check "$qa_user"
74 # Commit to a all-exec file by an unprivileged user clears suid and sgid.
75 echo "Test 4 - qa_user, all-exec file"
77 chmod a+rwxs $SCRATCH_MNT/a
78 commit_and_check "$qa_user"
80 # Commit to a non-exec file by root leaves suid and sgid.
81 echo "Test 5 - root, non-exec file"
83 chmod a+rws $SCRATCH_MNT/a
86 # Commit to a group-exec file by root leaves suid and sgid.
87 echo "Test 6 - root, group-exec file"
89 chmod g+x,a+rws $SCRATCH_MNT/a
92 # Commit to a user-exec file by root leaves suid and sgid.
93 echo "Test 7 - root, user-exec file"
95 chmod u+x,a+rws,g-x $SCRATCH_MNT/a
98 # Commit to a all-exec file by root leaves suid and sgid.
99 echo "Test 8 - root, all-exec file"
101 chmod a+rwxs $SCRATCH_MNT/a
104 #Commit to a non-exec file by an unprivileged user leaves sgid.
105 echo "Test 9 - qa_user, non-exec file, only sgid"
107 chmod a+rw,g+rws $SCRATCH_MNT/a
108 commit_and_check "$qa_user"
110 #Commit to a group-exec file by an unprivileged user clears sgid
111 echo "Test 10 - qa_user, group-exec file, only sgid"
113 chmod a+rw,g+rwxs $SCRATCH_MNT/a
114 commit_and_check "$qa_user"
116 #Commit to a user-exec file by an unprivileged user clears sgid
117 echo "Test 11 - qa_user, user-exec file, only sgid"
119 chmod a+rw,u+x,g+rws $SCRATCH_MNT/a
120 commit_and_check "$qa_user"
122 #Commit to a all-exec file by an unprivileged user clears sgid.
123 echo "Test 12 - qa_user, all-exec file, only sgid"
125 chmod a+rwx,g+rwxs $SCRATCH_MNT/a
126 commit_and_check "$qa_user"