xfs/{263,106}: erase max warnings printout
[xfstests-dev.git] / tests / generic / 575
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright 2018 Google LLC
4 #
5 # FS QA Test generic/575
6 #
7 # Test that fs-verity is using the correct measurement values.  This test
8 # verifies that fs-verity is doing its Merkle tree-based hashing correctly,
9 # i.e. that it hasn't been broken by a change.
10 #
11 seq=`basename $0`
12 seqres=$RESULT_DIR/$seq
13 echo "QA output created by $seq"
14
15 here=`pwd`
16 tmp=/tmp/$$
17 status=1        # failure is the default!
18 trap "_cleanup; exit \$status" 0 1 2 3 15
19
20 _cleanup()
21 {
22         cd /
23         _restore_fsverity_signatures
24         rm -f $tmp.*
25 }
26
27 # get standard environment, filters and checks
28 . ./common/rc
29 . ./common/filter
30 . ./common/verity
31
32 # remove previous $seqres.full before test
33 rm -f $seqres.full
34
35 # real QA test starts here
36 _supported_fs generic
37 _supported_os Linux
38 _require_scratch_verity
39 if [ $FSV_BLOCK_SIZE != 4096 ]; then
40         _notrun "4096-byte verity block size not supported on this platform"
41 fi
42 _disable_fsverity_signatures
43
44 _scratch_mkfs_verity &>> $seqres.full
45 _scratch_mount
46 fsv_orig_file=$SCRATCH_MNT/file
47 fsv_file=$SCRATCH_MNT/file.fsv
48
49 algs=(sha256 sha512)
50
51 # Try files with 0, 1, and multiple Merkle tree levels.
52 file_sizes=(0 4096 65536 65536 100000000)
53
54 # Try both unsalted and salted, and check that empty salt is the same as no salt
55 salts=('' '' '' '--salt=' '--salt=f3c93fa6fb828c0e1587e5714ecf6f56')
56
57 # The expected file measurements are here rather than in the expected output
58 # file because not all hash algorithms may be available.
59 sha256_vals=(
60 sha256:3d248ca542a24fc62d1c43b916eae5016878e2533c88238480b26128a1f1af95
61 sha256:babc284ee4ffe7f449377fbf6692715b43aec7bc39c094a95878904d34bac97e
62 sha256:011e3f2b1dc89b75d78cddcc2a1b85cd8a64b2883e5f20f277ae4c0617e0404f
63 sha256:011e3f2b1dc89b75d78cddcc2a1b85cd8a64b2883e5f20f277ae4c0617e0404f
64 sha256:9d33cab743468fcbe4edab91a275b30dd543c12dd5e6ce6f2f737f66a1558f06
65 )
66 sha512_vals=(
67 sha512:ccf9e5aea1c2a64efa2f2354a6024b90dffde6bbc017825045dce374474e13d10adb9dadcc6ca8e17a3c075fbd31336e8f266ae6fa93a6c3bed66f9e784e5abf
68 sha512:928922686c4caf32175f5236a7f964e9925d10a74dc6d8344a8bd08b23c228ff5792573987d7895f628f39c4f4ebe39a7367d7aeb16aaa0cd324ac1d53664e61
69 sha512:eab7224ce374a0a4babcb2db25e24836247f38b87806ad9be9e5ba4daac2f5b814fc0cbdfd9f1f8499b3c9a6c1b38fe08974cce49883ab4ccd04462fd2f9507f
70 sha512:eab7224ce374a0a4babcb2db25e24836247f38b87806ad9be9e5ba4daac2f5b814fc0cbdfd9f1f8499b3c9a6c1b38fe08974cce49883ab4ccd04462fd2f9507f
71 sha512:f7083a38644880d25539488313e9e5b41a4d431a0e383945129ad2c36e3c1d0f28928a424641bb1363c12b6e770578102566acea73baf1ce8ee15336f5ba2446
72 )
73
74 test_alg()
75 {
76         local alg=$1
77         local -n vals=${alg}_vals
78         local i
79         local file_size
80         local expected actual salt_arg
81
82         _fsv_scratch_begin_subtest "Check for expected measurement values ($alg)"
83
84         if ! _fsv_have_hash_algorithm $alg $fsv_file; then
85                 if [ "$alg" = sha256 ]; then
86                         _fail "Something is wrong - sha256 hash should always be available"
87                 fi
88                 return 0
89         fi
90
91         for i in ${!file_sizes[@]}; do
92                 file_size=${file_sizes[$i]}
93                 expected=${vals[$i]}
94                 salt_arg=${salts[$i]}
95
96                 head -c $file_size /dev/zero > $fsv_orig_file
97                 cp $fsv_orig_file $fsv_file
98                 _fsv_enable --hash-alg=$alg $salt_arg $fsv_file
99                 actual=$(_fsv_measure $fsv_file)
100                 if [ "$actual" != "$expected" ]; then
101                         echo "Mismatch: expected $expected, kernel calculated $actual (file_size=$file_size)"
102                 fi
103                 cmp $fsv_orig_file $fsv_file
104                 rm -f $fsv_file
105         done
106 }
107
108 for alg in ${algs[@]}; do
109         test_alg $alg
110 done
111
112 # success, all done
113 status=0
114 exit