tests: remove udf/101
[xfstests-dev.git] / tests / generic / 435
1 #! /bin/bash
2 # FS QA Test No. 435
3 #
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.
7 #
8 # Regression test for:
9 #       6332cd32c829 ("f2fs: check entire encrypted bigname when finding a dentry")
10 #       6b06cdee81d6 ("fscrypt: avoid collisions when presenting long encrypted filenames")
11 #
12 # Even with these two fixes it's still possible to create intentional
13 # collisions.  For now this test covers "accidental" collisions only.
14 #
15 #-----------------------------------------------------------------------
16 # Copyright (c) 2017 Google, Inc.  All Rights Reserved.
17 #
18 # Author: Eric Biggers <ebiggers@google.com>
19 #
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.
23 #
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.
28 #
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 #-----------------------------------------------------------------------
33 #
34
35 seq=`basename $0`
36 seqres=$RESULT_DIR/$seq
37 echo "QA output created by $seq"
38
39 here=`pwd`
40 tmp=/tmp/$$
41 status=1        # failure is the default!
42 trap "_cleanup; exit \$status" 0 1 2 3 15
43
44 _cleanup()
45 {
46         cd /
47         rm -f $tmp.*
48 }
49
50 # get standard environment, filters and checks
51 . ./common/rc
52 . ./common/filter
53 . ./common/encrypt
54
55 # remove previous $seqres.full before test
56 rm -f $seqres.full
57
58 # real QA test starts here
59 _supported_fs generic
60 _supported_os Linux
61 _require_scratch_encryption
62 _require_xfs_io_command "set_encpolicy"
63 _require_command "$KEYCTL_PROG" keyctl
64
65 # set up an encrypted directory
66
67 _new_session_keyring
68 _scratch_mkfs_encrypted &>> $seqres.full
69 _scratch_mount
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
74
75 # Create files with long names (> 32 bytes, long enough to trigger the use of
76 # "digested" names) in the encrypted directory.
77 #
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.
80 #
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
86
87 _unlink_encryption_key $keydesc
88 _scratch_cycle_mount
89
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
96
97 # success, all done
98 status=0
99 exit