NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

kern/37878: fdclone(9) suspected of not working well with fstat(1)



>Number:         37878
>Category:       kern
>Synopsis:       fdclone(9) suspected of not working well with fstat(1)
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    kern-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sat Jan 26 20:20:01 +0000 2008
>Originator:     Matthew Mondor
>Release:        NetBSD 4.99.49
>Organization:
Pulsar-Zone
>Environment:
NetBSD sat.xisop 4.99.49 NetBSD 4.99.49 (GENERIC_LAPTOP_MM) #0: Thu Jan 24 
00:27:38 EST 2008  
root%sat.xisop@localhost:/usr/src/sys/arch/i386/compile/GENERIC_LAPTOP_MM i386
>Description:
tap(4) and bpf(4) are using fdclone(9).  Interestingly, fstat(1) is not able to 
show open descriptors for those two devices as well.  These get magically 
skipped, and other descriptors are correctly reported.
>How-To-Repeat:
Run tcpdump(1) and attempt to obtain its bpf descriptor information via 
fstat(1).

# fstat -p $(pgrep tcpdump)
USER     CMD          PID   FD MOUNT       INUM MODE         SZ|DV R/W
root     tcpdump     8322   wd /         493920 drwxr-xr-x   30208 r 
root     tcpdump     8322    0 /dev/pts      15 crw--w----   ttyp6 rw
root     tcpdump     8322    1 /dev/pts      15 crw--w----   ttyp6 rw
root     tcpdump     8322    2 /dev/pts      15 crw--w----   ttyp6 rw


Alternatively try the following short code:

#include <errno.h>
#include <err.h>
#include <fcntl.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>

int
main(void)
{
        int t1, t2;

        if ((t1 = open("/dev/tap", O_RDWR)) == -1)
                err(errno, "open");
        if ((t2 = open("/dev/tap", O_RDWR)) == -1)
                err(errno, "open");

        sleep(60);

        (void) close(t2);
        (void) close(t1);

        return EXIT_SUCCESS;
}

# cd /tmp/
# vi test.c
# cc -o test test.c
# ./test &
# fstat -p $(pgrep test)

root     test        6329   wd /         757344 drwxrwxrwt     512 r
root     test        6329    0 /dev/pts       7 crw--w----   ttyp2 rw
root     test        6329    1 /dev/pts       7 crw--w----   ttyp2 rw
root     test        6329    2 /dev/pts       7 crw--w----   ttyp2 rw

# kill $(pgrep test)

Descriptors 3 and 4 are not shown.
>Fix:




Home | Main Index | Thread Index | Old Index