2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2018 FUJITSU LIMITED. All Rights Reserved.
7 # Regression test for commit:
8 # 46c59736d809 ("xfs: harden directory integrity checks some more")
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.
17 # we should have non fatal asserts configured, because assert
18 # failures triggered by the intentional corrupt would crash system.
21 _begin_fstest auto quick fuzzers
23 # Import common functions.
27 # real QA test starts here
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
37 _scratch_mkfs | _filter_mkfs > $seqres.full 2> $tmp.mkfs
38 test "${PIPESTATUS[0]}" -eq 0 || _fail "mkfs failed"
41 # Get directory block size
44 # Create a block+(e.g. leaf) format directory
45 __populate_create_dir "${SCRATCH_MNT}/dir_leaf" "$((dirbsize / 12))"
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")
51 # Get the subdirectory's generation number
53 subdgen=$(_scratch_xfs_get_metadata_field "core.gen" "inode $subdino")
55 # Corrupt the directory inode's core.mode
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"
61 # Scrub parent directory in subdirectory (online)
63 $XFS_IO_PROG -x -c "scrub parent $subdino $subdgen" ${SCRATCH_MNT} >> $seqres.full
65 echo "Silence is golden"