blob: fde3bf476efbc8a81162666c0256030f6b899535 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
|
#! /bin/bash
# SPDX-License-Identifier: GPL-2.0-or-newer
# Copyright (c) 2019, Oracle and/or its affiliates. All Rights Reserved.
#
# FS QA Test No. 148
#
# See if we catch corrupt directory names or attr names with nulls or slashes
# in them.
. ./common/preamble
_begin_fstest auto quick fuzzers
# Override the default cleanup function.
_cleanup()
{
cd /
$UMOUNT_PROG $mntpt > /dev/null 2>&1
_destroy_loop_device $loopdev > /dev/null 2>&1
rm -r -f $tmp.*
}
# Import common functions.
. ./common/filter
. ./common/attr
# real QA test starts here
_supported_fs xfs
_require_test
_require_attrs
_require_xfs_nocrc
_disable_dmesg_check
imgfile=$TEST_DIR/img-$seq
mntpt=$TEST_DIR/mount-$seq
testdir=$mntpt/testdir
testfile=$mntpt/testfile
nullstr="too_many_beans"
slashstr="are_bad_for_you"
test_names=("something" "$nullstr" "$slashstr" "another")
rm -f $imgfile $imgfile.old
# Format image file w/o crcs so we can sed the image file
#
# TODO: It might be possible to rewrite this using proper xfs_db
# fs manipulation commands that would work with CRCs.
#
# We need to use 512 byte inodes to ensure the attr forks remain in short form
# even when security xattrs are present so we are always doing name matches on
# lookup and not name hash compares as leaf/node forms will do.
$XFS_IO_PROG -f -c 'truncate 40m' $imgfile
loopdev=$(_create_loop_device $imgfile)
MKFS_OPTIONS="-m crc=0 -i size=512" _mkfs_dev $loopdev >> $seqres.full
# Mount image file
mkdir -p $mntpt
_mount $loopdev $mntpt
echo "creating entries" >> $seqres.full
# Create directory entries
mkdir -p $testdir
for name in "${test_names[@]}"; do
touch "$testdir/f_$name"
done
# Create attrs
touch $testfile
for name in "${test_names[@]}"; do
$ATTR_PROG -s "a_$name" -V heh $testfile >> $seqres.full
done
# Now put in the first part of the garbage names to make sure we can't
# access those directly
test_names+=("too_many" "are_bad/for_you")
access_stuff() {
ls $testdir
$ATTR_PROG -l $testfile | grep 'a_' | sort
for name in "${test_names[@]}"; do
ls "$testdir/f_$name"
$ATTR_PROG -g "a_$name" $testfile
done
}
# Does it work?
echo "++ ACCESSING GOOD METADATA" | tee -a $seqres.full
access_stuff > $tmp.log 2>&1
cat $tmp.log >> $seqres.full
cat $tmp.log | _filter_test_dir
# Corrupt the entries
$UMOUNT_PROG $mntpt
_destroy_loop_device $loopdev
cp $imgfile $imgfile.old
sed -b \
-e "s/$nullstr/too_many\x00beans/g" \
-e "s/$slashstr/are_bad\/for_you/g" \
-i $imgfile
test "$(md5sum < $imgfile)" != "$(md5sum < $imgfile.old)" ||
_fail "sed failed to change the image file?"
loopdev=$(_create_loop_device $imgfile)
_mount $loopdev $mntpt
# Try to access the corrupt metadata
echo "++ ACCESSING BAD METADATA" | tee -a $seqres.full
access_stuff > $tmp.log 2>&1
cat $tmp.log >> $seqres.full
cat $tmp.log | _filter_test_dir | sed -e '/Could not list/d'
echo "does scrub complain?" >> $seqres.full
# Does scrub complain about this?
if _supports_xfs_scrub $mntpt $loopdev; then
$XFS_SCRUB_PROG -n $mntpt >> $seqres.full 2>&1
res=$?
test $((res & 1)) -eq 0 && \
echo "scrub failed to report corruption ($res)"
fi
echo "does repair complain?" >> $seqres.full
# Does repair complain about this?
$UMOUNT_PROG $mntpt
$XFS_REPAIR_PROG -n $loopdev >> $seqres.full 2>&1
res=$?
test $res -eq 1 || \
echo "repair failed to report corruption ($res)"
# success, all done
status=0
exit
|