Subject: kern/17380: a huge kern.maxfiles and file descriptor leek lead to panic
To: None <>
From: None <>
List: netbsd-bugs
Date: 06/24/2002 18:05:59
>Number:         17380
>Category:       kern
>Synopsis:       a huge kern.maxfiles and file descriptor leek lead to panic
>Confidential:   no
>Severity:       critical
>Priority:       medium
>Responsible:    kern-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Jun 24 18:06:00 PDT 2002
>Originator:     Christian Biere
>Release:        1.6A
NetBSD localhost 1.6A NetBSD 1.6A (DURON) #0: Wed Jun 12 22:50:53 CEST 2002     root@localhost:/usr/src/sys/arch/i386/compile/DURON i386

I was curious and tried the following

# sysctl -w kern.maxfiles=10000000000
kern.maxfiles: 548 -> 2147483647
# ulimit -n unlimited
# /tmp/fdtest

After about 3000000 open() without close() the kernel panic'ed. It should be easy repeatable. Therefore, I did not notice the message. If it's really necessary I'll do it again. I did this as root but IMHO fdtest would cause the same problem for a normal user if the # of open files isn't restricted to an appropiate figure.

The following program was used. Normally it would fail with "open() failed: Too many open files". It does not if _SC_OPEN_MAX is extraordinary high.

#include <stdlib.h>
#include <stdio.h>
#include <fcntl.h>

int main(int argc, const char *argv[]) {
int	fd,
	count = 0;
	for (;;) {
		if (-1 == (fd = open("/dev/stdin",O_RDONLY))) {
			perror("open() failed");
			return EXIT_FAILURE;
	 if (++count % 1000 == 0)
	 	printf("count = %9d fd = %9d\n", count, fd);