2 # FS QA Test generic/398
4 # Filesystem encryption is designed to enforce that a consistent encryption
5 # policy is used within a given encrypted directory tree and that an encrypted
6 # directory tree does not contain any unencrypted files. This test verifies
7 # that filesystem operations that would violate this constraint fail with EPERM.
8 # This does not test enforcement of this constraint on lookup, which is still
9 # needed to detect offline changes.
11 #-----------------------------------------------------------------------
12 # Copyright (c) 2016 Google, Inc. All Rights Reserved.
14 # Author: Eric Biggers <ebiggers@google.com>
16 # This program is free software; you can redistribute it and/or
17 # modify it under the terms of the GNU General Public License as
18 # published by the Free Software Foundation.
20 # This program is distributed in the hope that it would be useful,
21 # but WITHOUT ANY WARRANTY; without even the implied warranty of
22 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 # GNU General Public License for more details.
25 # You should have received a copy of the GNU General Public License
26 # along with this program; if not, write the Free Software Foundation,
27 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
28 #-----------------------------------------------------------------------
32 seqres=$RESULT_DIR/$seq
33 echo "QA output created by $seq"
37 status=1 # failure is the default!
38 trap "_cleanup; exit \$status" 0 1 2 3 15
46 # get standard environment, filters and checks
52 # remove previous $seqres.full before test
55 # real QA test starts here
58 _require_scratch_encryption
59 _require_xfs_io_command "set_encpolicy"
63 _scratch_mkfs_encrypted &>> $seqres.full
66 # Set up two encrypted directories, with different encryption policies,
67 # and one unencrypted directory.
68 edir1=$SCRATCH_MNT/edir1
69 edir2=$SCRATCH_MNT/edir2
70 udir=$SCRATCH_MNT/udir
71 mkdir $edir1 $edir2 $udir
72 keydesc1=$(_generate_encryption_key)
73 keydesc2=$(_generate_encryption_key)
74 $XFS_IO_PROG -c "set_encpolicy $keydesc1" $edir1
75 $XFS_IO_PROG -c "set_encpolicy $keydesc2" $edir2
81 # Test linking and moving an encrypted file into an encrypted directory with a
82 # different encryption policy. Should fail with EPERM.
84 echo -e "\n*** Link encrypted <= encrypted ***"
85 ln $edir1/efile1 $edir2/efile1 |& _filter_scratch
87 echo -e "\n*** Rename encrypted => encrypted ***"
88 mv $edir1/efile1 $edir2/efile1 |& _filter_scratch
91 # Test linking and moving an unencrypted file into an encrypted directory.
92 # Should fail with EPERM.
94 echo -e "\n\n*** Link unencrypted <= encrypted ***"
95 ln $udir/ufile $edir1/ufile |& _filter_scratch
97 echo -e "\n*** Rename unencrypted => encrypted ***"
98 mv $udir/ufile $edir1/ufile |& _filter_scratch
101 # Test linking and moving an encrypted file into an unencrypted directory.
104 echo -e "\n\n*** Link encrypted <= unencrypted ***"
105 ln -v $edir1/efile1 $udir/efile1 |& _filter_scratch
106 rm $udir/efile1 # undo
108 echo -e "\n*** Rename encrypted => unencrypted ***"
109 mv -v $edir1/efile1 $udir/efile1 |& _filter_scratch
110 mv $udir/efile1 $edir1/efile1 # undo
113 # Test moving a forbidden (unencrypted, or encrypted with a different encryption
114 # policy) file into an encrypted directory via an exchange (cross rename)
115 # operation. Should fail with EPERM.
117 echo -e "\n\n*** Exchange encrypted <=> encrypted ***"
118 src/renameat2 -x $edir1/efile1 $edir2/efile2 |& _filter_scratch
120 echo -e "\n*** Exchange unencrypted <=> encrypted ***"
121 src/renameat2 -x $udir/ufile $edir1/efile1 |& _filter_scratch
123 echo -e "\n*** Exchange encrypted <=> unencrypted ***"
124 src/renameat2 -x $edir1/efile1 $udir/ufile |& _filter_scratch
127 # Test a file with a special type, i.e. not regular, directory, or symlink.
128 # Since such files are not subject to encryption, there should be no
129 # restrictions on linking or moving them into encrypted directories.
131 echo -e "\n\n*** Special file tests ***"
133 mv -v $edir1/fifo $edir2/fifo | _filter_scratch
134 mv -v $edir2/fifo $udir/fifo | _filter_scratch
135 mv -v $udir/fifo $edir1/fifo | _filter_scratch
137 src/renameat2 -x $udir/fifo $edir1/fifo
138 ln -v $edir1/fifo $edir2/fifo | _filter_scratch
139 rm $edir1/fifo $edir2/fifo $udir/fifo
142 # Now test that *without* access to the encrypted key, we cannot use an exchange
143 # (cross rename) operation to move a forbidden file into an encrypted directory.
145 _unlink_encryption_key $keydesc1
146 _unlink_encryption_key $keydesc2
148 efile1=$(find $edir1 -type f)
149 efile2=$(find $edir2 -type f)
151 echo -e "\n\n*** Exchange encrypted <=> encrypted without key ***"
152 src/renameat2 -x $efile1 $efile2
153 echo -e "\n*** Exchange encrypted <=> unencrypted without key ***"
154 src/renameat2 -x $efile1 $udir/ufile