4 # Test that without the encryption key for a directory, long filenames are
5 # presented in a way which avoids collisions, even though they are abbreviated
6 # in order to support names up to NAME_MAX bytes.
9 # 6332cd32c829 ("f2fs: check entire encrypted bigname when finding a dentry")
10 # 6b06cdee81d6 ("fscrypt: avoid collisions when presenting long encrypted filenames")
12 # Even with these two fixes it's still possible to create intentional
13 # collisions. For now this test covers "accidental" collisions only.
15 #-----------------------------------------------------------------------
16 # Copyright (c) 2017 Google, Inc. All Rights Reserved.
18 # Author: Eric Biggers <ebiggers@google.com>
20 # This program is free software; you can redistribute it and/or
21 # modify it under the terms of the GNU General Public License as
22 # published by the Free Software Foundation.
24 # This program is distributed in the hope that it would be useful,
25 # but WITHOUT ANY WARRANTY; without even the implied warranty of
26 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 # GNU General Public License for more details.
29 # You should have received a copy of the GNU General Public License
30 # along with this program; if not, write the Free Software Foundation,
31 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
32 #-----------------------------------------------------------------------
36 seqres=$RESULT_DIR/$seq
37 echo "QA output created by $seq"
41 status=1 # failure is the default!
42 trap "_cleanup; exit \$status" 0 1 2 3 15
50 # get standard environment, filters and checks
55 # remove previous $seqres.full before test
58 # real QA test starts here
61 _require_scratch_encryption
62 _require_xfs_io_command "set_encpolicy"
63 _require_command "$KEYCTL_PROG" keyctl
65 # set up an encrypted directory
68 _scratch_mkfs_encrypted &>> $seqres.full
70 mkdir $SCRATCH_MNT/edir
71 keydesc=$(_generate_encryption_key)
72 # -f 0x2: zero-pad to 16-byte boundary (i.e. encryption block boundary)
73 $XFS_IO_PROG -c "set_encpolicy -f 0x2 $keydesc" $SCRATCH_MNT/edir
75 # Create files with long names (> 32 bytes, long enough to trigger the use of
76 # "digested" names) in the encrypted directory.
78 # Use 100,000 files so that we have a good chance of detecting buggy filesystems
79 # that solely use a 32-bit hash to distinguish files, which f2fs was doing.
81 # Furthermore, make the filenames differ only in the last 16-byte encryption
82 # block. This reproduces the bug where it was not accounted for that ciphertext
83 # stealing (CTS) causes the last two blocks to appear "flipped".
84 seq -f "$SCRATCH_MNT/edir/abcdefghijklmnopqrstuvwxyz012345%.0f" 100000 | xargs touch
85 find $SCRATCH_MNT/edir/ -type f | xargs stat -c %i | sort | uniq | wc -l
87 _unlink_encryption_key $keydesc
90 # Verify that every file has a unique inode number and can be removed without
91 # error. With the bug(s), some filenames incorrectly pointed to the same inode,
92 # and ext4 reported a "Structure needs cleaning" error when removing files.
93 find $SCRATCH_MNT/edir/ -type f | xargs stat -c %i | sort | uniq | wc -l
94 rm -rf $SCRATCH_MNT/edir |& head -n 10
95 stat $SCRATCH_MNT/edir |& _filter_scratch