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 seqres="$RESULT_DIR/$seq"
22 echo "QA output created by $seq"
26 status=1 # failure is the default!
27 trap "_cleanup; exit \$status" 0 1 2 3 15
35 # get standard environment, filters and checks
40 # real QA test starts here
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
50 _scratch_mkfs | _filter_mkfs > $seqres.full 2> $tmp.mkfs || _fail "mkfs failed"
53 # Get directory block size
56 # Create a block+(e.g. leaf) format directory
57 __populate_create_dir "${SCRATCH_MNT}/dir_leaf" "$((dirbsize / 12))"
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")
63 # Get the subdirectory's generation number
65 subdgen=$(_scratch_xfs_get_metadata_field "core.gen" "inode $subdino")
67 # Corrupt the directory inode's core.mode
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"
73 # Scrub parent directory in subdirectory (online)
75 $XFS_IO_PROG -x -c "scrub parent $subdino $subdgen" ${SCRATCH_MNT} >> $seqres.full
77 echo "Silence is golden"