generic: ensure we drop suid after fallocate
[xfstests-dev.git] / tests / generic / 688
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2022 Oracle.  All Rights Reserved.
4 #
5 # FS QA Test No. 688
6 #
7 # Functional test for dropping capability bits as part of an fallocate.
8 #
9 . ./common/preamble
10 _begin_fstest auto prealloc 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
22 # real QA test starts here
23
24 # Modify as appropriate.
25 _supported_fs generic
26 _require_user
27 _require_command "$GETCAP_PROG" getcap
28 _require_command "$SETCAP_PROG" setcap
29 _require_xfs_io_command falloc
30 _require_test
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         touch $junk_file
40         chmod a+rwx $junk_file
41         $SETCAP_PROG cap_setgid,cap_setuid+ep $junk_file
42         sync
43 }
44
45 commit_and_check() {
46         local user="$1"
47
48         stat -c '%a %A %n' $junk_file | _filter_test_dir
49         _getcap -v $junk_file | _filter_test_dir
50
51         local cmd="$XFS_IO_PROG -c 'falloc 0 64k' $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         _getcap -v $junk_file | _filter_test_dir
60
61         # Blank line in output
62         echo
63 }
64
65 # Commit by an unprivileged user clears capability bits.
66 echo "Test 1 - qa_user"
67 setup_testfile
68 commit_and_check "$qa_user"
69
70 # Commit by root leaves capability bits.
71 echo "Test 2 - root"
72 setup_testfile
73 commit_and_check
74
75 # success, all done
76 status=0
77 exit