generic: test MADV_POPULATE_READ with IO errors
[xfstests-dev.git] / tests / generic / 576
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright 2018 Google LLC
4 #
5 # FS QA Test generic/576
6 #
7 # Test using fs-verity and fscrypt simultaneously.  This primarily verifies
8 # correct ordering of the hooks for each feature: fscrypt needs to be first.
9 #
10 . ./common/preamble
11 _begin_fstest auto quick verity encrypt
12
13 # Override the default cleanup function.
14 _cleanup()
15 {
16         cd /
17         _restore_fsverity_signatures
18         rm -f $tmp.*
19 }
20
21 # Import common functions.
22 . ./common/filter
23 . ./common/verity
24 . ./common/encrypt
25
26 # real QA test starts here
27 _supported_fs generic
28 _require_scratch_verity
29 _require_scratch_encryption
30 _require_command "$KEYCTL_PROG" keyctl
31 _disable_fsverity_signatures
32
33 _scratch_mkfs_encrypted_verity &>> $seqres.full
34 _scratch_mount
35
36 fsv_orig_file=$tmp.file
37 edir=$SCRATCH_MNT/edir
38 fsv_file=$edir/file.fsv
39
40 # Set up an encrypted directory.
41 _init_session_keyring
42 keydesc=$(_generate_session_encryption_key)
43 mkdir $edir
44 _set_encpolicy $edir $keydesc
45
46 # Create a file within the encrypted directory and enable verity on it.
47 # Then check that it has an encryption policy as well.
48 head -c 100000 /dev/zero > $fsv_orig_file
49 cp $fsv_orig_file $fsv_file
50 _fsv_enable $fsv_file
51 echo
52 $XFS_IO_PROG -r -c "get_encpolicy" $fsv_file | _filter_scratch \
53         | sed 's/Master key descriptor:.*/Master key descriptor: 0000000000000000/'
54 echo
55
56 # Verify that the file contents are as expected.  This should be going through
57 # both the decryption and verity I/O paths.
58 cmp $fsv_orig_file $fsv_file && echo "Files matched"
59
60 # Just in case, try again after a mount cycle to empty the page cache.
61 _scratch_cycle_mount
62 cmp $fsv_orig_file $fsv_file && echo "Files matched"
63
64 # Corrupt some bytes as a sanity check that fs-verity is really working.
65 # This also verifies that the data on-disk is really encrypted, since otherwise
66 # the data being written here would be identical to the old data.
67 head -c 1000 /dev/zero | _fsv_scratch_corrupt_bytes $fsv_file 50000
68 md5sum $fsv_file |& _filter_scratch
69
70 # success, all done
71 status=0
72 exit