xfs: Check for extent overflow when trivally adding a new extent
[xfstests-dev.git] / tests / xfs / 448
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2018 FUJITSU LIMITED. All Rights Reserved.
4 #
5 # FS QA Test No. 448
6 #
7 # Regression test for commit:
8 # 46c59736d809 ("xfs: harden directory integrity checks some more")
9 #
10 # If a malicious XFS contains a block+ format directory wherein
11 # the directory inode's core.mode is corrupted, and there are
12 # subdirectories of the corrupted directory, an attempt to traverse
13 # up the directory tree by running xfs_scrub will crash the
14 # kernel in __xfs_dir3_data_check.
15 #
16 # Notice:
17 # we should have non fatal asserts configured, because assert
18 # failures triggered by the intentional corrupt would crash system.
19 #
20 seq=`basename "$0"`
21 seqres="$RESULT_DIR/$seq"
22 echo "QA output created by $seq"
23
24 here=`pwd`
25 tmp=/tmp/$$
26 status=1    # failure is the default!
27 trap "_cleanup; exit \$status" 0 1 2 3 15
28
29 _cleanup()
30 {
31         cd /
32         rm -rf $tmp.*
33 }
34
35 # get standard environment, filters and checks
36 . ./common/rc
37 . ./common/filter
38 . ./common/populate
39
40 # real QA test starts here
41 _supported_fs xfs
42 _require_scratch_nocheck
43 _require_xfs_io_command "scrub"
44 # Corrupt XFS on purpose, and skip if assert failures would crash system.
45 _require_no_xfs_bug_on_assert
46
47 rm -f "$seqres.full"
48
49 # Format and mount
50 _scratch_mkfs | _filter_mkfs > $seqres.full 2> $tmp.mkfs || _fail "mkfs failed"
51 _scratch_mount
52
53 # Get directory block size
54 . $tmp.mkfs
55
56 # Create a block+(e.g. leaf) format directory
57 __populate_create_dir "${SCRATCH_MNT}/dir_leaf" "$((dirbsize / 12))"
58
59 # Get the block+ directory inode and a subdirectory inode of it
60 subdino=$(stat -c "%i" "$(find ${SCRATCH_MNT}/dir_leaf/* -type d | head -1)")
61 dino=$(stat -c "%i" "${SCRATCH_MNT}/dir_leaf")
62
63 # Get the subdirectory's generation number
64 _scratch_unmount
65 subdgen=$(_scratch_xfs_get_metadata_field "core.gen" "inode $subdino")
66
67 # Corrupt the directory inode's core.mode
68 setmode="0100755"
69 _scratch_xfs_set_metadata_field "core.mode" "$setmode" "inode $dino" >> $seqres.full
70 getmode=$(_scratch_xfs_get_metadata_field "core.mode" "inode $dino")
71 [ "$getmode" != "$setmode" ] && _fail "failed to set core.mode"
72
73 # Scrub parent directory in subdirectory (online)
74 _scratch_mount
75 $XFS_IO_PROG -x -c "scrub parent $subdino $subdgen" ${SCRATCH_MNT} >> $seqres.full
76
77 echo "Silence is golden"
78
79 # success, all done
80 status=0
81 exit