2 # SPDX-License-Identifier: GPL-2.0-only
3 # Copyright 2021 Google LLC
7 # Test retrieving the Merkle tree and fs-verity descriptor of a verity file
8 # using FS_IOC_READ_VERITY_METADATA.
11 seqres=$RESULT_DIR/$seq
12 echo "QA output created by $seq"
16 status=1 # failure is the default!
17 trap "_cleanup; exit \$status" 0 1 2 3 15
32 _require_scratch_verity
33 _disable_fsverity_signatures
34 # For the output of this test to always be the same, it has to use a specific
35 # Merkle tree block size.
36 if [ $FSV_BLOCK_SIZE != 4096 ]; then
37 _notrun "4096-byte verity block size not supported on this platform"
40 _scratch_mkfs_verity &>> $seqres.full
43 echo -e "\n# Creating a verity file"
44 fsv_file=$SCRATCH_MNT/file
45 # Always use the same file contents, so that the output of the test is always
46 # the same. Also use a file that is large enough to have multiple Merkle tree
47 # levels, so that the test verifies that the blocks are returned in the expected
48 # order. A 1 MB file with SHA-256 and a Merkle tree block size of 4096 will
49 # have 3 Merkle tree blocks (3*4096 bytes): two at level 0 and one at level 1.
50 head -c 1000000 /dev/zero > $fsv_file
51 merkle_tree_size=$((3 * FSV_BLOCK_SIZE))
52 fsverity_descriptor_size=256
53 _fsv_enable $fsv_file --salt=abcd
54 _require_fsverity_dump_metadata $fsv_file
55 _fsv_measure $fsv_file
57 echo -e "\n# Dumping Merkle tree"
58 _fsv_dump_merkle_tree $fsv_file | sha256sum
60 echo -e "\n# Dumping Merkle tree (in chunks)"
61 # The above test may get the whole tree in one read, so also try reading it in
63 for (( i = 0; i < merkle_tree_size; i += 997 )); do
64 _fsv_dump_merkle_tree $fsv_file --offset=$i --length=997
67 echo -e "\n# Dumping descriptor"
68 # Note that the hash that is printed here should be the same hash that was
69 # printed by _fsv_measure above.
70 _fsv_dump_descriptor $fsv_file | sha256sum
72 echo -e "\n# Dumping descriptor (in chunks)"
73 for (( i = 0; i < fsverity_descriptor_size; i += 13 )); do
74 _fsv_dump_descriptor $fsv_file --offset=$i --length=13