From jbackus@plex.nl  Wed Dec 30 10:20:31 1998
Received: from gw-nl3.philips.com (gw-nl3.philips.com [192.68.44.35])
          by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id KAA14401
          for <FreeBSD-gnats-submit@freebsd.org>; Wed, 30 Dec 1998 10:20:29 -0800 (PST)
          (envelope-from jbackus@plex.nl)
Received: from smtprelay-nl1.philips.com (localhost.philips.com [127.0.0.1])
          by gw-nl3.philips.com with ESMTP id TAA14938
          for <FreeBSD-gnats-submit@freebsd.org>; Wed, 30 Dec 1998 19:20:09 +0100 (MET)
          (envelope-from jbackus@plex.nl)
Received: from smtprelay-eur1.philips.com(130.139.36.3) by gw-nl3.philips.com via mwrap (4.0a)
	id xma014936; Wed, 30 Dec 98 19:20:09 +0100
Received: from dibbs1.eur.cis.philips.com (dibbs1.eur.cis.philips.com [130.139.33.66]) 
	by smtprelay-nl1.philips.com (8.8.5/8.6.10-1.2.2m-970826) with ESMTP id TAA19198
	for <FreeBSD-gnats-submit@freebsd.org>; Wed, 30 Dec 1998 19:20:08 +0100 (MET)
Received: from hal.mpn.cp.philips.com (hal.mpn.cp.philips.com [130.139.64.195])
	by dibbs1.eur.cis.philips.com (8.8.8/8.8.8) with SMTP id TAA11957
	for <FreeBSD-gnats-submit@freebsd.org>; Wed, 30 Dec 1998 19:20:08 +0100 (MET)
Received: (qmail 32467 invoked from network); 30 Dec 1998 18:20:28 -0000
Received: from unknown (HELO jos.mp-c.com) (172.16.121.86)
  by hal.mpn.cp.philips.com with SMTP; 30 Dec 1998 18:20:28 -0000
Received: (qmail 1596 invoked by uid 1000); 30 Dec 1998 17:21:17 -0000
Message-Id: <19981230172117.1595.qmail@jos.mp-c.com>
Date: 30 Dec 1998 17:21:17 -0000
From: jbackus@plex.nl
Reply-To: Jos Backus <jbackus@plex.nl>
To: FreeBSD-gnats-submit@freebsd.org
Subject: pw/pwd_mkdb deadlock on /etc/master.passwd
X-Send-Pr-Version: 3.2

>Number:         9247
>Category:       bin
>Synopsis:       One cannot invoke the no-lock function of pwd_mkdb
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    davidn
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Dec 30 10:30:01 PST 1998
>Closed-Date:    Sun Jan 10 10:50:19 PST 1999
>Last-Modified:  Sun Jan 10 10:51:40 PST 1999
>Originator:     Jos Backus
>Release:        FreeBSD 3.0-CURRENT i386
>Organization:
Organized? Me?
>Environment:

	-current, possibly -stable as of today

>Description:

	pw deadlocks because it doesn't close the open fd it is holding to
	/etc/master.passwd before forking/exec'ing ``pwd_mkdb -C''. pwd_mkdb
	subsequently tries to flock /etc/master.passwd exclusively, resulting in
	deadlock.

>How-To-Repeat:

	# pw useradd -g nofiles -n alias -d /var/qmail/alias -s /bin/false

	Bingo. You now have to ``killall -9 pwd_mkdb''.

	kdump output:

	1476 pw       CALL  open(0x804f52c,0x20,0)
	1476 pw       NAMI  "/etc/master.passwd"
	1476 pw       RET   open 4

	Note: no intervening close(4).

	1476 pw       CALL  fork
	1476 pw       RET   fork 1477/0x5c5
	1476 pw       CALL  wait4(0x5c5,0xefbfc8f0,0,0)
	1477 pw       RET   fork 0
	1477 pw       CALL  execve(0x80513a7,0xefbfc8f4,0xefbfdb5c)
	1477 pw       NAMI  "/usr/sbin/pwd_mkdb"
	1477 pw       NAMI  "/usr/libexec/ld-elf.so.1"
	1477 pwd_mkdb RET   execve 0

	Note: no intervening close(4).

	1477 pwd_mkdb CALL  open(0xefbfdc6e,0,0x1b6)
	1477 pwd_mkdb NAMI  "/etc/master.passwd"
	1477 pwd_mkdb RET   open 5
	1477 pwd_mkdb CALL  flock(0x5,0x2)
	1476 pw       PSIG  SIGINT SIG_DFL
	1477 pwd_mkdb PSIG  SIGKILL SIG_DFL

