generic: update encryption tests to use term "no-key names"
[xfstests-dev.git] / tests / generic / 421
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2017 Google, Inc.  All Rights Reserved.
4 #
5 # FS QA Test generic/421
6 #
7 # Test revoking an encryption key during concurrent I/O.  Regression test for
8 # 1b53cf9815bb ("fscrypt: remove broken support for detecting keyring key
9 # revocation").
10 #
11 . ./common/preamble
12 _begin_fstest auto quick encrypt dangerous
13
14 # Import common functions.
15 . ./common/filter
16 . ./common/encrypt
17
18 # real QA test starts here
19 _supported_fs generic
20 _require_scratch_encryption
21 _require_command "$KEYCTL_PROG" keyctl
22
23 _new_session_keyring
24 _scratch_mkfs_encrypted &>> $seqres.full
25 _scratch_mount
26
27 dir=$SCRATCH_MNT/encrypted_dir
28 file=$dir/file
29
30 # 4 processes, 2 MB per process
31 nproc=4
32 slice=2
33
34 # Create an encrypted file and sync its data to disk.
35 rm -rf $dir
36 mkdir $dir
37 keydesc=$(_generate_session_encryption_key)
38 _set_encpolicy $dir $keydesc
39 $XFS_IO_PROG -f $file -c "pwrite 0 $((nproc*slice))M" -c "fsync" > /dev/null
40
41 # Create processes to read from the encrypted file.  Use fadvise to wipe the
42 # pagecache before each read, ensuring that each read actually does decryption.
43 for ((proc = 0; proc < nproc; proc++)); do
44         (
45                 range="$((proc * slice))M ${slice}M"
46                 while [ ! -e $tmp.done ]; do
47                         $XFS_IO_PROG $file -c "fadvise -d $range" \
48                                            -c "pread $range" &> /dev/null
49                 done
50         ) &
51 done
52
53 # Wait a second for the readers to start up.
54 sleep 1
55
56 # Revoke the encryption key.
57 keyid=$(_revoke_session_encryption_key $keydesc)
58
59 # Now try to open the file again.  In buggy kernels this caused concurrent
60 # readers to crash with a NULL pointer dereference during decryption.
61 #
62 # Note that the fix also made filenames stop "immediately" reverting to no-key
63 # names on key revocation.  Therefore, the name of the file we're opening here
64 # may be in either plaintext or no-key form depending on the kernel version, and
65 # no-key names are unpredictable anyway, so just use 'find' to find it.
66 cat "$(find $dir -type f)" > /dev/null
67
68 # Wait for readers to exit
69 touch $tmp.done
70 wait
71
72 # success, all done
73 echo "Didn't crash!"
74 status=0
75 exit