18a272653SPeter Holm#!/bin/sh 28a272653SPeter Holm 38a272653SPeter Holm# 48a272653SPeter Holm# Copyright (c) 2011 Peter Holm 58a272653SPeter Holm# All rights reserved. 68a272653SPeter Holm# 78a272653SPeter Holm# Redistribution and use in source and binary forms, with or without 88a272653SPeter Holm# modification, are permitted provided that the following conditions 98a272653SPeter Holm# are met: 108a272653SPeter Holm# 1. Redistributions of source code must retain the above copyright 118a272653SPeter Holm# notice, this list of conditions and the following disclaimer. 128a272653SPeter Holm# 2. Redistributions in binary form must reproduce the above copyright 138a272653SPeter Holm# notice, this list of conditions and the following disclaimer in the 148a272653SPeter Holm# documentation and/or other materials provided with the distribution. 158a272653SPeter Holm# 168a272653SPeter Holm# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 178a272653SPeter Holm# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 188a272653SPeter Holm# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 198a272653SPeter Holm# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 208a272653SPeter Holm# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 218a272653SPeter Holm# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 228a272653SPeter Holm# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 238a272653SPeter Holm# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 248a272653SPeter Holm# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 258a272653SPeter Holm# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 268a272653SPeter Holm# SUCH DAMAGE. 278a272653SPeter Holm# 288a272653SPeter Holm 298a272653SPeter Holm# "panic: vn_lock 0xc65b5828: zero hold count" seen. 308a272653SPeter Holm 318a272653SPeter Holm# Originally found by the iknowthis test suite 328a272653SPeter Holm# by Tavis Ormandy <taviso cmpxchg8b com> 338a272653SPeter Holm# Fixed by r227952 348a272653SPeter Holm 358a272653SPeter Holm[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 368a272653SPeter Holm 378a272653SPeter Holm. ../default.cfg 388a272653SPeter Holm 398a272653SPeter Holmodir=`pwd` 408a272653SPeter Holmcd /tmp 418a272653SPeter Holmsed '1,/^EOF/d' < $odir/$0 > devfd.c 428a272653SPeter Holmrm -f /tmp/devfd 438a272653SPeter Holmmycc -o devfd -Wall -Wextra -O2 -g devfd.c -lpthread || exit 1 448a272653SPeter Holmrm -f devfd.c 458a272653SPeter Holm 468a272653SPeter Holmmount | grep $mntpoint | grep -q /dev/md && umount -f $mntpoint 478a272653SPeter Holmmdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart 488a272653SPeter Holm 498a272653SPeter Holmmdconfig -a -t swap -s 1g -u $mdstart || exit 1 50*608c97bfSPeter Holmnewfs $newfs_flags md$mdstart > /dev/null 51*608c97bfSPeter Holmmount /dev/md$mdstart $mntpoint 528a272653SPeter Holmchmod 777 $mntpoint 538a272653SPeter Holm 548a272653SPeter Holmsu $testuser -c "(cd $mntpoint; /tmp/devfd)" 558a272653SPeter Holm 568a272653SPeter Holmwhile mount | grep $mntpoint | grep -q /dev/md; do 578a272653SPeter Holm umount $mntpoint || sleep 1 588a272653SPeter Holmdone 598a272653SPeter Holmmdconfig -d -u $mdstart 608a272653SPeter Holmrm -f /tmp/devfd 618a272653SPeter Holmexit 628a272653SPeter HolmEOF 638a272653SPeter Holm#include <err.h> 648a272653SPeter Holm#include <fcntl.h> 658a272653SPeter Holm#include <pthread.h> 668a272653SPeter Holm#include <stdio.h> 678a272653SPeter Holm#include <stdlib.h> 688a272653SPeter Holm#include <sys/param.h> 698a272653SPeter Holm#include <sys/stat.h> 708a272653SPeter Holm#include <sys/types.h> 718a272653SPeter Holm#include <unistd.h> 728a272653SPeter Holm 738a272653SPeter Holmint fd[3], fd2[3]; 748a272653SPeter Holm 758a272653SPeter Holmvoid * 768a272653SPeter Holmthr1(void *arg __unused) 778a272653SPeter Holm{ 788a272653SPeter Holm int i, j; 798a272653SPeter Holm char path[80]; 808a272653SPeter Holm 818a272653SPeter Holm for (i = 0; i < 100000; i++) { 828a272653SPeter Holm for (j = 0; j < 3; j++) { 838a272653SPeter Holm if (fd[j] != -1) 848a272653SPeter Holm close(fd[j]); 858a272653SPeter Holm sprintf(path, "fx%d", j); 868a272653SPeter Holm fd[j] = open(path, O_RDWR | O_CREAT, 0640); 878a272653SPeter Holm } 888a272653SPeter Holm } 898a272653SPeter Holm return (0); 908a272653SPeter Holm} 918a272653SPeter Holm 928a272653SPeter Holmvoid * 938a272653SPeter Holmthr2(void *arg __unused) 948a272653SPeter Holm{ 958a272653SPeter Holm int i, j; 968a272653SPeter Holm char path[80]; 978a272653SPeter Holm 988a272653SPeter Holm for (i = 0; i < 100000; i++) { 998a272653SPeter Holm for (j = 0; j < 3; j++) { 1008a272653SPeter Holm if (fd2[j] != -1) 1018a272653SPeter Holm close(fd2[j]); 1028a272653SPeter Holm sprintf(path, "/dev/fd/%d", j); 1038a272653SPeter Holm if ((fd2[j] = open(path, O_RDONLY)) != -1) 1048a272653SPeter Holm fchflags(fd2[j], UF_NODUMP); 1058a272653SPeter Holm } 1068a272653SPeter Holm 1078a272653SPeter Holm } 1088a272653SPeter Holm return (0); 1098a272653SPeter Holm} 1108a272653SPeter Holm 1118a272653SPeter Holmint 1128a272653SPeter Holmmain(void) 1138a272653SPeter Holm{ 1148a272653SPeter Holm pthread_t p1, p2; 1158a272653SPeter Holm int r; 1168a272653SPeter Holm 1178a272653SPeter Holm close(0); 1188a272653SPeter Holm close(1); 1198a272653SPeter Holm close(2); 1208a272653SPeter Holm if ((r = pthread_create(&p1, NULL, thr1, NULL)) != 0) 1218a272653SPeter Holm errc(1, r, "pthread_create"); 1228a272653SPeter Holm if ((r = pthread_create(&p2, NULL, thr2, NULL)) != 0) 1238a272653SPeter Holm errc(1, r, "pthread_create"); 1248a272653SPeter Holm pthread_join(p1, NULL); 1258a272653SPeter Holm pthread_join(p2, NULL); 1268a272653SPeter Holm 1278a272653SPeter Holm return (0); 1288a272653SPeter Holm} 1298a272653SPeter Holm 130