generic: test MADV_POPULATE_READ with IO errors
[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 . ./common/preamble
21 _begin_fstest auto quick fuzzers
22
23 # Import common functions.
24 . ./common/filter
25 . ./common/populate
26
27 # real QA test starts here
28 _supported_fs xfs
29 _require_scratch_nocheck
30 _require_xfs_io_command "scrub"
31 # Corrupt XFS on purpose, and skip if assert failures would crash system.
32 _require_no_xfs_bug_on_assert
33
34 rm -f "$seqres.full"
35
36 # Format and mount
37 _scratch_mkfs | _filter_mkfs > $seqres.full 2> $tmp.mkfs
38 test "${PIPESTATUS[0]}" -eq 0 || _fail "mkfs failed"
39 _scratch_mount
40
41 # Get directory block size
42 . $tmp.mkfs
43
44 # Create a block+(e.g. leaf) format directory
45 __populate_create_dir "${SCRATCH_MNT}/dir_leaf" "$((dirbsize / 12))"
46
47 # Get the block+ directory inode and a subdirectory inode of it
48 subdino=$(stat -c "%i" "$(find ${SCRATCH_MNT}/dir_leaf/* -type d | head -1)")
49 dino=$(stat -c "%i" "${SCRATCH_MNT}/dir_leaf")
50
51 # Get the subdirectory's generation number
52 _scratch_unmount
53 subdgen=$(_scratch_xfs_get_metadata_field "core.gen" "inode $subdino")
54
55 # Corrupt the directory inode's core.mode
56 setmode="0100755"
57 _scratch_xfs_set_metadata_field "core.mode" "$setmode" "inode $dino" >> $seqres.full
58 getmode=$(_scratch_xfs_get_metadata_field "core.mode" "inode $dino")
59 [ "$getmode" != "$setmode" ] && _fail "failed to set core.mode"
60
61 # Scrub parent directory in subdirectory (online)
62 _scratch_mount
63 $XFS_IO_PROG -x -c "scrub parent $subdino $subdgen" ${SCRATCH_MNT} >> $seqres.full
64
65 echo "Silence is golden"
66
67 # success, all done
68 status=0
69 exit