NetBSD Problem Report #37878

From martin@duskware.de  Sat Jan 26 20:18:17 2008
Return-Path: <martin@duskware.de>
Received: from mail.netbsd.org (mail.netbsd.org [204.152.190.11])
	by narn.NetBSD.org (Postfix) with ESMTP id 8AF1663BD29
	for <gnats-bugs@gnats.netbsd.org>; Sat, 26 Jan 2008 20:18:17 +0000 (UTC)
Message-Id: <20080126185604.9C22D63B101@narn.NetBSD.org>
Date: Sat, 26 Jan 2008 18:56:04 +0000 (UTC)
From: mmondor@pulsar-zone.net
Reply-To: mmondor@pulsar-zone.net
To: netbsd-bugs-owner@NetBSD.org
Subject: fdclone(9) suspected of not working well with fstat(1)
X-Send-Pr-Version: www-1.0

>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:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sat Jan 26 20:20:01 +0000 2008
>Closed-Date:    Sat Apr 11 15:49:06 +0000 2009
>Last-Modified:  Sat Apr 11 15:50:01 +0000 2009
>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:/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:

>Release-Note:

>Audit-Trail:
From: "Matthew Mondor" <mmondor@pulsar-zone.net>
To: gnats-bugs@netbsd.org
Cc: 
Subject: Re: kern/37878: fdclone(9) suspected of not working well with fstat(1)
Date: Sat, 26 Jan 2008 15:55:56 -0500 (EST)

 Note that the descriptors are still visible via procfs.
 Also, this PR replaces bin/37550.

 -- 
 Matthew Mondor

State-Changed-From-To: open->closed
State-Changed-By: christos@NetBSD.org
State-Changed-When: Sat, 11 Apr 2009 11:49:06 -0400
State-Changed-Why:
fixed, thanks


From: Christos Zoulas <christos@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/37878 CVS commit: src/sys
Date: Sat, 11 Apr 2009 11:47:34 -0400

 Module Name:	src
 Committed By:	christos
 Date:		Sat Apr 11 15:47:34 UTC 2009

 Modified Files:
 	src/sys/dev/dmover: dmover_io.c
 	src/sys/dev/putter: putter.c
 	src/sys/kern: kern_drvctl.c sys_mqueue.c
 	src/sys/net: bpf.c bpfdesc.h if_tap.c
 	src/sys/opencrypto: cryptodev.c
 	src/sys/sys: mqueue.h

 Log Message:
 Fix PR/37878 and PR/37550: Provide stat(2) for all devices and don't use
 fbadop_stat.


 To generate a diff of this commit:
 cvs rdiff -u -r1.32 -r1.33 src/sys/dev/dmover/dmover_io.c
 cvs rdiff -u -r1.21 -r1.22 src/sys/dev/putter/putter.c
 cvs rdiff -u -r1.24 -r1.25 src/sys/kern/kern_drvctl.c
 cvs rdiff -u -r1.14 -r1.15 src/sys/kern/sys_mqueue.c
 cvs rdiff -u -r1.144 -r1.145 src/sys/net/bpf.c
 cvs rdiff -u -r1.29 -r1.30 src/sys/net/bpfdesc.h
 cvs rdiff -u -r1.55 -r1.56 src/sys/net/if_tap.c
 cvs rdiff -u -r1.47 -r1.48 src/sys/opencrypto/cryptodev.c
 cvs rdiff -u -r1.6 -r1.7 src/sys/sys/mqueue.h

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2007 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.