1#!/bin/sh 2 3# 4# SPDX-License-Identifier: BSD-2-Clause-FreeBSD 5# 6# Copyright (c) 2022 Peter Holm <pho@FreeBSD.org> 7# 8# Redistribution and use in source and binary forms, with or without 9# modification, are permitted provided that the following conditions 10# are met: 11# 1. Redistributions of source code must retain the above copyright 12# notice, this list of conditions and the following disclaimer. 13# 2. Redistributions in binary form must reproduce the above copyright 14# notice, this list of conditions and the following disclaimer in the 15# documentation and/or other materials provided with the distribution. 16# 17# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 18# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 21# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27# SUCH DAMAGE. 28# 29 30# msdosfs disk image fuzz test. 31 32# "panic: wrong dirclust" seen: 33# https://people.freebsd.org/~pho/stress/log/log0206.txt 34 35. ../default.cfg 36 37[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 38 39cc -o /tmp/flip -Wall -Wextra -O2 ../tools/flip.c || exit 1 40 41set -e 42u1=$mdstart 43u2=$((mdstart + 1)) 44mp1=${mntpoint}$u1 45mp2=${mntpoint}$u2 46mkdir -p $mp1 $mp2 47log=$mp1/msdos15.sh.log 48diskimage=$mp1/msdos15.sh.diskimage 49cap=$((32 * 1024)) # Only fuzz the first 32k 50max=$((10 * 1024 * 1024)) # dos disk size 51 52set +e 53mount | grep "on $mp1 " | grep -q /dev/md && umount -f $mp1 54[ -c /dev/md$u1 ] && mdconfig -d -u $u1 55mdconfig -a -t swap -s 1g -u $u1 56newfs -U /dev/md$u1 > /dev/null 57mount /dev/md$u1 $mp1 58 59[ -c /dev/md$u2 ] && mdconfig -d -u $u2 60dd if=/dev/zero of=$diskimage bs=$max count=1 status=none 61mdconfig -a -t vnode -f $diskimage -u $u2 62newfs_msdos /dev/md$u2 > /dev/null 2>&1 # FAT12 63mount -t msdosfs /dev/md$u2 $mp2 64[ -d /usr/include/sys ] && cp -r /usr/include/sys $mp2 65umount $mp2 66 67cd $mp1 68start=`date +%s` 69while [ $((`date +%s` - start)) -lt 60 ]; do 70 mount -t msdosfs /dev/md$u2 $mp2 2>/dev/null || break 71 ls -lR $mp2 > /dev/null 2>&1 || break 72 rm -rf $mp2/* > /dev/null 2>&1 || break 73 touch $mp2/`jot -rc 8 a z | tr -d '\n'` || break 74 while mount | grep -q "on $mp2 "; do umount $mp2; done 75 echo * | grep -q core && break 76 sync 77 mdconfig -d -u $u2 78 /tmp/flip -n 10 -s $cap $diskimage 79 sync 80 mdconfig -a -t vnode -f $diskimage -u $u2 81done 82mount | grep -q "on $mp2 " && umount $mp2 83mdconfig -d -u $u2 || exit 1 84 85echo * | grep -q core && { ls -l *.core; cp $log /tmp; exit 106; } || 86cd /tmp 87umount $mp1 88mdconfig -d -u $u1 89rm -f /tmp/flip 90exit 0 91