2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2017 Google, Inc. All Rights Reserved.
5 # FS QA Test generic/419
7 # Try to rename files in an encrypted directory, without access to the
8 # encryption key. This should fail with ENOKEY. Test both a regular rename and
9 # a cross rename. This is a regression test for:
10 # 173b8439e1ba ("ext4: don't allow encrypted operations without keys")
11 # 363fa4e078cb ("f2fs: don't allow encrypted operations without keys")
14 seqres=$RESULT_DIR/$seq
15 echo "QA output created by $seq"
19 status=1 # failure is the default!
20 trap "_cleanup; exit \$status" 0 1 2 3 15
28 # get standard environment, filters and checks
34 # remove previous $seqres.full before test
37 # real QA test starts here
40 _require_scratch_encryption
41 _require_xfs_io_command "set_encpolicy"
42 _require_command "$KEYCTL_PROG" keyctl
47 _scratch_mkfs_encrypted &>> $seqres.full
50 mkdir $SCRATCH_MNT/edir
51 keydesc=$(_generate_encryption_key)
52 $XFS_IO_PROG -c "set_encpolicy $keydesc" $SCRATCH_MNT/edir
53 echo a > $SCRATCH_MNT/edir/a
54 echo b > $SCRATCH_MNT/edir/b
55 _unlink_encryption_key $keydesc
58 # Note that because encrypted filenames are unpredictable, this needs to be
59 # written in a way that does not assume any particular filenames.
60 efile1=$(find $SCRATCH_MNT/edir -maxdepth 1 -type f | head -1)
61 efile2=$(find $SCRATCH_MNT/edir -maxdepth 1 -type f | tail -1)
62 mv $efile1 $efile2 |& _filter_scratch | sed 's|edir/[a-zA-Z0-9+,_]\+|edir/FILENAME|g'
63 src/renameat2 -x $efile1 $efile2