xfs/530: skip test if user MKFS_OPTIONS screw up formatting
[xfstests-dev.git] / tests / xfs / 520
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2020 Red Hat, Inc.  All Rights Reserved.
4 #
5 # FS QA Test 520
6 #
7 # Verify kernel doesn't hang when mounting a crafted image
8 # with bad agf.freeblks metadata due to CVE-2020-12655.
9 #
10 # Also, check if
11 # commit d0c7feaf8767 ("xfs: add agf freeblocks verify in xfs_agf_verify")
12 # is included in the current kernel.
13 #
14 . ./common/preamble
15 _begin_fstest auto quick reflink
16
17 # Override the default cleanup function.
18 _cleanup()
19 {
20         cd /
21         rm -f $tmp.*
22         _scratch_unmount > /dev/null 2>&1
23 }
24
25 # Import common functions.
26 . ./common/filter
27
28 # real QA test starts here
29
30 _supported_fs xfs
31 _disable_dmesg_check
32 _require_check_dmesg
33 _require_scratch_nocheck
34
35 # Don't let the rtbitmap fill up the data device and screw up this test
36 unset USE_EXTERNAL
37
38 force_crafted_metadata() {
39         _scratch_mkfs_xfs -f $fsdsopt "$4" >> $seqres.full 2>&1 || _fail "mkfs failed"
40         _scratch_xfs_set_metadata_field "$1" "$2" "$3" >> $seqres.full 2>&1
41         local kmsg="xfs/$seq: testing $1=$2 at $(date +"%F %T")"
42         local mounted=0
43         local hasmsg=0
44
45         echo "${kmsg}" > /dev/kmsg
46         _try_scratch_mount >> $seqres.full 2>&1 && mounted=1
47
48         if [ $mounted -ne 0 ]; then
49                 dd if=/dev/zero of=$SCRATCH_MNT/test bs=65536 count=1 >> \
50                         $seqres.full 2>&1
51                 sync
52         fi
53
54         _dmesg_since_test_start | tac | sed -ne "0,\#${kmsg}#p" | tac | \
55                 egrep -q 'Metadata corruption detected at' && hasmsg=1
56
57         _scratch_unmount > /dev/null 2>&1
58         [ $mounted -eq 0 -o $hasmsg -eq 1 ] || \
59                 _fail "potential broken kernel (mounted=${mounted},hasmsg=${hasmsg})"
60 }
61
62 bigval=100000000
63 fsdsopt="-d agcount=1,size=64m"
64
65 force_crafted_metadata freeblks 0 "agf 0"
66 force_crafted_metadata longest $bigval "agf 0"
67 force_crafted_metadata length $bigval "agf 0"
68
69 _scratch_mkfs_xfs_supported -m reflink=1 >> $seqres.full 2>&1 && \
70         force_crafted_metadata refcntblocks $bigval "agf 0" "-m reflink=1"
71
72 _scratch_mkfs_xfs_supported -m rmapbt=1 >> $seqres.full 2>&1 && \
73         force_crafted_metadata rmapblocks $bigval "agf 0" "-m rmapbt=1"
74
75 echo "Silence is golden"
76
77 # success, all done
78 status=0
79 exit