common/rc: add _scratch_{u}mount_idmapped() helpers
[xfstests-dev.git] / tests / generic / 435
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2017 Google, Inc.  All Rights Reserved.
4 #
5 # FS QA Test No. 435
6 #
7 # Test that without the encryption key for a directory, long filenames are
8 # presented in a way which avoids collisions, even though they are abbreviated
9 # in order to support names up to NAME_MAX bytes.
10 #
11 # Regression test for:
12 #       6332cd32c829 ("f2fs: check entire encrypted bigname when finding a dentry")
13 #       6b06cdee81d6 ("fscrypt: avoid collisions when presenting long encrypted filenames")
14 #
15 # Even with these two fixes it's still possible to create intentional
16 # collisions.  For now this test covers "accidental" collisions only.
17 #
18 seq=`basename $0`
19 seqres=$RESULT_DIR/$seq
20 echo "QA output created by $seq"
21
22 here=`pwd`
23 tmp=/tmp/$$
24 status=1        # failure is the default!
25 trap "_cleanup; exit \$status" 0 1 2 3 15
26
27 _cleanup()
28 {
29         cd /
30         rm -f $tmp.*
31 }
32
33 # get standard environment, filters and checks
34 . ./common/rc
35 . ./common/filter
36 . ./common/encrypt
37
38 # remove previous $seqres.full before test
39 rm -f $seqres.full
40
41 # real QA test starts here
42 _supported_fs generic
43 _require_scratch_encryption
44 _require_command "$KEYCTL_PROG" keyctl
45
46 # set up an encrypted directory
47
48 _new_session_keyring
49 _scratch_mkfs_encrypted &>> $seqres.full
50 _scratch_mount
51 mkdir $SCRATCH_MNT/edir
52 keydesc=$(_generate_session_encryption_key)
53 # -f 0x2: zero-pad to 16-byte boundary (i.e. encryption block boundary)
54 _set_encpolicy $SCRATCH_MNT/edir $keydesc -f 0x2
55
56 # Create files with long names (> 32 bytes, long enough to trigger the use of
57 # "digested" names) in the encrypted directory.
58 #
59 # Use 100,000 files so that we have a good chance of detecting buggy filesystems
60 # that solely use a 32-bit hash to distinguish files, which f2fs was doing.
61 #
62 # Furthermore, make the filenames differ only in the last 16-byte encryption
63 # block.  This reproduces the bug where it was not accounted for that ciphertext
64 # stealing (CTS) causes the last two blocks to appear "flipped".
65 seq -f "$SCRATCH_MNT/edir/abcdefghijklmnopqrstuvwxyz012345%.0f" 100000 | xargs touch
66 find $SCRATCH_MNT/edir/ -type f | xargs stat -c %i | sort | uniq | wc -l
67
68 _unlink_session_encryption_key $keydesc
69 _scratch_cycle_mount
70
71 # Verify that every file has a unique inode number and can be removed without
72 # error.  With the bug(s), some filenames incorrectly pointed to the same inode,
73 # and ext4 reported a "Structure needs cleaning" error when removing files.
74 find $SCRATCH_MNT/edir/ -type f | xargs stat -c %i | sort | uniq | wc -l
75 rm -rf $SCRATCH_MNT/edir |& head -n 10
76 stat $SCRATCH_MNT/edir |& _filter_stat |& _filter_scratch
77
78 # success, all done
79 status=0
80 exit