NetBSD Problem Report #48925

From mm_lists@pulsar-zone.net  Thu Jun 19 08:23:41 2014
Return-Path: <mm_lists@pulsar-zone.net>
Received: from mail.netbsd.org (mail.netbsd.org [149.20.53.66])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(Client CN "mail.netbsd.org", Issuer "Postmaster NetBSD.org" (verified OK))
	by mollari.NetBSD.org (Postfix) with ESMTPS id 8B61FA64F0
	for <gnats-bugs@gnats.NetBSD.org>; Thu, 19 Jun 2014 08:23:41 +0000 (UTC)
Message-Id: <201406190823.s5J8Ncd0020288@ginseng.pulsar-zone.net>
Date: Thu, 19 Jun 2014 04:23:37 -0400
From: Matthew Mondor <mm_lists@pulsar-zone.net>
To: gnats-bugs@gnats.NetBSD.org
Subject: netbsd-6 fstat(1) pmisc descriptor number mismatch

>Number:         48925
>Category:       bin
>Synopsis:       netbsd-6 fstat(1) pmisc descriptor number mismatch
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    bin-bug-people
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Jun 19 08:25:00 +0000 2014
>Closed-Date:    Sun Jul 25 01:20:13 +0000 2021
>Last-Modified:  Sun Jul 25 01:20:13 +0000 2021
>Originator:     Matthew Mondor
>Release:        NetBSD 6.1_STABLE
>Organization:
>Environment:
System: NetBSD ninja.xisop 6.1_STABLE NetBSD 6.1_STABLE (GENERIC_MM) #3: Mon Jul 1 19:08:46 EDT 2013 root@ninja.xisop:/usr/obj/sys/arch/amd64/compile/GENERIC_MM amd64
Architecture: x86_64
Machine: amd64
>Description:

As can be seen below, some file descriptor types (handled by pmisc())
are reported with a wrong FD number.

# fstat -p 14403
USER     CMD          PID   FD MOUNT       INUM MODE         SZ|DV R/W
mmondor  tms-server 14403   wd /              2 drwxr-xr-x    1024 r 
mmondor  tms-server 14403    0 /         873100 crw-rw-rw-    null rw
mmondor  tms-server 14403    1 /         873100 crw-rw-rw-    null rw
mmondor  tms-server 14403    2 /         873100 crw-rw-rw-    null rw
mmondor  tms-server 14403    3* unix dgram  <-> fffffe810ede6f08
mmondor  tms-server 14403    4* kqueue pending 0
mmondor  tms-server 14403    5* internet stream tcp *:7777
mmondor  tms-server 14403    5* misc 0xfffffe810f768fa8
mmondor  tms-server 14403    7* internet stream tcp 192.168.1.15:64000 <-> 192.168.1.15:7777

[...]

www      httpd        314    5* crypto 0xc378cdd4
www      httpd        314    5* crypto 0xc378cd6c
www      httpd        314    5* crypto 0xc378cd04
www      httpd        314    5* crypto 0xc378cc9c
www      httpd        314    5* crypto 0xc378cc34
www      httpd        314    5* crypto 0xc378cbcc
www      httpd        314    5* crypto 0xc378cb64
www      httpd        314    5* crypto 0xc378cafc
www      httpd        314    5* crypto 0xc378ca94
www      httpd        314   61* pipe 0xc4372d88 <- 0xc3aba304 rn
www      httpd        314   62* pipe 0xc3aba304 -> 0xc4372d88 w
www      httpd        314   63 /         349490 -rw-r-----  784855 w 
www      httpd        314    4* kqueue pending 1
www      httpd        314   65* pipe 0xc4377cc8 -> 0xc4372848 w
www      httpd        314   67* unix stream  <-> c86d4504
www      httpd        314   68* unix stream  <-> c7b9b1e4

>How-To-Repeat:

Use fstat on processes using kqueue, crypto, misc, etc

>Fix:

The attached diff appears to fix it for me.

--MP_/xAK7ceaI/SWkG6Lq6fW8H_1
Content-Type: text/plain
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename=netbsd-6-fstat.diff

Index: usr.bin/fstat/fstat.c
===================================================================
RCS file: /data/rsync/netbsd-cvs/src/usr.bin/fstat/fstat.c,v
retrieving revision 1.95.4.1
diff -u -p -r1.95.4.1 fstat.c
--- usr.bin/fstat/fstat.c	2 Apr 2012 18:22:03 -0000	1.95.4.1
+++ usr.bin/fstat/fstat.c	19 Jun 2014 08:03:04 -0000
@@ -170,7 +170,7 @@ static const char *inet6_addrstr(char *,
 #endif
 static const char *at_addrstr(char *, size_t, const struct sockaddr_at *);
 static void	socktrans(struct socket *, int);
-static void	misctrans(struct file *);
+static void	misctrans(int fd, struct file *);
 static int	ufs_filestat(struct vnode *, struct filestat *);
 static void	usage(void) __dead;
 static const char   *vfilestat(struct vnode *, struct filestat *);
@@ -424,7 +424,7 @@ ftrans(fdfile_t *fp, int i)
 	case DTYPE_MQUEUE:
 	case DTYPE_SEM:
 		if (checkfile == 0)
-			misctrans(&file);
+			misctrans(i, &file);
 		break;
 	default:
 		dprintf("unknown file type %d for file %d of pid %d",
@@ -1081,10 +1081,10 @@ bad:
 }

 static void
-misctrans(struct file *file)
+misctrans(int fd, struct file *file)
 {

-	PREFIX((int)file->f_type);
+	PREFIX(fd);
 	pmisc(file, dtypes[file->f_type]);
 }


--MP_/xAK7ceaI/SWkG6Lq6fW8H_1--

>Release-Note:

>Audit-Trail:

State-Changed-From-To: open->closed
State-Changed-By: dholland@NetBSD.org
State-Changed-When: Sun, 25 Jul 2021 01:20:13 +0000
State-Changed-Why:
Someone seems to have committed a similar patch sometime since 2014.
sorry this got missed at the time...


>Unformatted:
 --MP_/xAK7ceaI/SWkG6Lq6fW8H_1
 Content-Type: text/plain; charset=US-ASCII
 Content-Transfer-Encoding: 7bit
 Content-Disposition: inline

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: gnats-precook-prs,v 1.4 2018/12/21 14:20:20 maya Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2017 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.