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
39 _require_scratch_encryption
40 _require_command "$KEYCTL_PROG" keyctl
41 _require_renameat2 exchange
45 _scratch_mkfs_encrypted &>> $seqres.full
48 mkdir $SCRATCH_MNT/edir
49 keydesc=$(_generate_session_encryption_key)
50 _set_encpolicy $SCRATCH_MNT/edir $keydesc
51 echo a > $SCRATCH_MNT/edir/a
52 echo b > $SCRATCH_MNT/edir/b
53 _unlink_session_encryption_key $keydesc
56 # Note that because encrypted filenames are unpredictable, this needs to be
57 # written in a way that does not assume any particular filenames.
58 efile1=$(find $SCRATCH_MNT/edir -maxdepth 1 -type f | head -1)
59 efile2=$(find $SCRATCH_MNT/edir -maxdepth 1 -type f | tail -1)
60 mv $efile1 $efile2 |& _filter_scratch | sed 's|edir/[a-zA-Z0-9+,_]\+|edir/FILENAME|g'
61 $here/src/renameat2 -x $efile1 $efile2