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 _begin_fstest auto quick encrypt
16 # Import common functions.
21 # real QA test starts here
23 _require_scratch_encryption
24 _require_command "$KEYCTL_PROG" keyctl
25 _require_renameat2 exchange
29 _scratch_mkfs_encrypted &>> $seqres.full
32 mkdir $SCRATCH_MNT/edir
33 keydesc=$(_generate_session_encryption_key)
34 _set_encpolicy $SCRATCH_MNT/edir $keydesc
35 echo a > $SCRATCH_MNT/edir/a
36 echo b > $SCRATCH_MNT/edir/b
37 _unlink_session_encryption_key $keydesc
40 # Note that because no-key filenames are unpredictable, this needs to be written
41 # in a way that does not assume any particular filenames.
42 efile1=$(find $SCRATCH_MNT/edir -maxdepth 1 -type f | head -1)
43 efile2=$(find $SCRATCH_MNT/edir -maxdepth 1 -type f | tail -1)
44 mv $efile1 $efile2 |& _filter_scratch | _filter_nokey_filenames edir
45 $here/src/renameat2 -x $efile1 $efile2