>Fix:
	
	This fix makes things work but is of course unacceptable in this form. The
	problem seems to be that endpwent() doesn't actually close fd 4.

	 pwupd.c.orig	Wed Dec 30 18:00:19 1998
	 pwupd.c	Wed Dec 30 18:00:00 1998
	 -109,6 +109,7 @@
 	int             rc = 0;
 
 	endpwent();
+	close(4);
 
 	/*
 	 * First, let's check the see if the database is alright
>Release-Note:
>Audit-Trail:

From: Hidetoshi Shimokawa <simokawa@sat.t.u-tokyo.ac.jp>
To: Jos Backus <jbackus@plex.nl>
Cc: FreeBSD-gnats-submit@FreeBSD.ORG, dillon@FreeBSD.ORG, billf@FreeBSD.ORG
Subject: Re: bin/9247: pw/pwd_mkdb deadlock on /etc/master.passwd
Date: Mon, 04 Jan 1999 15:31:06 +0900

 jbackus> 	This fix makes things work but is of course unacceptable in this form. The
 jbackus> 	problem seems to be that endpwent() doesn't actually close fd 4.
 jbackus> 
 jbackus> 	 pwupd.c.orig	Wed Dec 30 18:00:19 1998
 jbackus> 	 pwupd.c	Wed Dec 30 18:00:00 1998
 jbackus> 	 -109,6 +109,7 @@
 jbackus>  	int             rc = 0;
 jbackus>  
 jbackus>  	endpwent();
 jbackus> +	close(4);
 jbackus>  
 jbackus>  	/*
 jbackus>  	 * First, let's check the see if the database is alright
 
 I have same promblem here.
 master.passwd is not used by getpwent, which uses only pwd.db or spwd.db,
 but it is locked by pw itselt, see main() of pw.c:
 
 	/*
 	 * Try to lock the master passowrd and group files right away (we
 	 * don't care if it works, since this is just advisory locking.
 	 */
 	filelock(_PATH_GROUP);
 	filelock(_PATH_MASTERPASSWD);
 
 We need to unlock(close) before calling "pwd_mkdb" or to have non-lock option
 in pwd_mkdb.c.
 
 /\ Hidetoshi Shimokawa
 \/  simokawa@sat.t.u-tokyo.ac.jp
 PGP public key: finger -l simokawa@sat.t.u-tokyo.ac.jp
 
 
 
 
 

From: Jos Backus <Jos.Backus@nl.origin-it.com>
To: FreeBSD-gnats-submit@FreeBSD.ORG
Cc:  
Subject: Re: bin/9247: pw/pwd_mkdb deadlock on /etc/master.passwd
Date: Sun, 10 Jan 1999 17:32:04 +0100

 This PR can be closed. It has been fixed by
 
 davidn      1999/01/08 02:52:39 PST
 
   Modified files:
     usr.sbin/pw          pw.c
   Log:
   Remove bogus file locking in main().
 
   Revision  Changes    Path
   1.11      +1 -13     src/usr.sbin/pw/pw.c
 
 Thanks,
 -- 
 Jos Backus                          _/  _/_/_/    "Reliability means never
                                    _/  _/   _/     having to say you're sorry."
                                   _/  _/_/_/               -- D. J. Bernstein
                              _/  _/  _/    _/
 Jos.Backus@nl.origin-it.com  _/_/   _/_/_/        use Std::Disclaimer;
Responsible-Changed-From-To: freebsd-bugs->davidn 
Responsible-Changed-By: nectar 
Responsible-Changed-When: Sun Jan 10 09:37:22 PST 1999 
Responsible-Changed-Why:  
davidn made the commit that the bug submitter claims fixes 
this PR. 
State-Changed-From-To: open->closed 
State-Changed-By: steve 
State-Changed-When: Sun Jan 10 10:50:19 PST 1999 
State-Changed-Why:  
Fixed by davidn in rev.1.11 of src/usr.sbin/pw/pw.c. 
>Unformatted:
