summaryrefslogtreecommitdiff
path: root/tests/generic/419
blob: 5d56d64fc50f286d40dd9b1c934935d3d06f60dd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#! /bin/bash
# SPDX-License-Identifier: GPL-2.0
# Copyright (c) 2017 Google, Inc.  All Rights Reserved.
#
# FS QA Test generic/419
#
# Try to rename files in an encrypted directory, without access to the
# encryption key.  This should fail with ENOKEY.  Test both a regular rename and
# a cross rename.  This is a regression test for:
#	173b8439e1ba ("ext4: don't allow encrypted operations without keys")
#	363fa4e078cb ("f2fs: don't allow encrypted operations without keys")
#
. ./common/preamble
_begin_fstest auto quick encrypt

# Import common functions.
. ./common/filter
. ./common/encrypt
. ./common/renameat2

# real QA test starts here
_supported_fs generic
_require_scratch_encryption
_require_command "$KEYCTL_PROG" keyctl
_require_renameat2 exchange

_init_session_keyring

_scratch_mkfs_encrypted &>> $seqres.full
_scratch_mount

mkdir $SCRATCH_MNT/edir
keydesc=$(_generate_session_encryption_key)
_set_encpolicy $SCRATCH_MNT/edir $keydesc
echo a > $SCRATCH_MNT/edir/a
echo b > $SCRATCH_MNT/edir/b
_unlink_session_encryption_key $keydesc
_scratch_cycle_mount

# Note that because no-key filenames are unpredictable, this needs to be written
# in a way that does not assume any particular filenames.
efile1=$(find $SCRATCH_MNT/edir -maxdepth 1 -type f | head -1)
efile2=$(find $SCRATCH_MNT/edir -maxdepth 1 -type f | tail -1)
mv $efile1 $efile2 |& _filter_scratch | _filter_nokey_filenames edir
$here/src/renameat2 -x $efile1 $efile2

# success, all done
status=0
exit