generic: handle fs.verity.require_signatures being enabled
[xfstests-dev.git] / tests / generic / 573
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright 2018 Google LLC
4 #
5 # FS QA Test generic/573
6 #
7 # Test access controls on the fs-verity ioctls.  FS_IOC_MEASURE_VERITY is
8 # allowed on any file, whereas FS_IOC_ENABLE_VERITY requires write access.
9 #
10 seq=`basename $0`
11 seqres=$RESULT_DIR/$seq
12 echo "QA output created by $seq"
13
14 here=`pwd`
15 tmp=/tmp/$$
16 status=1        # failure is the default!
17 trap "_cleanup; exit \$status" 0 1 2 3 15
18
19 _cleanup()
20 {
21         cd /
22         _restore_fsverity_signatures
23         rm -f $tmp.*
24 }
25
26 # get standard environment, filters and checks
27 . ./common/rc
28 . ./common/filter
29 . ./common/verity
30
31 # remove previous $seqres.full before test
32 rm -f $seqres.full
33
34 # real QA test starts here
35 _supported_fs generic
36 _supported_os Linux
37 _require_scratch_verity
38 _require_user
39 _require_chattr ia
40 _disable_fsverity_signatures
41
42 _scratch_mkfs_verity &>> $seqres.full
43 _scratch_mount
44 fsv_file=$SCRATCH_MNT/file.fsv
45
46 _fsv_scratch_begin_subtest "FS_IOC_ENABLE_VERITY doesn't require root"
47 echo foo > $fsv_file
48 chmod 666 $fsv_file
49 _user_do "$FSVERITY_PROG enable $fsv_file"
50
51 _fsv_scratch_begin_subtest "FS_IOC_ENABLE_VERITY requires write access"
52 echo foo > $fsv_file >> $seqres.full
53 chmod 444 $fsv_file
54 _user_do "$FSVERITY_PROG enable $fsv_file" |& _filter_scratch
55
56 _fsv_scratch_begin_subtest "FS_IOC_ENABLE_VERITY requires !append-only"
57 echo foo > $fsv_file >> $seqres.full
58 $CHATTR_PROG +a $fsv_file
59 $FSVERITY_PROG enable $fsv_file |& _filter_scratch
60 $CHATTR_PROG -a $fsv_file
61
62 _fsv_scratch_begin_subtest "FS_IOC_ENABLE_VERITY requires !immutable"
63 echo foo > $fsv_file >> $seqres.full
64 $CHATTR_PROG +i $fsv_file
65 $FSVERITY_PROG enable $fsv_file |& _filter_scratch
66 $CHATTR_PROG -i $fsv_file
67
68 _fsv_scratch_begin_subtest "FS_IOC_MEASURE_VERITY doesn't require root"
69 _fsv_create_enable_file $fsv_file >> $seqres.full
70 chmod 444 $fsv_file
71 su $qa_user -c "$FSVERITY_PROG measure $fsv_file" >> $seqres.full
72
73 # success, all done
74 status=0
75 exit