#!/bin/sh12#3# SPDX-License-Identifier: BSD-2-Clause4#5# Copyright (c) 2021 Peter Holm <[email protected]>6#7# Redistribution and use in source and binary forms, with or without8# modification, are permitted provided that the following conditions9# are met:10# 1. Redistributions of source code must retain the above copyright11# notice, this list of conditions and the following disclaimer.12# 2. Redistributions in binary form must reproduce the above copyright13# notice, this list of conditions and the following disclaimer in the14# documentation and/or other materials provided with the distribution.15#16# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND17# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE18# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE19# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE20# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL21# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS22# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)23# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT24# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY25# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF26# SUCH DAMAGE.27#2829# Test scenario input by: "Patrick Sullivan" [email protected]3031# Bug 25359332# "panic: ldvp 0xffff... fl 0x1 dvp 0xffff... fl 0 flags 0x34048144" seen.33# https://people.freebsd.org/~pho/stress/log/log0087.txt3435[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 13637. ../default.cfg3839mount | grep $mntpoint | grep -q /dev/md && umount -f $mntpoint40mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart4142odir=`pwd`43cd /tmp44sed '1,/^EOF/d' < $odir/$0 > chroot.c45rm -f /tmp/chroot46mycc -o chroot -Wall -Wextra -O0 -g chroot.c -static || exit 147rm -f chroot.c4849mdconfig -a -t swap -s 10m -u $mdstart || exit 150newfs -n $newfs_flags md$mdstart > /dev/null51mount /dev/md$mdstart $mntpoint52mkdir -p $mntpoint/root/dir $mntpoint/jail $mntpoint/dev53mount -t nullfs $mntpoint/root $mntpoint/jail54mount -t devfs null $mntpoint/dev55mv /tmp/chroot $mntpoint/root5657chroot $mntpoint/jail ./chroot &58sleep .559mv $mntpoint/root/dir $mntpoint60wait6162umount $mntpoint/dev63umount $mntpoint/jail64while mount | grep "on $mntpoint " | grep -q /dev/md; do65umount $mntpoint || sleep 166done67mdconfig -d -u $mdstart68exit69EOF70#include <sys/types.h>71#include <err.h>72#include <stdio.h>73#include <unistd.h>7475int76main(void)77{78if (chdir("dir") == -1)79err(1, "chdir() #1");80sleep(2);81fprintf(stderr, "cwd is %s\n", getwd(NULL));82}838485