2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2020 Red Hat, Inc. All Rights Reserved.
7 # Verify kernel doesn't hang when mounting a crafted image
8 # with bad agf.freeblks metadata due to CVE-2020-12655.
11 # commit d0c7feaf8767 ("xfs: add agf freeblocks verify in xfs_agf_verify")
12 # is included in the current kernel.
15 seqres=$RESULT_DIR/$seq
16 echo "QA output created by $seq"
20 status=1 # failure is the default!
21 trap "_cleanup; exit \$status" 0 1 2 3 15
27 _scratch_unmount > /dev/null 2>&1
30 # get standard environment, filters and checks
34 # remove previous $seqres.full before test
37 # real QA test starts here
42 _require_scratch_nocheck
44 # Don't let the rtbitmap fill up the data device and screw up this test
47 force_crafted_metadata() {
48 _scratch_mkfs_xfs -f $fsdsopt "$4" >> $seqres.full 2>&1 || _fail "mkfs failed"
49 _scratch_xfs_set_metadata_field "$1" "$2" "$3" >> $seqres.full 2>&1
50 local kmsg="xfs/$seq: testing $1=$2 at $(date +"%F %T")"
54 echo "${kmsg}" > /dev/kmsg
55 _try_scratch_mount >> $seqres.full 2>&1 && mounted=1
57 if [ $mounted -ne 0 ]; then
58 dd if=/dev/zero of=$SCRATCH_MNT/test bs=65536 count=1 >> \
63 _dmesg_since_test_start | tac | sed -ne "0,\#${kmsg}#p" | tac | \
64 egrep -q 'Metadata corruption detected at' && hasmsg=1
66 _scratch_unmount > /dev/null 2>&1
67 [ $mounted -eq 0 -o $hasmsg -eq 1 ] || \
68 _fail "potential broken kernel (mounted=${mounted},hasmsg=${hasmsg})"
72 fsdsopt="-d agcount=1,size=64m"
74 force_crafted_metadata freeblks 0 "agf 0"
75 force_crafted_metadata longest $bigval "agf 0"
76 force_crafted_metadata length $bigval "agf 0"
78 _scratch_mkfs_xfs_supported -m reflink=1 >> $seqres.full 2>&1 && \
79 force_crafted_metadata refcntblocks $bigval "agf 0" "-m reflink=1"
81 _scratch_mkfs_xfs_supported -m rmapbt=1 >> $seqres.full 2>&1 && \
82 force_crafted_metadata rmapblocks $bigval "agf 0" "-m rmapbt=1"
84 echo "Silence is golden"