Skip to content

Commit

Permalink
Added two scenarios for SU problem with flush of inodes.
Browse files Browse the repository at this point in the history
  • Loading branch information
phoatfreebsd committed Oct 7, 2011
1 parent e5ead40 commit 2d9e6e4
Show file tree
Hide file tree
Showing 2 changed files with 285 additions and 0 deletions.
136 changes: 136 additions & 0 deletions misc/linger3.sh
@@ -0,0 +1,136 @@
#!/bin/sh

#
# Copyright (c) 2011 Peter Holm <pho@FreeBSD.org>
# 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.
#
# $FreeBSD$
#

# Test for SU problem with false EMLINK

[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1

. ../default.cfg

here=`pwd`
cd /tmp
sed '1,/^EOF/d' < $here/$0 > linger3.c
cc -o linger3 -Wall -Wextra -O2 linger3.c
rm -f linger3.c

mount | grep "$mntpoint" | grep -q md$mdstart && umount $mntpoint
mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart

mdconfig -a -t swap -s 2g -u $mdstart
bsdlabel -w md$mdstart auto
[ $# -eq 1 ] && opt="$1"
[ $# -eq 0 ] && opt=-U # The default is "-U"
echo "newfs $opt md${mdstart}$part"
newfs $opt md${mdstart}$part > /dev/null
mount /dev/md${mdstart}$part $mntpoint

cd $mntpoint
chmod 777 $mntpoint

su $testuser -c "/tmp/linger3"

cd $here

while mount | grep -q $mntpoint; do
umount ${mntpoint} 2> /dev/null || sleep 1
done
mdconfig -d -u $mdstart
rm -f /tmp/linger3
exit 0
EOF
#include <sys/types.h>
#include <err.h>
#include <errno.h>
#include <fcntl.h>
#include <sched.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <unistd.h>

#define PARALLEL 4
#define ND ((32767 / PARALLEL) - 2)

static pid_t p;

void
setup(int loop)
{
int d;
char name[128];

for (d = 0; d < ND; d++) {
snprintf(name, sizeof(name), "d%06d.%03d", p, d);
if (mkdir(name, 00700) == -1)
err(1, "mkdir(%s) @ loop #%d", name, loop);
}
}

void
prune(int loop)
{
int d;
char name[128];

for (d = 0; d < ND; d++) {
snprintf(name, sizeof(name), "d%06d.%03d", p, d);
if (rmdir(name) == -1)
err(1, "rmdir(%s) @ loop #%d", name, loop);
}
}

int
main()
{
int i, j;
int linger = 0;

if (getenv("LINGER"))
linger = atoi(getenv("LINGER"));

for (i = 0; i < PARALLEL; i++) {
if (fork() == 0) {
p = getpid();
for (j = 0; j < 10; j++) {
setup(j);
prune(j);
if (linger != 0)
sleep(linger);
}
_exit(0);
}
}

for (i = 0; i < PARALLEL; i++)
wait(NULL);

return (0);
}
149 changes: 149 additions & 0 deletions misc/linger4.sh
@@ -0,0 +1,149 @@
#!/bin/sh

#
# Copyright (c) 2011 Peter Holm <pho@FreeBSD.org>
# 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.
#
# $FreeBSD$
#

# Test for SU problem with "out of inodes" for CREAT

[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1

. ../default.cfg

here=`pwd`
cd /tmp
sed '1,/^EOF/d' < $here/$0 > linger3.c
cc -o linger4 -Wall -Wextra -O2 linger3.c
rm -f linger4.c

mount | grep "$mntpoint" | grep -q md$mdstart && umount $mntpoint
mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart

mdconfig -a -t swap -s 2g -u $mdstart
bsdlabel -w md$mdstart auto
[ $# -eq 1 ] && opt="$1"
[ $# -eq 0 ] && opt=-U # The default is "-U"
echo "newfs $opt md${mdstart}$part"
newfs $opt md${mdstart}$part > /dev/null
mount /dev/md${mdstart}$part $mntpoint

cd $mntpoint
chmod 777 $mntpoint

su $testuser -c "/tmp/linger4"

cd $here

while mount | grep -q $mntpoint; do
umount ${mntpoint} 2> /dev/null || sleep 1
done
mdconfig -d -u $mdstart
rm -f /tmp/linger4
exit 0
EOF
#include <sys/types.h>
#include <err.h>
#include <errno.h>
#include <fcntl.h>
#include <sched.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/param.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <unistd.h>

#define PARALLEL 4

#define NUMBER 80000 / PARALLEL /* Number of files to use. Max is 131068 */

void
Creat(int loopno)
{
int e, fd, i, j;
char file[128];
char path[128];
pid_t pid;

e = 0;
pid = getpid();
sprintf(path, "f%06d", pid);
if (mkdir(path, 0770) == -1)
warn("mkdir(%s), %s:%d, loop #%d", path, __FILE__, __LINE__, loopno);
chdir(path);

for (j = 0; j < NUMBER; j++) {
sprintf(file,"p%05d.%05d", pid, j);
if ((fd = creat(file, 0660)) == -1) {
if (errno != EINTR) {
warn("creat(%s). %s:%d, loop #%d", file, __FILE__, __LINE__, loopno);
e = 1;
break;
}
}
if (fd != -1 && close(fd) == -1)
err(2, "close(%d)", j);

}

for (i = --j; i >= 0; i--) {
sprintf(file,"p%05d.%05d", pid, i);
if (unlink(file) == -1)
err(3, "unlink(%s)", file);

}
chdir ("..");
if (rmdir(path) == -1)
err(1, "rmdir(%s), %s:%d, loop #%d", path, __FILE__, __LINE__, loopno);

_exit(e);
}


int
main()
{
int e, i, j, status;

for (j = 0; j < 300; j++) {
for (i = 0; i < PARALLEL; i++) {
if (fork() == 0)
Creat(j);
}

for (i = 0; i < PARALLEL; i++) {
wait(&status);
e += status;
}
if (e != 0)
break;
// sleep(60); /* No problems if this is included */
}
system("ls -la /mnt; df -i /mnt");

return (0);
}

0 comments on commit 2d9e6e4

Please sign in to comment.