diff --git a/tools/test/stress2/misc/fdatasync.sh b/tools/test/stress2/misc/fdatasync.sh index f17e2826ad94..9abd31e5bd94 100755 --- a/tools/test/stress2/misc/fdatasync.sh +++ b/tools/test/stress2/misc/fdatasync.sh @@ -1,197 +1,197 @@ #!/bin/sh # # Copyright (c) 2018 Dell EMC Isilon # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # fdatasync(2) fuzz. # Deadlock seen: # https://people.freebsd.org/~pho/stress/log/fdatasync.txt [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 . ../default.cfg dir=$RUNDIR nfiles=500 [ `df -i $dir | tail -1 | awk '{print $7}'` -lt $nfiles ] && exit 0 odir=`pwd` cd /tmp sed '1,/^EOF/d' < $odir/$0 > fdatasync.c rm -f /tmp/fdatasync mycc -o fdatasync -Wall -Wextra -O2 -g fdatasync.c -lpthread || exit 1 rm -f fdatasync.c mkdir -p $dir && chmod 777 $dir cd $dir jot $nfiles | xargs touch jot $nfiles | xargs chmod 666 cd $odir (cd /tmp; /tmp/fdatasync $dir) e=$? rm -rf $dir/* /tmp/fdatasync exit $e EOF #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define N (128 * 1024 / (int)sizeof(u_int32_t)) #define RUNTIME 180 #define THREADS 2 static int fd[900]; static u_int32_t r[N]; static char *args[2]; static unsigned long makearg(void) { unsigned long val; val = arc4random(); #if defined(__LP64__) val = (val << 32) | arc4random(); val = val & 0x00007fffffffffffUL; #endif return(val); } static void * test(void *arg __unused) { FTS *fts; FTSENT *p; int ftsoptions, i, n; ftsoptions = FTS_PHYSICAL; for (;;) { for (i = 0; i < N; i++) r[i] = arc4random(); if ((fts = fts_open(args, ftsoptions, NULL)) == NULL) err(1, "fts_open"); i = n = 0; while ((p = fts_read(fts)) != NULL) { if (fd[i] > 0) close(fd[i]); if ((fd[i] = open(p->fts_path, O_RDWR)) == -1) if ((fd[i] = open(p->fts_path, O_WRONLY)) == -1) continue; if (ftruncate(fd[i], 0) != 0) err(1, "ftruncate"); i++; i = i % nitems(fd); } if (fts_close(fts) == -1) err(1, "fts_close()"); sleep(1); } return(0); } static void * calls(void *arg __unused) { off_t offset; time_t start; int fd2; start = time(NULL); while ((time(NULL) - start) < RUNTIME) { fd2 = makearg() % nitems(fd) + 3; offset = makearg(); if (lseek(fd2, offset - 1, SEEK_SET) != -1) { if (write(fd2, "x", 1) != 1) if (errno != EBADF && errno != ENOSPC && errno != E2BIG && errno != ESTALE && errno != EFBIG) warn("write"); } else if (errno != EBADF) warn("lseek"); if (fdatasync(fd2) == -1) if (errno != EBADF) warn("x"); } return (0); } int main(int argc, char **argv) { struct passwd *pw; pthread_t rp, cp[THREADS]; int e, i; if (argc != 2) { fprintf(stderr, "Usage: %s \n", argv[0]); exit(1); } args[0] = argv[1]; args[1] = 0; if ((pw = getpwnam("nobody")) == NULL) err(1, "failed to resolve nobody"); - if (setgroups(1, &pw->pw_gid) || + if (setgroups(0, NULL) || setegid(pw->pw_gid) || setgid(pw->pw_gid) || seteuid(pw->pw_uid) || setuid(pw->pw_uid)) err(1, "Can't drop privileges to \"nobody\""); endpwent(); if ((e = pthread_create(&rp, NULL, test, NULL)) != 0) errc(1, e, "pthread_create"); usleep(1000); for (i = 0; i < THREADS; i++) if ((e = pthread_create(&cp[i], NULL, calls, NULL)) != 0) errc(1, e, "pthread_create"); for (i = 0; i < THREADS; i++) pthread_join(cp[i], NULL); return (0); } diff --git a/tools/test/stress2/misc/fdatasync2.sh b/tools/test/stress2/misc/fdatasync2.sh index 6011eba53698..42ade0cedbd3 100755 --- a/tools/test/stress2/misc/fdatasync2.sh +++ b/tools/test/stress2/misc/fdatasync2.sh @@ -1,196 +1,196 @@ #!/bin/sh # # Copyright (c) 2018 Dell EMC Isilon # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # fdatasync(2) fuzz. Variation of fdatasync.sh. # https://people.freebsd.org/~pho/stress/log/fdatasync2.txt [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 . ../default.cfg dir=$RUNDIR nfiles=10000 [ `df -i $dir | tail -1 | awk '{print $7}'` -lt $nfiles ] && exit 0 odir=`pwd` cd /tmp sed '1,/^EOF/d' < $odir/$0 > fdatasync2.c rm -f /tmp/fdatasync2 mycc -o fdatasync2 -Wall -Wextra -O2 -g fdatasync2.c -lpthread || exit 1 rm -f fdatasync2.c mkdir -p $dir && chmod 777 $dir cd $dir jot $nfiles | xargs touch jot $nfiles | xargs chmod 666 cd $odir (cd /tmp; /tmp/fdatasync2 $dir) e=$? rm -rf $dir/* /tmp/fdatasync2 exit $e EOF #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define N (128 * 1024 / (int)sizeof(u_int32_t)) #define RUNTIME 180 #define THREADS 6 static int fd[900]; static u_int32_t r[N]; static char *args[2]; static unsigned long makearg(void) { unsigned long val; val = arc4random(); #if defined(__LP64__) val = (val << 32) | arc4random(); val = val & 0x00007fffffffffffUL; #endif return(val); } static void * test(void *arg __unused) { FTS *fts; FTSENT *p; int ftsoptions, i, n; ftsoptions = FTS_PHYSICAL; for (;;) { for (i = 0; i < N; i++) r[i] = arc4random(); if ((fts = fts_open(args, ftsoptions, NULL)) == NULL) err(1, "fts_open"); i = n = 0; while ((p = fts_read(fts)) != NULL) { if (fd[i] > 0) close(fd[i]); if ((fd[i] = open(p->fts_path, O_RDWR)) == -1) if ((fd[i] = open(p->fts_path, O_WRONLY)) == -1) continue; if (ftruncate(fd[i], 0) != 0) err(1, "ftruncate"); i++; i = i % nitems(fd); } if (fts_close(fts) == -1) err(1, "fts_close()"); sleep(1); } return(0); } static void * calls(void *arg __unused) { off_t offset; time_t start; int fd2; start = time(NULL); while ((time(NULL) - start) < RUNTIME) { fd2 = makearg() % nitems(fd) + 3; offset = makearg(); if (lseek(fd2, offset - 1, SEEK_SET) != -1) { if (write(fd2, "x", 1) != 1) if (errno != EBADF && errno != ENOSPC && errno != E2BIG && errno != ESTALE && errno != EFBIG) warn("write"); } else if (errno != EBADF) warn("lseek"); if (fdatasync(fd2) == -1) if (errno != EBADF) warn("x"); } return (0); } int main(int argc, char **argv) { struct passwd *pw; pthread_t rp, cp[THREADS]; int e, i, threads; if (argc != 2) { fprintf(stderr, "Usage: %s \n", argv[0]); exit(1); } args[0] = argv[1]; args[1] = 0; threads = arc4random() % (THREADS -1 ) + 2; /* 2 - THREADS */ if ((pw = getpwnam("nobody")) == NULL) err(1, "failed to resolve nobody"); - if (setgroups(1, &pw->pw_gid) || + if (setgroups(0, NULL) || setegid(pw->pw_gid) || setgid(pw->pw_gid) || seteuid(pw->pw_uid) || setuid(pw->pw_uid)) err(1, "Can't drop privileges to \"nobody\""); endpwent(); if ((e = pthread_create(&rp, NULL, test, NULL)) != 0) errc(1, e, "pthread_create"); usleep(1000); for (i = 0; i < threads; i++) if ((e = pthread_create(&cp[i], NULL, calls, NULL)) != 0) errc(1, e, "pthread_create"); for (i = 0; i < threads; i++) pthread_join(cp[i], NULL); return (0); } diff --git a/tools/test/stress2/misc/fifo2.sh b/tools/test/stress2/misc/fifo2.sh index 4a7b986931d9..e84506cbfb01 100755 --- a/tools/test/stress2/misc/fifo2.sh +++ b/tools/test/stress2/misc/fifo2.sh @@ -1,204 +1,204 @@ #!/bin/sh # # Copyright (c) 2013 EMC Corp. # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # Page fault seen # http://people.freebsd.org/~pho/stress/log/kostik654.txt # Fixed by r259521. [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 . ../default.cfg odir=`pwd` cd /tmp sed '1,/^EOF/d' < $odir/$0 > fifo2.c rm -f /tmp/fifo2 mycc -o fifo2 -Wall -Wextra -O2 -g fifo2.c -lpthread || exit 1 rm -f fifo2.c mount | grep $mntpoint | grep -q /dev/md && umount -f $mntpoint mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart mdconfig -a -t swap -s 1g -u $mdstart || exit 1 newfs $newfs_flags md$mdstart > /dev/null mount /dev/md$mdstart $mntpoint chmod 777 $mntpoint mkfifo $mntpoint/f chmod 777 $mntpoint/f sleeptime=12 st=`date '+%s'` while [ $((`date '+%s'` - st)) -lt $((10 * sleeptime)) ]; do (cd $mntpoint; /tmp/fifo2) & start=`date '+%s'` while [ $((`date '+%s'` - start)) -lt $sleeptime ]; do pgrep -q fifo2 || break sleep .5 done while pkill -9 fifo2; do :; done wait done for i in `jot 10`; do mount | grep -q md$mdstart && \ umount $mntpoint > /dev/null 2>&1 && mdconfig -d -u $mdstart && break sleep 10 done s=0 mount | grep -q md$mdstart && { echo "umount $mntpoint failed"; s=1; } rm -f /tmp/fifo2 exit $s EOF #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define N (128 * 1024 / (int)sizeof(u_int32_t)) static int debug; /* Set to 1 for debug output */ u_int32_t r[N]; static void hand(int i __unused) { /* handler */ _exit(1); } static unsigned long makearg(void) { unsigned int i; unsigned long val; val = arc4random(); i = arc4random() % 100; if (i < 20) val = val & 0xff; if (i >= 20 && i < 40) val = val & 0xffff; if (i >= 40 && i < 60) val = (unsigned long)(r) | (val & 0xffff); #if defined(__LP64__) if (i >= 60) { val = (val << 32) | arc4random(); if (i > 80) val = val & 0x00007fffffffffffUL; } #endif return(val); } static void * calls(void *arg __unused) { unsigned long arg1, arg2, arg3, arg4, arg5, arg6, arg7; int i; for (i = 0;; i++) { arg1 = (unsigned long)(void *)"f"; arg2 = makearg(); arg3 = makearg(); arg4 = makearg(); arg5 = makearg(); arg6 = makearg(); arg7 = makearg(); if (debug != 0) fprintf(stderr, "%2d : syscall(%3d, %lx, %lx, %lx, %lx, %lx, %lx, %lx)\n", i, SYS_open, arg1, arg2, arg3, arg4, arg5, arg6, arg7); usleep(100000); alarm(1); syscall(SYS_open, arg1, arg2, arg3, arg4, arg5, arg6, arg7); } return (0); } int main(void) { struct passwd *pw; struct rlimit limit; pthread_t cp[50]; time_t start; int e, j; if ((pw = getpwnam("nobody")) == NULL) err(1, "no such user: nobody"); - if (setgroups(1, &pw->pw_gid) || + if (setgroups(0, NULL) || setegid(pw->pw_gid) || setgid(pw->pw_gid) || seteuid(pw->pw_uid) || setuid(pw->pw_uid)) err(1, "Can't drop privileges to \"nobody\""); endpwent(); limit.rlim_cur = limit.rlim_max = 1000; if (setrlimit(RLIMIT_NPTS, &limit) < 0) err(1, "setrlimit"); signal(SIGALRM, hand); signal(SIGILL, hand); signal(SIGFPE, hand); signal(SIGSEGV, hand); signal(SIGBUS, hand); signal(SIGURG, hand); signal(SIGSYS, hand); signal(SIGTRAP, hand); start = time(NULL); while ((time(NULL) - start) < 120) { if (fork() == 0) { for (j = 0; j < 1; j++) if ((e = pthread_create(&cp[j], NULL, calls, NULL)) != 0) errc(1, e,"pthread_create"); for (j = 0; j < 1; j++) pthread_join(cp[j], NULL); _exit(0); } wait(NULL); } return (0); } diff --git a/tools/test/stress2/misc/ftruncate.sh b/tools/test/stress2/misc/ftruncate.sh index ddec85b6745a..f9aa1869756f 100755 --- a/tools/test/stress2/misc/ftruncate.sh +++ b/tools/test/stress2/misc/ftruncate.sh @@ -1,189 +1,189 @@ #!/bin/sh # # Copyright (c) 2016 EMC Corp. # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # ftruncate(2) fuzz. # "panic: softdep_deallocate_dependencies: dangling deps" seen in # 10.3-STABLE: # https://people.freebsd.org/~pho/stress/log/ftruncate.txt [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 . ../default.cfg dir=$RUNDIR odir=`pwd` cd /tmp sed '1,/^EOF/d' < $odir/$0 > ftruncate.c rm -f /tmp/ftruncate mycc -o ftruncate -Wall -Wextra -O2 -g ftruncate.c -lpthread || exit 1 rm -f ftruncate.c rm -rf $dir mkdir -p $dir chmod 777 $dir cd $dir jot 500 | xargs touch jot 500 | xargs chmod 666 cd $odir (cd /tmp; /tmp/ftruncate $dir) e=$? rm -rf $dir rm -f /tmp/ftruncate exit $e EOF #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define N (128 * 1024 / (int)sizeof(u_int32_t)) #define RUNTIME 180 #define THREADS 2 static int fd[900]; static u_int32_t r[N]; static char *args[2]; static unsigned long makearg(void) { unsigned long val; val = arc4random(); #if defined(__LP64__) val = (val << 32) | arc4random(); val = val & 0x00007fffffffffffUL; #endif return(val); } static void * test(void *arg __unused) { FTS *fts; FTSENT *p; int ftsoptions, i, n; ftsoptions = FTS_PHYSICAL; for (;;) { for (i = 0; i < N; i++) r[i] = arc4random(); if ((fts = fts_open(args, ftsoptions, NULL)) == NULL) err(1, "fts_open"); i = n = 0; while ((p = fts_read(fts)) != NULL) { if (fd[i] > 0) close(fd[i]); if ((fd[i] = open(p->fts_path, O_RDWR)) == -1) if ((fd[i] = open(p->fts_path, O_WRONLY)) == -1) continue; i++; i = i % nitems(fd); } if (fts_close(fts) == -1) err(1, "fts_close()"); sleep(1); } return(0); } static void * calls(void *arg __unused) { off_t offset; time_t start; int fd2; start = time(NULL); while ((time(NULL) - start) < RUNTIME) { fd2 = makearg() % nitems(fd) + 3; offset = makearg(); if (ftruncate(fd2, offset) == 0) { if (lseek(fd2, offset - 1, SEEK_SET) != -1) write(fd2, "x", 1); } } return (0); } int main(int argc, char **argv) { struct passwd *pw; pthread_t rp, cp[THREADS]; int e, i; if (argc != 2) { fprintf(stderr, "Usage: %s \n", argv[0]); exit(1); } args[0] = argv[1]; args[1] = 0; if ((pw = getpwnam("nobody")) == NULL) err(1, "failed to resolve nobody"); - if (setgroups(1, &pw->pw_gid) || + if (setgroups(0, NULL) || setegid(pw->pw_gid) || setgid(pw->pw_gid) || seteuid(pw->pw_uid) || setuid(pw->pw_uid)) err(1, "Can't drop privileges to \"nobody\""); endpwent(); if ((e = pthread_create(&rp, NULL, test, NULL)) != 0) errc(1, e, "pthread_create"); usleep(1000); for (i = 0; i < THREADS; i++) if ((e = pthread_create(&cp[i], NULL, calls, NULL)) != 0) errc(1, e, "pthread_create"); for (i = 0; i < THREADS; i++) pthread_join(cp[i], NULL); return (0); } diff --git a/tools/test/stress2/misc/ftruncate2.sh b/tools/test/stress2/misc/ftruncate2.sh index 35db3a4c5f8d..94d9b6ca810f 100755 --- a/tools/test/stress2/misc/ftruncate2.sh +++ b/tools/test/stress2/misc/ftruncate2.sh @@ -1,204 +1,204 @@ #!/bin/sh # # Copyright (c) 2016 EMC Corp. # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # A fuzz test triggered a failed block allocation unwinding problem. # "panic: ffs_blkfree_cg: freeing free block" seen: # https://people.freebsd.org/~pho/stress/log/kostik923.txt # Fixed by r304232. [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 . ../default.cfg odir=`pwd` cd /tmp sed '1,/^EOF/d' < $odir/$0 > ftruncate2.c rm -f /tmp/ftruncate2 mycc -o ftruncate2 -Wall -Wextra -O2 -g ftruncate2.c -lpthread || exit 1 rm -f ftruncate2.c echo "Expect: \"/mnt: write failed, filesystem is full\"" mount | grep $mntpoint | grep -q "on $mntpoint " && umount -f $mntpoint mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart mdconfig -a -t swap -s 1g -u $mdstart || exit 1 newfs md$mdstart > /dev/null # Non SU panics mount /dev/md$mdstart $mntpoint dir=$mntpoint chmod 777 $dir cd $dir jot 500 | xargs touch jot 500 | xargs chmod 666 cd $odir (cd /tmp; /tmp/ftruncate2 $dir) e=$? rm -rf $dir/* while mount | grep -q "on $mntpoint "; do umount $mntpoint || sleep 1 done mdconfig -d -u $mdstart rm -f /tmp/ftruncate2 exit $e EOF #include #include #include #include #include #include #include #include #include #include #include #include #include #define N (128 * 1024 / (int)sizeof(u_int32_t)) #define RUNTIME 180 #define THREADS 2 static int fd[900]; static u_int32_t r[N]; static char *args[2]; static unsigned long makearg(void) { unsigned long val; val = arc4random(); #if defined(__LP64__) val = (val << 32) | arc4random(); val = val & 0x00007fffffffffffUL; #endif return(val); } static void * test(void *arg __unused) { FTS *fts; FTSENT *p; int ftsoptions, i, n; ftsoptions = FTS_PHYSICAL; for (;;) { for (i = 0; i < N; i++) r[i] = arc4random(); if ((fts = fts_open(args, ftsoptions, NULL)) == NULL) err(1, "fts_open"); i = n = 0; while ((p = fts_read(fts)) != NULL) { if (fd[i] > 0) close(fd[i]); if ((fd[i] = open(p->fts_path, O_RDWR)) == -1) if ((fd[i] = open(p->fts_path, O_WRONLY)) == -1) continue; if (ftruncate(fd[i], 0) != 0) err(1, "ftruncate"); i++; i = i % nitems(fd); } if (fts_close(fts) == -1) err(1, "fts_close()"); sleep(1); } return(0); } static void * calls(void *arg __unused) { off_t offset; time_t start; int fd2; start = time(NULL); while ((time(NULL) - start) < RUNTIME) { fd2 = makearg() % nitems(fd) + 3; offset = makearg(); if (lseek(fd2, offset - 1, SEEK_SET) != -1) { if (write(fd2, "x", 1) != 1) if (errno != EBADF && errno != ENOSPC && errno != E2BIG && errno != ESTALE && errno != EFBIG) warn("write"); } else if (errno != EBADF) warn("lseek"); if (fsync(fd2) == -1) if (errno != EBADF) warn("x"); } return (0); } int main(int argc, char **argv) { struct passwd *pw; pthread_t rp, cp[THREADS]; int e, i; if (argc != 2) { fprintf(stderr, "Usage: %s \n", argv[0]); exit(1); } args[0] = argv[1]; args[1] = 0; if ((pw = getpwnam("nobody")) == NULL) err(1, "failed to resolve nobody"); - if (setgroups(1, &pw->pw_gid) || + if (setgroups(0, NULL) || setegid(pw->pw_gid) || setgid(pw->pw_gid) || seteuid(pw->pw_uid) || setuid(pw->pw_uid)) err(1, "Can't drop privileges to \"nobody\""); endpwent(); if ((e = pthread_create(&rp, NULL, test, NULL)) != 0) errc(1, e, "pthread_create"); usleep(1000); for (i = 0; i < THREADS; i++) if ((e = pthread_create(&cp[i], NULL, calls, NULL)) != 0) errc(1, e, "pthread_create"); for (i = 0; i < THREADS; i++) pthread_join(cp[i], NULL); return (0); } diff --git a/tools/test/stress2/misc/kevent7.sh b/tools/test/stress2/misc/kevent7.sh index 8b58c35551f7..4c7718c6ae5f 100755 --- a/tools/test/stress2/misc/kevent7.sh +++ b/tools/test/stress2/misc/kevent7.sh @@ -1,280 +1,280 @@ #!/bin/sh # # Copyright (c) 2013 EMC Corp. # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # Threaded syscall(2) fuzz test inspired by the iknowthis test suite # by Tavis Ormandy # kevent(2) with random arguments. # Spinning threads seen. # Fixed in r255877. # "panic: softclock_call_cc: act 0xfffff801219a0840 0" seen: # https://people.freebsd.org/~pho/stress/log/kevent7.txt # Fixed by r315289 [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 . ../default.cfg ulimit -t 200 odir=`pwd` cd /tmp sed '1,/^EOF/d' < $odir/$0 > kevent7.c rm -f /tmp/kevent7 mycc -o kevent7 -Wall -Wextra -O2 -g kevent7.c -lpthread || exit 1 rm -f kevent7.c mount | grep $mntpoint | grep -q /dev/md && umount -f $mntpoint mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart mdconfig -a -t swap -s 2g -u $mdstart || exit 1 newfs $newfs_flags md$mdstart > /dev/null mount /dev/md$mdstart $mntpoint chmod 777 $mntpoint for i in `jot 5`; do (cd $mntpoint; /tmp/kevent7 $* < /dev/null) & sleep 60 while pgrep -q kevent7; do pkill -9 kevent7 sleep 1 done done for i in `jot 5`; do mount | grep -q md$mdstart && \ umount $mntpoint && mdconfig -d -u $mdstart && break sleep 10 done if mount | grep -q md$mdstart; then fstat $mntpoint echo "umount $mntpoint failed" exit 1 fi rm -f /tmp/kevent7 exit 0 EOF #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define THREADS 50 int fd[900], fds[2], socketpr[2]; #define N (128 * 1024 / (int)sizeof(u_int32_t)) static u_int32_t r[N]; static int syscallno; static void hand(int i __unused) { /* handler */ _exit(1); } static unsigned long makearg(void) { unsigned int i; unsigned long val; val = arc4random(); i = arc4random() % 100; if (i < 20) val = val & 0xff; if (i >= 20 && i < 40) val = val & 0xffff; if (i >= 40 && i < 60) val = (unsigned long)(r) | (val & 0xffff); #if defined(__LP64__) if (i >= 60) { val = (val << 32) | arc4random(); if (i > 80) val = val & 0x00007fffffffffffUL; } #endif return(val); } static void * test(void *arg __unused) { FTS *fts; FTSENT *p; int ftsoptions; int i; char *args[5]; ftsoptions = FTS_PHYSICAL; args[0] = "/dev"; args[1] = "/proc"; args[2] = "/usr/compat/linux/proc"; args[3] = "."; args[4] = 0; for (;;) { for (i = 0; i < N; i++) r[i] = arc4random(); if ((fts = fts_open(args, ftsoptions, NULL)) == NULL) err(1, "fts_open"); i = 0; while ((p = fts_read(fts)) != NULL) { if (fd[i] > 0) close(fd[i]); if ((fd[i] = open(p->fts_path, O_RDWR)) == -1) if ((fd[i] = open(p->fts_path, O_WRONLY)) == -1) if ((fd[i] = open(p->fts_path, O_RDONLY)) == -1) continue; i++; i = i % nitems(fd); } if (fts_close(fts) == -1) if (errno != ENOTDIR) warn("fts_close()"); if (pipe(fds) == -1) err(1, "pipe()"); if (socketpair(PF_UNIX, SOCK_SEQPACKET, 0, socketpr) == -1) err(1, "socketpair()"); sleep(1); close(socketpr[0]); close(socketpr[1]); close(fds[0]); close(fds[1]); } return(0); } static void * calls(void *arg __unused) { unsigned long arg1, arg2, arg3, arg4, arg5, arg6, arg7; int i, kq, num; if ((kq = kqueue()) < 0) err(1, "kqueue()"); for (i = 0; i < 1000; i++) { if (i == 0) usleep(1000); num = syscallno; arg1 = makearg(); arg2 = makearg(); arg3 = makearg(); arg4 = makearg(); arg5 = makearg(); arg6 = makearg(); arg7 = makearg(); #if 0 fprintf(stderr, "%2d : syscall(%3d, %lx, %lx, %lx, %lx, %lx," " %lx, %lx)\n", i, num, arg1, arg2, arg3, arg4, arg5, arg6, arg7); #endif alarm(1); syscall(num, arg1, arg2, arg3, arg4, arg5, arg6, arg7); num = 0; } close(kq); return (0); } int main(void) { struct passwd *pw; time_t start; pthread_t rp, cp[THREADS]; int e, j, n; if ((pw = getpwnam("nobody")) == NULL) err(1, "no such user: nobody"); - if (setgroups(1, &pw->pw_gid) || + if (setgroups(0, NULL) || setegid(pw->pw_gid) || setgid(pw->pw_gid) || seteuid(pw->pw_uid) || setuid(pw->pw_uid)) err(1, "Can't drop privileges to \"nobody\""); endpwent(); signal(SIGALRM, hand); signal(SIGILL, hand); signal(SIGFPE, hand); signal(SIGSEGV, hand); signal(SIGBUS, hand); signal(SIGURG, hand); signal(SIGSYS, hand); signal(SIGTRAP, hand); syscallno = SYS_kevent; n = 0; start = time(NULL); while (time(NULL) - start < 120) { if (fork() == 0) { if ((e = pthread_create(&rp, NULL, test, NULL)) != 0) errc(1, e, "pthread_create"); usleep(1000); for (j = 0; j < THREADS; j++) { if ((e = pthread_create(&cp[j], NULL, calls, NULL)) != 0) errc(1, e, "pthread_create"); } for (j = 0; j < THREADS; j++) pthread_join(cp[j], NULL); if ((e = pthread_kill(rp, SIGINT)) != 0) errc(1, e, "pthread_kill"); _exit(0); } wait(NULL); if (n++ > 5000) break; } return (0); } diff --git a/tools/test/stress2/misc/killpg.sh b/tools/test/stress2/misc/killpg.sh index c6af55a3d593..ea99f5e0d0fd 100755 --- a/tools/test/stress2/misc/killpg.sh +++ b/tools/test/stress2/misc/killpg.sh @@ -1,155 +1,155 @@ #!/bin/sh # # Copyright (c) 2013 EMC Corp. # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # Regression test for r241859: # Return EPERM if processes were found but they were unable to be signaled. [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 . ../default.cfg here=`pwd` cd /tmp sed '1,/^EOF/d' < $here/$0 > killpg.c mycc -o killpg -Wall -Wextra killpg.c || exit 1 rm -f killpg.c /tmp/killpg rm -f /tmp/killpg exit 0 EOF #include #include #include #include #include #include #include #include #include #include static pid_t gid, pid; #define LOOPS 100 static void hand(int i __unused) { /* handler */ _exit(0); } static void nlooper(void) { int i; setproctitle("nlooper"); setpgrp(0, getpid()); for (i = 0; i < LOOPS; i++) { if ((pid = fork()) == 0) { signal(SIGINFO, hand); if (arc4random() % 100 < 10) usleep(arc4random() % 100); _exit(0); } wait(NULL); } _exit(0); } static void looper(void) { int i; setproctitle("looper"); setpgrp(0, getpid()); for (i = 0; i < LOOPS; i++) { if ((pid = fork()) == 0) { signal(SIGINFO, hand); if (arc4random() % 100 < 10) usleep(arc4random() % 100); _exit(0); } wait(NULL); } unlink("cont"); _exit(0); } static void killer(void) { struct passwd *pw; setproctitle("killer"); if ((pw = getpwnam("nobody")) == NULL) err(1, "no such user: nobody"); - if (setgroups(1, &pw->pw_gid) || + if (setgroups(0, NULL) || setegid(pw->pw_gid) || setgid(pw->pw_gid) || seteuid(pw->pw_uid) || setuid(pw->pw_uid)) err(1, "Can't drop privileges to \"nobody\""); endpwent(); if ((gid = fork()) == 0) nlooper(); /* nobody looper */ sleep(1); while (access("cont", R_OK) == 0) { if (killpg(gid, SIGINFO) == -1) { if (errno == EPERM) continue; warn("FAIL killpg"); } } _exit(0); } int main(void) { int fd; if ((fd = open("cont", O_RDWR | O_CREAT, 0666)) == -1) err(1, "creat"); close(fd); signal(SIGINFO, SIG_IGN); if ((gid = fork()) == 0) looper(); if (fork() == 0) killer(); wait(NULL); wait(NULL); return (0); } diff --git a/tools/test/stress2/misc/killpg2.sh b/tools/test/stress2/misc/killpg2.sh index 5e986f059637..cf186d686dfd 100755 --- a/tools/test/stress2/misc/killpg2.sh +++ b/tools/test/stress2/misc/killpg2.sh @@ -1,197 +1,197 @@ #!/bin/sh # # SPDX-License-Identifier: BSD-2-Clause # # Copyright (c) 2023 Peter Holm # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # killpg(2) version of reaper.sh. No problems seen. . ../default.cfg prog=$(basename "$0" .sh) cat > /tmp/$prog.c < #include #include #include #include #include #include #include #include #include #include static volatile u_int *share; #define CONT 0 #define GID 1 #define SYNC 2 #define MAXP 10000 static void hand(int i __unused) { _exit(0); } static void looper(void) { struct sigaction sa; time_t start; struct passwd *pw; pid_t pids[MAXP]; int i, parallel; setproctitle("looper"); sa.sa_handler = SIG_IGN; sigemptyset(&sa.sa_mask); sa.sa_flags = 0; if (sigaction(SIGUSR1, &sa, NULL) == -1) err(1, "sigaction"); if ((pw = getpwnam("TUSER")) == NULL) err(1, "no such user: TUSER"); - if (setgroups(1, &pw->pw_gid) || + if (setgroups(0, NULL) || setegid(pw->pw_gid) || setgid(pw->pw_gid) || seteuid(pw->pw_uid) || setuid(pw->pw_uid)) err(1, "Can't drop privileges to \"TUSER\""); endpwent(); setpgrp(0, 0); share[GID] = getpgrp(); share[SYNC] = 1; start = time(NULL); while (time(NULL) - start < 120) { parallel = arc4random() % MAXP + 1; for (i = 0; i < parallel; i++) { if ((pids[i] = fork()) == 0) { sa.sa_handler = hand; sigemptyset(&sa.sa_mask); sa.sa_flags = 0; if (sigaction(SIGUSR1, &sa, NULL) == -1) err(1, "sigaction"); setproctitle("child"); for (;;) pause(); _exit(0); /* never reached */ } if (pids[i] == -1) err(1, "fork()"); } for (i = 0; i < parallel; i++) { if (waitpid(pids[i], NULL, 0) != pids[i]) err(1, "waitpid(%d) in looper", pids[i]); } } _exit(0); } static void killer(void) { int e, gid; while (share[SYNC] == 0) ; gid = share[GID]; while (share[CONT] == 1) { usleep(arc4random() % 50000); gid = share[GID]; if (gid != 0) { e = 0; while (e == 0) { if (killpg(gid, SIGUSR1) == -1) { e = 1; if (errno != ESRCH) err(1, "pgkill(%d)", gid); } usleep(5000 + arc4random() % 5000); } } } _exit(0); } int main(void) { size_t len; time_t start; int lpid, kpid, s1, s2; len = PAGE_SIZE; if ((share = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_ANON | MAP_SHARED, -1, 0)) == MAP_FAILED) err(1, "mmap"); start = time(NULL); while (time(NULL) - start < 120) { share[CONT] = 1; share[GID] = 0; share[SYNC] = 0; if ((lpid = fork()) == 0) looper(); usleep(arc4random() % 100000); if ((kpid = fork()) == 0) killer(); if (waitpid(lpid, &s1, 0) != lpid) err(1, "waitpid looper"); usleep(arc4random() % 1000); share[CONT] = 0; waitpid(kpid, &s2, 0); } return (0); } EOF sed -i '' "s#TUSER#$testuser#" /tmp/$prog.c cc -o /tmp/$prog -Wall -Wextra -O0 /tmp/$prog.c || exit 1 rm /tmp/$prog.c n=1 start=`date +%s` while true; do /tmp/$prog for i in `jot 50`; do pgrep -q $prog || break sleep .5 done if pgrep -q $prog; then e=$((`date +%s` - start)) echo "Failed in loop #$n after $e seconds." pgrep "$prog|timeout" | xargs ps -jp pkill $prog rm -f /tmp/$prog exit 1 fi [ $((`date +%s` - start)) -ge 600 ] && break n=$((n + 1)) done rm /tmp/$prog exit 0 diff --git a/tools/test/stress2/misc/killpg3.sh b/tools/test/stress2/misc/killpg3.sh index 304b3e320f2f..4fcb4fa7a643 100755 --- a/tools/test/stress2/misc/killpg3.sh +++ b/tools/test/stress2/misc/killpg3.sh @@ -1,192 +1,192 @@ #!/bin/sh # # SPDX-License-Identifier: BSD-2-Clause # # Copyright (c) 2023 Peter Holm # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # killpg(2) version of reaper.sh. No problems seen. . ../default.cfg prog=$(basename "$0" .sh) cat > /tmp/$prog.c < #include #include #include #include #include #include #include #include #include #include #include static _Atomic(int) *share; #define GID 0 #define PARALLEL 10 #define RDY 1 #define MAXP 7000 static void hand(int i __unused) { _exit(0); } static void innerloop(int parallel) { pid_t pids[MAXP]; struct sigaction sa; int i; usleep(1000); for (i = 0; i < parallel; i++) { if ((pids[i] = fork()) == 0) { sa.sa_handler = hand; sigemptyset(&sa.sa_mask); sa.sa_flags = 0; if (sigaction(SIGUSR1, &sa, NULL) == -1) err(1, "sigaction"); atomic_fetch_add(&share[RDY], 1); setproctitle("child"); for (;;) pause(); _exit(0); /* never reached */ } if (pids[i] == -1) err(1, "fork()"); } for (i = 0; i < parallel; i++) { if (waitpid(pids[i], NULL, 0) != pids[i]) err(1, "waitpid(%d) in looper", pids[i]); } _exit(0); } static void looper(void) { struct sigaction sa; struct passwd *pw; pid_t pids[MAXP]; int i, parallel; setproctitle("looper"); sa.sa_handler = SIG_IGN; sigemptyset(&sa.sa_mask); sa.sa_flags = 0; if (sigaction(SIGUSR1, &sa, NULL) == -1) err(1, "sigaction"); if ((pw = getpwnam("TUSER")) == NULL) err(1, "no such user: TUSER"); - if (setgroups(1, &pw->pw_gid) || + if (setgroups(0, NULL) || setegid(pw->pw_gid) || setgid(pw->pw_gid) || seteuid(pw->pw_uid) || setuid(pw->pw_uid)) err(1, "Can't drop privileges to \"TUSER\""); endpwent(); setpgrp(0, 0); share[GID] = getpgrp(); parallel = arc4random() % MAXP + 1; parallel = parallel / PARALLEL * PARALLEL; for (i = 0; i < PARALLEL; i++) { if ((pids[i] = fork()) == 0) innerloop(parallel / PARALLEL); } while (atomic_load(&share[RDY]) != parallel) usleep(10000); if (killpg(share[GID], SIGUSR1) == -1) err(1, "pgkill(%d)", share[GID]); for (i = 0; i < 4; i++) { if (waitpid(pids[i], NULL, 0) != pids[i]) err(1, "waitpid(%d) in looper", pids[i]); } _exit(0); } int main(void) { size_t len; time_t start; int lpid, s1; len = PAGE_SIZE; if ((share = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_ANON | MAP_SHARED, -1, 0)) == MAP_FAILED) err(1, "mmap"); start = time(NULL); while (time(NULL) - start < 120) { share[GID] = 0; share[RDY] = 0; if ((lpid = fork()) == 0) looper(); if (waitpid(lpid, &s1, 0) != lpid) err(1, "waitpid looper"); } return (0); } EOF sed -i '' "s#TUSER#$testuser#" /tmp/$prog.c mycc -o /tmp/$prog -Wall -Wextra -O0 /tmp/$prog.c || exit 1 rm /tmp/$prog.c export MAXSWAPPCT=70 n=1 start=`date +%s` while true; do ../testcases/swap/swap -t 2m -i 20 > /dev/null & /tmp/$prog & pid=$! st=`date +%s` while kill -0 $pid > /dev/null 2>&1; do e=$((`date +%s` - st)) if [ $e -ge 120 ]; then while pgrep -q swap; do pkill swap; done fi if [ $e -ge 600 ]; then echo "Failed in loop #$n after $e seconds." ps -jU$testuser | head -20 kill $pid pkill -U$testuser wait rm -f /tmp/$prog exit 1 fi done wait [ $((`date +%s` - start)) -ge 300 ] && break n=$((n + 1)) done rm /tmp/$prog exit 0 diff --git a/tools/test/stress2/misc/maxproc.sh b/tools/test/stress2/misc/maxproc.sh index 0574def8a605..3241e275375e 100755 --- a/tools/test/stress2/misc/maxproc.sh +++ b/tools/test/stress2/misc/maxproc.sh @@ -1,167 +1,167 @@ #!/bin/sh # # Copyright (c) 2014 EMC Corp. # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 # Test that a non root user can at most have maxproc - 10 processes. . ../default.cfg [ `sysctl -n kern.maxproc` -gt 37028 ] && exit 0 # Excessive run time here=`pwd` cd /tmp sed '1,/^EOF/d' < $here/$0 > maxproc.c mycc -o maxproc -Wall -Wextra maxproc.c -lkvm || exit 1 rm -f maxproc.c cd $here /tmp/maxproc rm -f /tmp/maxproc exit EOF #include #include #include #include #include #include #include #include #include #include enum { NL_NPROCS, NL_MAXPROC, NL_MARKER }; static struct { int order; const char *name; } namelist[] = { { NL_NPROCS, "_nprocs" }, { NL_MAXPROC, "_maxproc" }, { NL_MARKER, "" }, }; #define NNAMES (sizeof(namelist) / sizeof(*namelist)) #define MULTIUSERFUZZ 5 static struct nlist nl[NNAMES]; static void t2(void) { pid_t p; for (;;) { if ((p = fork()) == 0) { sleep(2); _exit(0); } if (p == -1) break; } } static void t1(int priv) { pid_t p; struct passwd *pw; if ((p = fork()) == 0) { if ((pw = getpwnam("nobody")) == NULL) err(1, "no such user: nobody"); if (priv == 0) { - if (setgroups(1, &pw->pw_gid) || + if (setgroups(0, NULL) || setegid(pw->pw_gid) || setgid(pw->pw_gid) || seteuid(pw->pw_uid) || setuid(pw->pw_uid)) err(1, "Can't drop privileges to \"nobody\""); } endpwent(); t2(); _exit(0); } waitpid(p, NULL, 0); } int getprocs(void) { kvm_t *kd; int i, nprocs, maxproc; char buf[_POSIX2_LINE_MAX]; char *nlistf, *memf; nlistf = memf = NULL; for (i = 0; i < (int)NNAMES; i++) nl[namelist[i].order].n_name = strdup(namelist[i].name); if ((kd = kvm_openfiles(nlistf, memf, NULL, O_RDONLY, buf)) == NULL) errx(1, "kvm_openfile(%s, %s): %s", nlistf, memf, buf); if (kvm_nlist(kd, nl) == -1) errx(1, "kvm_nlist: %s", kvm_geterr(kd)); if (kvm_read(kd, nl[NL_NPROCS].n_value, &nprocs, sizeof(nprocs)) != sizeof(nprocs)) errx(1, "kvm_read(): %s", kvm_geterr(kd)); if (kvm_read(kd, nl[NL_MAXPROC].n_value, &maxproc, sizeof(maxproc)) != sizeof(maxproc)) errx(1, "kvm_read(): %s", kvm_geterr(kd)); kvm_close(kd); return (maxproc - nprocs - 1); } int main(void) { int i, n; alarm(1200); n = getprocs(); for (i = 0; i < n / 10 * 8; i++) { if (fork() == 0) { sleep(2); _exit(0); } } t1(0); n = getprocs(); if (n < 10 - MULTIUSERFUZZ) errx(1, "FAIL: nprocs = %d\n", n); return (0); } diff --git a/tools/test/stress2/misc/mlockall3.sh b/tools/test/stress2/misc/mlockall3.sh index 0ff1e24eaa7f..aa53e75166a5 100755 --- a/tools/test/stress2/misc/mlockall3.sh +++ b/tools/test/stress2/misc/mlockall3.sh @@ -1,167 +1,167 @@ #!/bin/sh # # Copyright (c) 2013 Peter Holm # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # mlockall(2) test scenario. # "panic: vm_page_unwire: page xxx's wire count is zero" seen. # http://people.freebsd.org/~pho/stress/log/mlockall.txt [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 . ../default.cfg dir=/tmp odir=`pwd` cd $dir sed '1,/^EOF/d' < $odir/$0 > $dir/mlockall3.c mycc -o mlockall3 -Wall -Wextra mlockall3.c -lpthread || exit 1 rm -f mlockall3.c cd $odir /tmp/mlockall3 killall mlockall3 > /dev/null 2>&1 rm -f /tmp/mlockall3 exit EOF #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define N (128 * 1024 / (int)sizeof(u_int32_t)) u_int32_t r[N]; static void hand(int i __unused) { /* handler */ _exit(1); } unsigned long makearg(void) { unsigned int i; unsigned long val; val = arc4random(); i = arc4random() % 100; if (i < 20) val = val & 0xff; if (i >= 20 && i < 40) val = val & 0xffff; if (i >= 40 && i < 60) val = (unsigned long)(r) | (val & 0xffff); #if defined(__LP64__) if (i >= 60) { val = (val << 32) | arc4random(); if (i > 80) val = val & 0x00007fffffffffffUL; } #endif return(val); } void * calls(void *arg __unused) { int i; unsigned long arg1, arg2, arg3; usleep(1000); for (i = 0; i < 500; i++) { arg1 = makearg(); arg2 = makearg(); arg3 = makearg(); alarm(1); syscall(SYS_mlockall, arg1, arg2, arg3); } return (0); } int main(void) { struct passwd *pw; pid_t pid; pthread_t cp[50]; int e, i, j; if ((pw = getpwnam("nobody")) == NULL) err(1, "no such user: nobody"); - if (setgroups(1, &pw->pw_gid) || + if (setgroups(0, NULL) || setegid(pw->pw_gid) || setgid(pw->pw_gid) || seteuid(pw->pw_uid) || setuid(pw->pw_uid)) err(1, "Can't drop privileges to \"nobody\""); endpwent(); signal(SIGALRM, hand); signal(SIGILL, hand); signal(SIGFPE, hand); signal(SIGSEGV, hand); signal(SIGBUS, hand); signal(SIGURG, hand); signal(SIGSYS, hand); signal(SIGTRAP, hand); alarm(180); for (i = 0; i < 8000; i++) { if ((pid = fork()) == 0) { for (j = 0; j < N; j++) r[j] = arc4random(); for (j = 0; j < 50; j++) if ((e = pthread_create(&cp[j], NULL, calls, NULL)) != 0) errc(1, e, "pthread_create"); for (j = 0; j < 50; j++) pthread_join(cp[j], NULL); _exit(0); } if (pid == -1) err(1, "fork()"); wait(NULL); } return (0); } diff --git a/tools/test/stress2/misc/mlockall7.sh b/tools/test/stress2/misc/mlockall7.sh index 987e312f19e7..5a927043cb56 100755 --- a/tools/test/stress2/misc/mlockall7.sh +++ b/tools/test/stress2/misc/mlockall7.sh @@ -1,262 +1,262 @@ #!/bin/sh # # Copyright (c) 2014 EMC Corp. # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # Variation of mmap18.sh. # "panic: vm_page_unwire: page 0xfffff81038d721f0's wire count is zero" seen: # https://people.freebsd.org/~pho/stress/log/mlockall7.txt # Fixed by r328880 [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 . ../default.cfg here=`pwd` cd /tmp sed '1,/^EOF/d' < $here/$0 > mlockall7.c mycc -o mlockall7 -Wall -Wextra -O2 mlockall7.c -lpthread || exit 1 rm -f mlockall7.c /tmp/mlockall7 `[ $# -eq 0 ] && echo 1 || echo $1` || s=1 sleep 2 rm -f /tmp/mlockall7 /tmp/mlockall7.core exit $s EOF #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define N 4096 #define PARALLEL 50 #define RUNTIME 180 static u_int32_t r[N]; static void *p; static unsigned long makearg(void) { unsigned long val; unsigned int i; val = arc4random(); i = arc4random() % 100; if (i < 20) val = val & 0xff; if (i >= 20 && i < 40) val = val & 0xffff; if (i >= 40 && i < 60) val = (unsigned long)(r) | (val & 0xffff); #if defined(__LP64__) if (i >= 60) { val = (val << 32) | arc4random(); if (i > 80) val = val & 0x00007fffffffffffUL; } #endif return (val); } static void * tmmap(void *arg __unused) { size_t len; time_t start; pthread_set_name_np(pthread_self(), __func__); len = 128LL * 1024 * 1024; start = time(NULL); while (time(NULL) - start < 60) { if ((p = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_ANON, -1, 0)) != MAP_FAILED) { usleep(100); munmap(p, len); } } return (NULL); } static void * tmlockall(void *arg __unused) { time_t start; int flags; pthread_set_name_np(pthread_self(), __func__); start = time(NULL); while (time(NULL) - start < 60) { flags = makearg() & 0xff; mlockall(flags); usleep(100); munlockall(); usleep(1000); } return (NULL); } static void test(void) { pthread_t tid[2]; time_t start; int i, rc; if ((rc = pthread_create(&tid[0], NULL, tmmap, NULL)) != 0) errc(1, rc, "tmmap()"); if ((rc = pthread_create(&tid[1], NULL, tmlockall, NULL)) != 0) errc(1, rc, "tmlock()"); start = time(NULL); while (time(NULL) - start < 60) { if (fork() == 0) { usleep(10000); _exit(0); } wait(NULL); } for (i = 0; i < 2; i++) if ((rc = pthread_join(tid[i], NULL)) != 0) errc(1, rc, "pthread_join"); _exit(0); } int testing(unsigned long maxl) { struct passwd *pw; struct rlimit rl; rlim_t maxlock; time_t start; int i; maxlock = maxl; if ((pw = getpwnam("nobody")) == NULL) err(1, "failed to resolve nobody"); - if (setgroups(1, &pw->pw_gid) || + if (setgroups(0, NULL) || setegid(pw->pw_gid) || setgid(pw->pw_gid) || seteuid(pw->pw_uid) || setuid(pw->pw_uid)) err(1, "Can't drop privileges to \"nobody\""); endpwent(); rl.rlim_max = rl.rlim_cur = 0; if (setrlimit(RLIMIT_CORE, &rl) == -1) warn("setrlimit"); if (getrlimit(RLIMIT_MEMLOCK, &rl) == -1) warn("getrlimit"); if (maxlock <= 0) errx(1, "Argument is %jd", maxlock); maxlock = (maxlock / 10 * 8) / PARALLEL * PAGE_SIZE; if (maxlock < rl.rlim_cur) { rl.rlim_max = rl.rlim_cur = maxlock; if (setrlimit(RLIMIT_MEMLOCK, &rl) == -1) warn("setrlimit"); } for (i = 0; i < N; i++) r[i] = arc4random(); start = time(NULL); while (time(NULL) - start < RUNTIME) { for (i = 0; i < PARALLEL; i++) { if (fork() == 0) test(); } for (i = 0; i < PARALLEL; i++) wait(NULL); } _exit(0); } int main(int argc, char *argv[]) { pid_t pid; size_t len; int i, loops, s, status; unsigned long max_wired; unsigned int wire_count, wire_count_old; s = 0; if (argc != 2) errx(1, "Usage: %s ", argv[0]); loops = atoi(argv[1]); len = sizeof(max_wired); if (sysctlbyname("vm.max_user_wired", &max_wired, &len, NULL, 0) != 0) err(1, "vm.max_user_wired"); len = sizeof(wire_count); if (sysctlbyname("vm.stats.vm.v_user_wire_count", &wire_count, &len, NULL, 0) != 0) err(1, "vm.stats.vm.v_user_wire_count"); for (i = 0; i < loops; i++) { wire_count_old = wire_count; if ((pid = fork()) == 0) testing(max_wired); if (waitpid(pid, &status, 0) != pid) err(1, "waitpid(%d)", pid); if (status != 0) errx(1, "Exit status %d from pid %d\n", status, pid); len = sizeof(wire_count); if (sysctlbyname("vm.stats.vm.v_user_wire_count", &wire_count, &len, NULL, 0) != 0) err(1, "vm.stats.vm.v_user_wire_count"); fprintf(stderr, "vm.stats.vm.v_user_wire_count was %d, is %d. %d\n", wire_count_old, wire_count, wire_count - wire_count_old); } return (s); } diff --git a/tools/test/stress2/misc/mountu.sh b/tools/test/stress2/misc/mountu.sh index abd3c744d160..95043e634ef1 100755 --- a/tools/test/stress2/misc/mountu.sh +++ b/tools/test/stress2/misc/mountu.sh @@ -1,288 +1,288 @@ #!/bin/sh # # SPDX-License-Identifier: BSD-2-Clause # # Copyright (c) 2012 Peter Holm # Copyright (c) 2019 Dell EMC Isilon # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # Change mount point from rw to ro with a file mapped rw # Currently fails for NFS # Page fault seen: # https://people.freebsd.org/~pho/stress/log/mountu.txt # Fixed by: r285039. [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 . ../default.cfg here=`pwd` cd /tmp sed '1,/^EOF/d' < $here/$0 > mountu.c mycc -o mountu -Wall -Wextra -O2 mountu.c || exit 1 rm -f mountu.c pstat() { local pid pid=`ps ax | grep -v grep | grep /tmp/mountu | awk '{print $1}'` [ -n "$pid" ] && procstat -v $pid } ck() { if mount | grep $mntpoint | grep -q "read-only"; then if pstat $!| awk "\$2 == \"$map\"" | grep -q " rw-"; then echo echo "$1 difference" mount | grep $mntpoint printf "RW mount mapping and RO mount mapping:\n%s\n" "$r" pstat $! | awk "\$2 == \"$map\"" status=$((status + 1)) fi else echo "$1 mount point RO did not succeed" mount | grep $mntpoint status=$((status + 1)) fi } status=0 file=$mntpoint/mountu.sh.file mapfile=/tmp/mountu.sh.map mount | grep -q "$mntpoint " && umount $mntpoint mdconfig -l | grep -q $mdstart && mdconfig -d -u $mdstart mdconfig -a -t swap -s 100m -u $mdstart gpart create -s bsd md$mdstart > /dev/null gpart add -t freebsd-ufs md$mdstart > /dev/null part=a newfs $newfs_flags md${mdstart}$part > /dev/null mount /dev/md${mdstart}$part $mntpoint chmod 777 $mntpoint # ufs exec 5>$mapfile /tmp/mountu UFS $file & pid=$! sleep 1 map=`cat $mapfile`; rm $mapfile; exec 5>&- r=`pstat $! | awk "\\$2 == \"$map\""` mount -u -o ro $mntpoint 2>/dev/null || mount -fu -o ro $mntpoint ck UFS mount -u -o rw $mntpoint rm -f $file wait $pid s=$? [ $s -ne 139 ] && { echo "UFS exit status is $s"; status=1; } while mount | grep -q "$mntpoint "; do umount $mntpoint || sleep 1 done mdconfig -d -u $mdstart # nfs if ping -c 2 `echo $nfs_export | sed 's/:.*//'` > /dev/null 2>&1; then mount -t nfs -o tcp -o retrycnt=3 -o intr,soft -o rw $nfs_export \ $mntpoint sleep .2 rm -f $file /tmp/mountu NFS $file & pid=$! sleep 1 r=`pstat $! | awk "\\$2 == \"$map\""` mount -u -o ro $mntpoint 2>/dev/null || mount -fu -o ro $mntpoint 2>/dev/null ck NFS wait $pid s=$? [ $s -ne 139 ] && { echo "NFS exit status is $s"; status=1; } mount -u -o rw $mntpoint 2>/dev/null sleep .2 [ -f $file ] && rm -f $file umount $mntpoint || umount $mntpoint fi # msdos if [ -x /sbin/mount_msdosfs ]; then mdconfig -a -t swap -s 100m -u $mdstart gpart create -s bsd md$mdstart > /dev/null gpart add -t freebsd-ufs md$mdstart > /dev/null part=a newfs_msdos -F 16 -b 8192 /dev/md${mdstart}$part > /dev/null 2>&1 mount_msdosfs -m 777 /dev/md${mdstart}$part $mntpoint /tmp/mountu MSDOS $file & pid=$! sleep 1 r=`pstat $! | awk "\\$2 == \"$map\""` mount -u -o ro $mntpoint 2>/dev/null || mount -fu -o ro $mntpoint ck MSDOS wait $pid s=$? [ $s -ne 139 ] && { echo "MSDOS exit status is $s"; status=1; } mount -u -o rw $mntpoint rm -f $file while mount | grep -q "$mntpoint "; do umount $mntpoint || sleep 1 done mdconfig -d -u $mdstart fi # tmpfs mount -t tmpfs null $mntpoint chmod 777 $mntpoint /tmp/mountu TMPFS $file & pid=$! sleep 1 r=`pstat $! | awk "\\$2 == \"$map\""` mount -u -o ro $mntpoint 2>/dev/null || mount -fu -o ro $mntpoint ck TMPFS sleep 1 mount -u -o rw $mntpoint rm -f $file wait $pid s=$? [ $s -ne 139 ] && { echo "TMPFS exit status is $s"; status=1; } while mount | grep -q "$mntpoint "; do umount $mntpoint || sleep 1 done rm -f /tmp/mountu exit 0 EOF /* kib@ noted: UFS/NFS/msdosfs reclaim vnode on rw->ro forced remount, and change the type of the underying object to OBJT_DEAD, but leave the pages on the object queue and installed in the page tables. Applications can read/write already mapped pages, but cannot page in new pages, cannot observe possible further modifications to already mapped pages (if ro->rw remount happen later), and their updates to pages are not flushed to file. It is impossible to mimic this behaviour for tmpfs. */ #include #include #include #include #include #include #include #include #include #include #include #include #define STARTADDR 0x0U #define ADRSPACE 0x0640000U static void sighandler(int signo, siginfo_t *si, void *uc1) { ucontext_t *uc; uc = uc1; printf("SIG%s at %p, addr %p\n", sys_signame[signo], si->si_addr, #if defined(__i386__) (void *)uc->uc_mcontext.mc_eip); #else (void *)uc->uc_mcontext.mc_rip); #endif exit(1); } int main(int argc __unused, char **argv) { struct passwd *pw; struct sigaction sa; void *p; size_t len; int fd; char *name, *path; volatile char *c; memset(&sa, 0, sizeof(sa)); sa.sa_sigaction = sighandler; sa.sa_flags = SA_SIGINFO; if (sigaction(SIGSEGV, &sa, NULL) == -1) err(1, "sigaction(SIGSEGV)"); if (sigaction(SIGBUS, &sa, NULL) == -1) err(1, "sigaction(SIGBUS)"); if ((pw = getpwnam("nobody")) == NULL) err(1, "no such user: nobody"); - if (setgroups(1, &pw->pw_gid) || + if (setgroups(0, NULL) || setegid(pw->pw_gid) || setgid(pw->pw_gid) || seteuid(pw->pw_uid) || setuid(pw->pw_uid)) err(1, "Can't drop privileges to \"nobody\""); endpwent(); p = (void *)STARTADDR; len = ADRSPACE; name = argv[1]; path = argv[2]; if ((fd = open(path, O_CREAT | O_TRUNC | O_RDWR, 0622)) == -1) err(1,"open(%s)", path); if (ftruncate(fd, len) == -1) err(1, "ftruncate"); if ((p = mmap(p, len, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0)) == MAP_FAILED) { if (errno == ENOMEM) { warn("mmap()"); return (1); } err(1, "mmap(1)"); } dprintf(5, "%p\n", p); for (c = p; (void *)c < p + len; c += PAGE_SIZE) { *c = 1; } close(fd); sleep(5); fprintf(stderr, "%s: Late read start.\n", name); for (c = p; (void *)c < p + len; c += PAGE_SIZE) { *c; } fprintf(stderr, "%s: Late read complete.\n", name); fprintf(stderr, "%s: Late write start.\n", name); for (c = p; (void *)c < p + len; c += PAGE_SIZE) { *c = 1; } fprintf(stderr, "%s: Late write complete.\n", name); return (0); } diff --git a/tools/test/stress2/misc/msync.sh b/tools/test/stress2/misc/msync.sh index 326c7e723774..df05875afb45 100755 --- a/tools/test/stress2/misc/msync.sh +++ b/tools/test/stress2/misc/msync.sh @@ -1,201 +1,201 @@ #!/bin/sh # # Copyright (c) 2013 Peter Holm # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # msync(2) / mlockall(2) test scenario. # "panic: vm_fault_copy_wired: page missing" seen. # http://people.freebsd.org/~pho/stress/log/msync.txt # Fixed in r253189. [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 . ../default.cfg dir=/tmp odir=`pwd` cd $dir sed '1,/^EOF/d' < $odir/$0 > $dir/msync.c mycc -o msync -Wall -Wextra msync.c -lpthread || exit 1 rm -f msync.c cd $odir /tmp/msync & sleep 180 while pkill -9 msync; do :; done wait rm -f /tmp/msync exit EOF #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include int syscallno = SYS_msync; #define N (128 * 1024 / (int)sizeof(u_int32_t)) u_int32_t r[N]; static void hand(int i __unused) { /* handler */ _exit(1); } unsigned long makearg(void) { unsigned int i; unsigned long val; val = arc4random(); i = arc4random() % 100; if (i < 20) val = val & 0xff; if (i >= 20 && i < 40) val = val & 0xffff; if (i >= 40 && i < 60) val = (unsigned long)(r) | (val & 0xffff); #if defined(__LP64__) if (i >= 60) { val = (val << 32) | arc4random(); if (i > 80) val = val & 0x00007fffffffffffUL; } #endif return(val); } void * calls(void *arg __unused) { int i, num; unsigned long arg1, arg2, arg3; usleep(1000); num = syscallno; for (i = 0; i < 500; i++) { arg1 = makearg(); arg2 = makearg(); #if 0 arg3 = makearg(); arg3 = arg3 & ~MS_INVALIDATE; /* No problem seen */ #else arg3 = MS_INVALIDATE; /* panic */ #endif #if 0 fprintf(stderr, "%2d : syscall(%3d, 0x%lx, 0x%lx, 0x%lx)\n", i, num, arg1, arg2, arg3); usleep(50000); #endif alarm(1); syscall(num, arg1, arg2, arg3); num = 0; } return (0); } void wd(void) { int i; if (mlockall(MCL_CURRENT | MCL_FUTURE) != 0) err(1, "mlockall failed"); for (i = 0; i < 800; i++) { if (fork() == 0) { usleep(20000); _exit(0); } wait(NULL); usleep(100000); } _exit(0); } int main(void) { struct passwd *pw; pthread_t cp[50]; int e, i, j; if (fork() == 0) wd(); if ((pw = getpwnam("nobody")) == NULL) err(1, "no such user: nobody"); - if (setgroups(1, &pw->pw_gid) || + if (setgroups(0, NULL) || setegid(pw->pw_gid) || setgid(pw->pw_gid) || seteuid(pw->pw_uid) || setuid(pw->pw_uid)) err(1, "Can't drop privileges to \"nobody\""); endpwent(); signal(SIGALRM, hand); signal(SIGILL, hand); signal(SIGFPE, hand); signal(SIGSEGV, hand); signal(SIGBUS, hand); signal(SIGURG, hand); signal(SIGSYS, hand); signal(SIGTRAP, hand); alarm(180); for (i = 0; i < 8000; i++) { if (fork() == 0) { for (j = 0; j < N; j++) r[j] = arc4random(); for (j = 0; j < 50; j++) if ((e = pthread_create(&cp[j], NULL, calls, NULL)) != 0) errc(1, e, "pthread_create"); for (j = 0; j < 50; j++) pthread_join(cp[j], NULL); _exit(0); } wait(NULL); } return (0); } diff --git a/tools/test/stress2/misc/pread.sh b/tools/test/stress2/misc/pread.sh index 24ee2efb696a..985d3f643df1 100755 --- a/tools/test/stress2/misc/pread.sh +++ b/tools/test/stress2/misc/pread.sh @@ -1,189 +1,189 @@ #!/bin/sh # # Copyright (c) 2011 Peter Holm # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # pread(2) fuzzing inspired by the iknowthis test suite # by Tavis Ormandy # Fixed in r227527. [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 . ../default.cfg here=`pwd` cd /tmp sed '1,/^EOF/d' < $here/$0 > pread.c mycc -o pread -Wall -Wextra pread.c rm -f pread.c mount | grep $mntpoint | grep -q /dev/md && umount -f $mntpoint mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart mount -t tmpfs tmpfs $mntpoint cp -a /usr/include $mntpoint echo "Testing tmpfs(4)" /tmp/pread $mntpoint while mount | grep -q "on $mntpoint "; do umount $mntpoint || sleep 1 done echo "Testing fdescfs(4)" mount -t fdescfs null /dev/fd for i in `jot 100`; do /tmp/pread /dev/fd done while mount | grep -q "on /dev/fd "; do umount /dev/fd || sleep 1 done echo "Testing procfs(4)" mount -t procfs procfs $mntpoint /tmp/pread $mntpoint while mount | grep -q "on $mntpoint "; do umount $mntpoint || sleep 1 done mdconfig -a -t swap -s 1g -u $mdstart || exit 1 newfs $newfs_flags md$mdstart > /dev/null mount /dev/md$mdstart $mntpoint cp -a /usr/include $mntpoint echo "Testing FFS" /tmp/pread $mntpoint while mount | grep -q "on $mntpoint "; do umount $mntpoint || sleep 1 done mdconfig -d -u $mdstart mount -t nullfs /bin $mntpoint echo "Testing nullfs(4)" /tmp/pread $mntpoint while mount | grep -q "on $mntpoint "; do umount $mntpoint || sleep 1 done echo "Testing procfs(4)" mount -t procfs procfs $mntpoint /tmp/pread $mntpoint while mount | grep -q "on $mntpoint "; do umount $mntpoint || sleep 1 done echo "Testing devfs(8)" mount -t devfs devfs $mntpoint /tmp/pread $mntpoint while mount | grep -q "on $mntpoint "; do umount $mntpoint || sleep 1 done rm -f /tmp/pread exit 0 EOF #include #include #include #include #include #include #include #include #include #include #include #include #include #include static void hand(int i __unused) { /* handler */ _exit(1); } int test(char *path) { FTS *fts; FTSENT *p; int ftsoptions; char *args[2]; int buf[64], fd; signal(SIGSEGV, hand); signal(SIGABRT, hand); ftsoptions = FTS_PHYSICAL; args[0] = path; args[1] = 0; if ((fts = fts_open(args, ftsoptions, NULL)) == NULL) err(1, "fts_open"); while ((p = fts_read(fts)) != NULL) { if ((fd = open(p->fts_path, O_RDONLY)) == -1) { if (errno != EACCES && errno != ENXIO) warn("open(%s)", p->fts_path); continue; } alarm(1); pread(fd, (void *)0xdeadc0de, 0x7ffffff, 0xffffffff); pread(fd, buf, 0x7ffffff, 0xffffffff); pread(fd, buf, sizeof(buf), 0xffffffff); pread(fd, buf, sizeof(buf), 0); close(fd); } fts_close(fts); exit(0); } int main(int argc __unused, char **argv) { int i; struct passwd *pw; if ((pw = getpwnam("nobody")) == NULL) err(1, "no such user: nobody"); - if (setgroups(1, &pw->pw_gid) || + if (setgroups(0, NULL) || setegid(pw->pw_gid) || setgid(pw->pw_gid) || seteuid(pw->pw_uid) || setuid(pw->pw_uid)) err(1, "Can't drop privileges to \"nobody\""); endpwent(); if (daemon(0, 0) == -1) err(1, "daemon()"); for (i = 0; i < 10; i++) { if (fork() == 0) test(argv[1]); wait(NULL); } return (0); } diff --git a/tools/test/stress2/misc/sched.sh b/tools/test/stress2/misc/sched.sh index 1a1db70eb38a..8b33d7b16094 100755 --- a/tools/test/stress2/misc/sched.sh +++ b/tools/test/stress2/misc/sched.sh @@ -1,160 +1,160 @@ #!/bin/sh # # Copyright (c) 2014 EMC Corp. # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 # Show scheduler fairness for ULE vs. 4BSD. . ../default.cfg here=`pwd` cd /tmp sed '1,/^EOF/d' < $here/$0 > sched.c mycc -o sched -Wall -Wextra -O0 sched.c || exit 1 rm -f sched.c cd $here mount | grep $mntpoint | grep -q /dev/md && umount -f $mntpoint mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart mdconfig -a -t swap -s 1g -u $mdstart || exit 1 newfs $newfs_flags md$mdstart > /dev/null mount /dev/md$mdstart $mntpoint chmod 777 $mntpoint cpus=`sysctl hw.ncpu | sed 's/.*: //'` uname -v (cd $mntpoint; /tmp/sched $((cpus + 1))) > /dev/null 2>&1 & sleep 30 export LANG=C top -U nobody -d 1 | grep nobody | awk '{print $11}' | sed 's/%//' | ministat -A -w 73 | tail -1 | awk '{if ($NF > 1.0) exit 1}' || { echo Broken; top -U nobody -d 1 | grep nobody; } killall sched wait for i in `jot 3`; do echo "run #$i" (cd $mntpoint; /tmp/sched $((cpus + 1))) done while mount | grep $mntpoint | grep -q /dev/md; do umount $mntpoint || sleep 1 done rm -f /tmp/sched mdconfig -d -u $mdstart exit EOF #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define N 100 * 1024 * 1024 double r; int parallel; void work(void) { struct passwd *pw; struct timespec start, finish; double d1, d2; int i, j; volatile char *cp; while (access("rendezvous", R_OK) != 0) usleep(1); if ((pw = getpwnam("nobody")) == NULL) err(1, "no such user: nobody"); - if (setgroups(1, &pw->pw_gid) || + if (setgroups(0, NULL) || setegid(pw->pw_gid) || setgid(pw->pw_gid) || seteuid(pw->pw_uid) || setuid(pw->pw_uid)) err(1, "Can't drop privileges to \"nobody\""); endpwent(); d1 = d2 = 0; cp = malloc(N); clock_gettime(CLOCK_REALTIME_PRECISE, &start); for (i = 0; i < 1; i++) { for (j = 0; j < INT_MAX; j++) { d1 = d1 + 1.0 / j; d2 = d1 + 0.8 / j; if (j % 1000 == 0) { cp[arc4random() % N] = j % 255; } } } r = d1 + d2; clock_gettime(CLOCK_REALTIME_PRECISE, &finish); timespecsub(&finish, &start, &finish); #if defined(DEBUG) fprintf(stderr, "Elapsed time for pid %d: %.4f\n", getpid(), finish.tv_sec + (double)finish.tv_nsec / 1e9); #endif _exit(0); } int main(int argc, char **argv) { int fd, i; if (argc == 2) parallel = atoi(argv[1]); else errx(1, "Usage: %s ", argv[0]); for (i = 0; i < parallel; i++) { if (fork() == 0) work(); } if ((fd = open("rendezvous", O_CREAT, 0644)) == -1) err(1, "open()"); close(fd); for (i = 0; i < parallel; i++) wait(NULL); return (0); } diff --git a/tools/test/stress2/misc/sigreturn3.sh b/tools/test/stress2/misc/sigreturn3.sh index a2d865b73847..6795c4fd0846 100755 --- a/tools/test/stress2/misc/sigreturn3.sh +++ b/tools/test/stress2/misc/sigreturn3.sh @@ -1,181 +1,181 @@ #!/bin/sh # # SPDX-License-Identifier: BSD-2-Clause # # Copyright (c) 2022 Peter Holm # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # Fatal trap -4186856: UNKNOWN while in kernel mode # cpuid = 1; apic id = 01 # error code = 0xfbafcf8c # instruction pointer = 0x79e4:0x4 # stack pointer = 0x28:0xffc0aff0 # frame pointer = 0x28:0x204620d4 # code segment = base 0x0, limit 0x0, type 0x0 # = DPL 0, pres 0, def32 0, gran 0 # processor eflags = trace trap, at 0x3b/frame 0xffc0340c # KDB: enter: panic # [ thread pid 15631 tid 114622 ] # Stopped at kdb_enter+0x34: movl $0,kdb_why # db> [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 prog=sigreturn3 cat > /tmp/$prog.c < #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define N 4096 #define RUNTIME 120 #define THREADS 1 static uint32_t r[N]; static void hand(int i __unused) { /* handler */ exit(1); } static void * churn(void *arg __unused) { time_t start; pthread_set_name_np(pthread_self(), __func__); start = time(NULL); while (time(NULL) - start < 10) { arc4random_buf(r, sizeof(r)); usleep(100); } return(NULL); } static void * calls(void *arg __unused) { time_t start; start = time(NULL); while (time(NULL) - start < 10) { arc4random_buf(r, sizeof(r)); alarm(1); syscall(SYS_sigreturn, r); } return (NULL); } int main(int argc, char **argv) { struct passwd *pw; struct rlimit limit; pid_t pid; pthread_t rp, cp[THREADS]; time_t start; int e, j; if ((pw = getpwnam("nobody")) == NULL) err(1, "failed to resolve nobody"); if (getenv("USE_ROOT") && argc == 2) fprintf(stderr, "Running syscall4 as root for %s.\n", argv[1]); else { - if (setgroups(1, &pw->pw_gid) || + if (setgroups(0, NULL) || setegid(pw->pw_gid) || setgid(pw->pw_gid) || seteuid(pw->pw_uid) || setuid(pw->pw_uid)) err(1, "Can't drop privileges to \"nobody\""); endpwent(); } limit.rlim_cur = limit.rlim_max = 1000; #if defined(RLIMIT_NPTS) if (setrlimit(RLIMIT_NPTS, &limit) < 0) err(1, "setrlimit"); #endif signal(SIGALRM, hand); signal(SIGILL, hand); signal(SIGFPE, hand); signal(SIGSEGV, hand); signal(SIGBUS, hand); signal(SIGURG, hand); signal(SIGSYS, hand); signal(SIGTRAP, hand); if (daemon(1, 1) == -1) err(1, "daemon()"); start = time(NULL); while ((time(NULL) - start) < RUNTIME) { if ((pid = fork()) == 0) { if ((e = pthread_create(&rp, NULL, churn, NULL)) != 0) errc(1, e, "pthread_create"); for (j = 0; j < THREADS; j++) if ((e = pthread_create(&cp[j], NULL, calls, NULL)) != 0) errc(1, e, "pthread_create"); for (j = 0; j < THREADS; j++) pthread_join(cp[j], NULL); if ((e = pthread_kill(rp, SIGINT)) != 0) errc(1, e, "pthread_kill"); if ((e = pthread_join(rp, NULL)) != 0) errc(1, e, "pthread_join"); _exit(0); } waitpid(pid, NULL, 0); } return (0); } EOF cd /tmp cc -o $prog -Wall -Wextra -O0 $prog.c -lpthread || exit 1 start=`date +%s` while [ $((`date +%s` - start)) -lt 300 ]; do ./$prog > /dev/null 2>&1 done rm -f /tmp/$prog /tmp/$prog.c /tmp/$prog.core exit 0 diff --git a/tools/test/stress2/misc/sigreturn4.sh b/tools/test/stress2/misc/sigreturn4.sh index c77140de0518..90ee16777e03 100755 --- a/tools/test/stress2/misc/sigreturn4.sh +++ b/tools/test/stress2/misc/sigreturn4.sh @@ -1,207 +1,207 @@ #!/bin/sh # panic: vm_fault_lookup: fault on nofault entry, addr: 0 # cpuid = 2 # time = 1661698922 # KDB: stack backtrace: # db_trace_self_wrapper(b,2931e740,2931e742,ffc0ddb8,190431,...) at db_trace_self_wrapper+0x28/frame 0xffc0dd24 # vpanic(150acba,ffc0dd60,ffc0dd60,ffc0de20,12cc155,...) at vpanic+0xf4/frame 0xffc0dd40 # panic(150acba,14ec1ab,0,146253d,1430,...) at panic+0x14/frame 0xffc0dd54 # vm_fault(1e360c8,0,4,0,0) at vm_fault+0x1725/frame 0xffc0de20 # vm_fault_trap(1e360c8,3b,4,0,0,0) at vm_fault_trap+0x52/frame 0xffc0de48 # trap_pfault(3b,0,0) at trap_pfault+0x176/frame 0xffc0de94 # trap(ffc0df6c,8,28,28,19156000,...) at trap+0x2d9/frame 0xffc0df60 # calltrap() at 0xffc031ef/frame 0xffc0df60 # --- trap 0xc, eip = 0x3b, esp = 0xffc0dfac, ebp = 0xffc0340c --- # (null)() at 0x3b/frame 0xffc0340c # KDB: enter: panic # [ thread pid 54680 tid 102765 ] # Stopped at kdb_enter+0x34: movl $0,kdb_why # db> x/s version # version: FreeBSD 14.0-CURRENT #0 main-n257606-9ea2716b775-dirty: Thu Aug 25 10:47:45 CEST 2022 # pho@mercat1.netperf.freebsd.org:/media/ob # j/usr/src/i386.i386/sys/PHO\012 # db> show proc # Process 54680 (date) at 0x28905d50: # state: NORMAL # uid: 0 gids: 0, 0, 5 # parent: pid 785 at 0x26c14000 # ABI: FreeBSD ELF32 # flag: 0x10004002 flag2: 0 # arguments: date +%s # reaper: 0x18c710a4 reapsubtree: 1 # sigparent: 20 # vmspace: 0x29332100 # (map 0x29332100) # (map.pmap 0x29332174) # (pmap 0x293321b0) # threads: 1 # 102765 Run CPU 2 date # db> [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 prog=sigreturn4 cat > /tmp/$prog.c < #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define RUNTIME 120 #define THREADS 1 static void hand(int i __unused) { /* handler */ _exit(1); } static long random_long(long mi, long ma) { return (arc4random() % (ma - mi + 1) + mi); } static void flip(void *ap, size_t len) { unsigned char *cp; int byte; unsigned char bit, buf, mask, old __unused; cp = (unsigned char *)ap; byte = random_long(0, len); bit = random_long(0,7); mask = ~(1 << bit); buf = cp[byte]; old = cp[byte]; buf = (buf & mask) | (~buf & ~mask); cp[byte] = buf; } static void * churn(void *arg __unused) { time_t start; start = time(NULL); while (time(NULL) - start < 10) { usleep(100); } return(NULL); } static void * calls(void *arg __unused) { time_t start; ucontext_t uc; int n; start = time(NULL); while (time(NULL) - start < 10) { n = 0; if (getcontext(&uc) == -1) err(1, "getcontext"); n++; if (n == 1) { flip(&uc, sizeof(uc)); alarm(1); if (sigreturn(&uc) == -1) err(1, "sigreturn()"); } else break; } return (NULL); } int main(int argc, char **argv) { struct passwd *pw; struct rlimit limit; pid_t pid; pthread_t rp, cp[THREADS]; time_t start; int e, j; if ((pw = getpwnam("nobody")) == NULL) err(1, "failed to resolve nobody"); if (getenv("USE_ROOT") && argc == 2) fprintf(stderr, "Running sigreturn4 as root for %s.\n", argv[1]); else { - if (setgroups(1, &pw->pw_gid) || + if (setgroups(0, NULL) || setegid(pw->pw_gid) || setgid(pw->pw_gid) || seteuid(pw->pw_uid) || setuid(pw->pw_uid)) err(1, "Can't drop privileges to \"nobody\""); endpwent(); } limit.rlim_cur = limit.rlim_max = 1000; #if defined(RLIMIT_NPTS) if (setrlimit(RLIMIT_NPTS, &limit) < 0) err(1, "setrlimit"); #endif signal(SIGALRM, hand); signal(SIGILL, hand); signal(SIGFPE, hand); signal(SIGSEGV, hand); signal(SIGBUS, hand); signal(SIGURG, hand); signal(SIGSYS, hand); signal(SIGTRAP, hand); if (daemon(1, 1) == -1) err(1, "daemon()"); start = time(NULL); while ((time(NULL) - start) < RUNTIME) { if ((pid = fork()) == 0) { if ((e = pthread_create(&rp, NULL, churn, NULL)) != 0) errc(1, e, "pthread_create"); for (j = 0; j < THREADS; j++) if ((e = pthread_create(&cp[j], NULL, calls, NULL)) != 0) errc(1, e, "pthread_create"); for (j = 0; j < THREADS; j++) pthread_join(cp[j], NULL); if ((e = pthread_kill(rp, SIGINT)) != 0) errc(1, e, "pthread_kill"); if ((e = pthread_join(rp, NULL)) != 0) errc(1, e, "pthread_join"); _exit(0); } waitpid(pid, NULL, 0); } return (0); } EOF cd /tmp cc -o $prog -Wall -Wextra -O0 $prog.c -lpthread || exit 1 start=`date +%s` while [ $((`date +%s` - start)) -lt 300 ]; do ./$prog > /dev/null 2>&1 done rm -f /tmp/$prog /tmp/$prog.c /tmp/$prog.core exit 0 diff --git a/tools/test/stress2/misc/syscall4.sh b/tools/test/stress2/misc/syscall4.sh index 3937d45c0303..92150c782ac1 100755 --- a/tools/test/stress2/misc/syscall4.sh +++ b/tools/test/stress2/misc/syscall4.sh @@ -1,381 +1,381 @@ #!/bin/sh # # Copyright (c) 2011-2013 Peter Holm # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # Threaded syscall(2) fuzz test inspired by the iknowthis test suite # by Tavis Ormandy # Usage: syscall4.sh [syscall number] # Without an argument random syscall numbers are tested. # With an argument only the specified syscall number is tested. # Sample problems found: # Thread stuck in stopprof. # http://people.freebsd.org/~pho/stress/log/kostik732.txt # Fixed by r275121. # panic: td 0xcbe1ac40 is not suspended. # https://people.freebsd.org/~pho/stress/log/kostik807.txt # Fixed by r282944. [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 . ../default.cfg odir=`pwd` cd /tmp sed '1,/^EOF/d' < $odir/$0 > syscall4.c sed -i '' -e "s#MNTPOINT#$mntpoint#" syscall4.c rm -f /tmp/syscall4 mycc -o syscall4 -Wall -Wextra -O2 -g syscall4.c -lpthread || exit 1 rm -f syscall4.c kldstat -v | grep -q sysvmsg || $stress2tools/kldload.sh sysvmsg kldstat -v | grep -q sysvsem || $stress2tools/kldload.sh sysvsem kldstat -v | grep -q sysvshm || $stress2tools/kldload.sh sysvshm kldstat -v | grep -q aio || $stress2tools/kldload.sh aio kldstat -v | grep -q mqueuefs || $stress2tools/kldload.sh mqueuefs mount | grep -q "on $mntpoint " && umount -f $mntpoint [ -c /dev/md$mdstart ] && mdconfig -d -u $mdstart mdconfig -a -t swap -s 2g -u $mdstart || exit 1 newfs $newfs_flags -n md$mdstart > /dev/null mount /dev/md$mdstart $mntpoint chmod 777 $mntpoint [ -z "$noswap" ] && daemon sh -c "(cd $odir/../testcases/swap; ./swap -t 10m -i 20 -k)" > \ /dev/null sleeptime=${sleeptime:-12} st=`date '+%s'` while [ $((`date '+%s'` - st)) -lt $((10 * sleeptime)) ]; do (cd $mntpoint; /tmp/syscall4 $* 1>>stdout 2>>stderr) & start=`date '+%s'` while [ $((`date '+%s'` - start)) -lt $sleeptime ]; do pgrep syscall4 > /dev/null || break sleep .5 done while pkill -9 syscall4; do :; done wait ipcs | grep nobody | awk '/^(q|m|s)/ {print " -" $1, $2}' | xargs -L 1 ipcrm done while pkill -9 swap; do :; done while pkill -9 syscall4; do :; done for i in `jot 10`; do mount | grep -q md$mdstart && \ umount $mntpoint && mdconfig -d -u $mdstart && break sleep 10 done if mount | grep -q md$mdstart; then fstat $mntpoint echo "umount $mntpoint failed" exit 1 fi rm -f /tmp/syscall4 exit 0 EOF #include #include #include #include #include #include #include #include #include #include #include #include #include #if defined(__FreeBSD__) #include #define __NP__ #endif #include #include #include #include #include #include #include static int ignore[] = { SYS_syscall, SYS_exit, SYS_fork, 11, /* 11 is obsolete execv */ SYS_reboot, SYS_vfork, 109, /* 109 is old sigblock */ 111, /* 111 is old sigsuspend */ SYS_shutdown, SYS___syscall, 216, /* custom syscall */ SYS_rfork, SYS_mac_syscall, }; static int fd[900], fds[2], kq, socketpr[2]; #ifndef nitems #define nitems(x) (sizeof((x)) / sizeof((x)[0])) #endif #define N 4096 #define MAGIC 1664 #define RUNTIME 120 #define THREADS 50 static uint32_t r[N]; static int magic1, syscallno, magic2; static int random_int(int mi, int ma) { return (arc4random() % (ma - mi + 1) + mi); } static void hand(int i __unused) { /* handler */ exit(1); } static unsigned long makearg(void) { unsigned int i; unsigned long val; val = arc4random(); i = arc4random() % 100; if (i < 20) val = val & 0xff; if (i >= 20 && i < 40) val = val & 0xffff; if (i >= 40 && i < 60) val = (unsigned long)(r) | (val & 0xffff); #if defined(__LP64__) if (i >= 60) { val = (val << 32) | arc4random(); if (i > 80) val = val & 0x00007fffffffffffUL; } #endif return(val); } static void * test(void *arg __unused) { FTS *fts; FTSENT *p; time_t start; int ftsoptions, i, numfiles; char *args[] = { "/dev", "/proc", "MNTPOINT", "mnt2", ".", NULL, }; #ifdef __NP__ pthread_set_name_np(pthread_self(), __func__); #endif numfiles = 0; ftsoptions = FTS_PHYSICAL; start = time(NULL); while (time(NULL) - start < 2) { for (i = 0; i < N; i++) r[i] = arc4random(); if (pipe(fds) == -1) err(1, "pipe()"); if (socketpair(PF_UNIX, SOCK_SEQPACKET, 0, socketpr) == -1) err(1, "socketpair()"); kq = kqueue(); if ((fts = fts_open(args, ftsoptions, NULL)) == NULL) err(1, "fts_open"); i = 0; while ((p = fts_read(fts)) != NULL) { if (fd[i] > 0) close(fd[i]); if ((fd[i] = open(p->fts_path, O_RDWR)) == -1) if ((fd[i] = open(p->fts_path, O_WRONLY)) == -1) if ((fd[i] = open(p->fts_path, O_RDONLY)) == -1) continue; i++; i = i % nitems(fd); if (numfiles++ < 10) { fprintf(stderr, "%d: pts_path = %s\n", numfiles, p->fts_path); } } if (fts_close(fts) == -1) warn("fts_close()"); sleep(1); close(socketpr[0]); close(socketpr[1]); close(fds[0]); close(fds[1]); close(kq); } return(NULL); } static void * calls(void *arg __unused) { time_t start; int i __unused, j, num; unsigned long arg1, arg2, arg3, arg4, arg5, arg6, arg7; #ifdef __NP__ pthread_set_name_np(pthread_self(), __func__); #endif start = time(NULL); for (i = 0; time(NULL) - start < 10; i++) { num = syscallno; while (num == 0) { num = random_int(0, SYS_MAXSYSCALL); for (j = 0; j < (int)nitems(ignore); j++) if (num == ignore[j]) { num = 0; break; } } arg1 = makearg(); arg2 = makearg(); arg3 = makearg(); arg4 = makearg(); arg5 = makearg(); arg6 = makearg(); arg7 = makearg(); #if 0 /* Debug mode */ fprintf(stderr, "%2d : syscall(%3d, %lx, %lx, %lx, %lx, %lx," " %lx, %lx)\n", i, num, arg1, arg2, arg3, arg4, arg5, arg6, arg7); sleep(2); #endif alarm(1); syscall(num, arg1, arg2, arg3, arg4, arg5, arg6, arg7); num = 0; if (magic1 != MAGIC || magic2 != MAGIC) exit(1); } return (NULL); } int main(int argc, char **argv) { struct passwd *pw; struct rlimit limit; pthread_t rp, cp[THREADS]; time_t start; int e, j; magic1 = magic2 = MAGIC; if ((pw = getpwnam("nobody")) == NULL) err(1, "failed to resolve nobody"); if (getenv("USE_ROOT") && argc == 2) fprintf(stderr, "Running syscall4 as root for %s.\n", argv[1]); else { - if (setgroups(1, &pw->pw_gid) || + if (setgroups(0, NULL) || setegid(pw->pw_gid) || setgid(pw->pw_gid) || seteuid(pw->pw_uid) || setuid(pw->pw_uid)) err(1, "Can't drop privileges to \"nobody\""); endpwent(); } limit.rlim_cur = limit.rlim_max = 1000; #if defined(RLIMIT_NPTS) if (setrlimit(RLIMIT_NPTS, &limit) < 0) err(1, "setrlimit"); #endif signal(SIGALRM, hand); signal(SIGILL, hand); signal(SIGFPE, hand); signal(SIGSEGV, hand); signal(SIGBUS, hand); signal(SIGURG, hand); signal(SIGSYS, hand); signal(SIGTRAP, hand); if (argc > 2) { fprintf(stderr, "usage: %s [syscall-num]\n", argv[0]); exit(1); } if (argc == 2) { syscallno = atoi(argv[1]); for (j = 0; j < (int)nitems(ignore); j++) if (syscallno == ignore[j]) errx(0, "syscall #%d is on the ignore list.", syscallno); } if (daemon(1, 1) == -1) err(1, "daemon()"); system("touch aaa bbb ccc; mkdir -p ddd"); start = time(NULL); while ((time(NULL) - start) < RUNTIME) { if (fork() == 0) { if ((e = pthread_create(&rp, NULL, test, NULL)) != 0) errc(1, e, "pthread_create"); usleep(1000); for (j = 0; j < THREADS; j++) if ((e = pthread_create(&cp[j], NULL, calls, NULL)) != 0) errc(1, e, "pthread_create"); for (j = 0; j < THREADS; j++) pthread_join(cp[j], NULL); if ((e = pthread_kill(rp, SIGINT)) != 0) errc(1, e, "pthread_kill"); exit(0); } wait(NULL); usleep(10000); } return (0); } diff --git a/tools/test/stress2/misc/tmpfs16.sh b/tools/test/stress2/misc/tmpfs16.sh index 8cc3c3596a4e..683817ce6497 100755 --- a/tools/test/stress2/misc/tmpfs16.sh +++ b/tools/test/stress2/misc/tmpfs16.sh @@ -1,200 +1,200 @@ #!/bin/sh # # Copyright (c) 2016 EMC Corp. # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # A fuzz test using random file descriptors with random seeks. # "panic: Assertion (cookie & TMPFS_DIRCOOKIE_MASK) == cookie failed": # https://people.freebsd.org/~pho/stress/log/kostik922.txt # Fixed by r303916. [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 . ../default.cfg mount | grep -q "on $mntpoint " && umount -f $mntpoint mount -o size=1g -t tmpfs tmpfs $mntpoint RUNDIR=$mntpoint/stressX dir=$RUNDIR odir=`pwd` cd /tmp sed '1,/^EOF/d' < $odir/$0 > tmpfs16.c rm -f /tmp/tmpfs16 mycc -o tmpfs16 -Wall -Wextra -O2 -g tmpfs16.c -lpthread || exit 1 rm -f tmpfs16.c rm -rf $dir mkdir -p $dir chmod 777 $dir cd $dir jot 500 | xargs touch jot 500 | xargs chmod 666 cd $odir (cd /tmp; /tmp/tmpfs16 $dir) e=$? rm -rf $dir umount $mntpoint rm -f /tmp/tmpfs16 exit $e EOF #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define N (128 * 1024 / (int)sizeof(u_int32_t)) #define RUNTIME 180 #define THREADS 2 static int fd[900]; static u_int32_t r[N]; static char *args[2]; static unsigned long makearg(void) { unsigned long val; val = arc4random(); #if defined(__LP64__) val = (val << 31) | arc4random(); val = val & 0x00007fffffffffffUL; #endif return(val); } static void * test(void *arg __unused) { FTS *fts; FTSENT *p; int ftsoptions, i, n; ftsoptions = FTS_PHYSICAL; for (;;) { for (i = 0; i < N; i++) r[i] = arc4random(); if ((fts = fts_open(args, ftsoptions, NULL)) == NULL) err(1, "fts_open"); i = n = 0; while ((p = fts_read(fts)) != NULL) { if (fd[i] > 0) close(fd[i]); if ((fd[i] = open(p->fts_path, O_RDWR)) == -1) if ((fd[i] = open(p->fts_path, O_WRONLY)) == -1) continue; if (ftruncate(fd[i], 0) != 0) err(1, "ftruncate"); i++; i = i % nitems(fd); } if (fts_close(fts) == -1) err(1, "fts_close()"); sleep(1); } return(0); } static void * calls(void *arg __unused) { off_t offset; time_t start; int fd2; start = time(NULL); while ((time(NULL) - start) < RUNTIME) { fd2 = makearg() % nitems(fd) + 3; offset = makearg(); if (lseek(fd2, offset - 1, SEEK_SET) != -1) { if (write(fd2, "x", 1) != 1) if (errno != EBADF && errno != ENOSPC) warn("write"); } else if (errno != EBADF) warn("lseek"); if (fsync(fd2) == -1) if (errno != EBADF) warn("x"); } return (0); } int main(int argc, char **argv) { struct passwd *pw; pthread_t rp, cp[THREADS]; int e, i; if (argc != 2) { fprintf(stderr, "Usage: %s \n", argv[0]); exit(1); } args[0] = argv[1]; args[1] = 0; if ((pw = getpwnam("nobody")) == NULL) err(1, "failed to resolve nobody"); - if (setgroups(1, &pw->pw_gid) || + if (setgroups(0, NULL) || setegid(pw->pw_gid) || setgid(pw->pw_gid) || seteuid(pw->pw_uid) || setuid(pw->pw_uid)) err(1, "Can't drop privileges to \"nobody\""); endpwent(); if ((e = pthread_create(&rp, NULL, test, NULL)) != 0) errc(1, e, "pthread_create"); usleep(1000); for (i = 0; i < THREADS; i++) if ((e = pthread_create(&cp[i], NULL, calls, NULL)) != 0) errc(1, e, "pthread_create"); for (i = 0; i < THREADS; i++) pthread_join(cp[i], NULL); return (0); }