2 # FS QA Test generic/419
4 # Try to rename files in an encrypted directory, without access to the
5 # encryption key. This should fail with ENOKEY. Test both a regular rename and
6 # a cross rename. This is a regression test for:
7 # 173b8439e1ba ("ext4: don't allow encrypted operations without keys")
8 # 363fa4e078cb ("f2fs: don't allow encrypted operations without keys")
10 #-----------------------------------------------------------------------
11 # Copyright (c) 2017 Google, Inc. All Rights Reserved.
13 # Author: Eric Biggers <ebiggers@google.com>
15 # This program is free software; you can redistribute it and/or
16 # modify it under the terms of the GNU General Public License as
17 # published by the Free Software Foundation.
19 # This program is distributed in the hope that it would be useful,
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 # GNU General Public License for more details.
24 # You should have received a copy of the GNU General Public License
25 # along with this program; if not, write the Free Software Foundation,
26 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
27 #-----------------------------------------------------------------------
31 seqres=$RESULT_DIR/$seq
32 echo "QA output created by $seq"
36 status=1 # failure is the default!
37 trap "_cleanup; exit \$status" 0 1 2 3 15
45 # get standard environment, filters and checks
51 # remove previous $seqres.full before test
54 # real QA test starts here
57 _require_scratch_encryption
58 _require_xfs_io_command "set_encpolicy"
59 _require_command "$KEYCTL_PROG" keyctl
64 _scratch_mkfs_encrypted &>> $seqres.full
67 mkdir $SCRATCH_MNT/edir
68 keydesc=$(_generate_encryption_key)
69 $XFS_IO_PROG -c "set_encpolicy $keydesc" $SCRATCH_MNT/edir
70 echo a > $SCRATCH_MNT/edir/a
71 echo b > $SCRATCH_MNT/edir/b
72 _unlink_encryption_key $keydesc
75 # Note that because encrypted filenames are unpredictable, this needs to be
76 # written in a way that does not assume any particular filenames.
77 efile1=$(find $SCRATCH_MNT/edir -maxdepth 1 -type f | head -1)
78 efile2=$(find $SCRATCH_MNT/edir -maxdepth 1 -type f | tail -1)
79 mv $efile1 $efile2 |& _filter_scratch | sed 's|edir/[a-zA-Z0-9+,_]\+|edir/FILENAME|g'
80 src/renameat2 -x $efile1 $efile2