NetBSD Problem Report #49738

From mlelstv@pussyfoot.1st.de  Mon Mar  9 07:43:08 2015
Return-Path: <mlelstv@pussyfoot.1st.de>
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" (not verified))
	by mollari.NetBSD.org (Postfix) with ESMTPS id A4FF2A65B7
	for <gnats-bugs@gnats.NetBSD.org>; Mon,  9 Mar 2015 07:43:08 +0000 (UTC)
Message-Id: <20150309074145.0F999B13F@pussyfoot.1st.de>
Date: Mon,  9 Mar 2015 08:41:44 +0100 (CET)
From: mlelstv@serpens.de
Reply-To: mlelstv@serpens.de
To: gnats-bugs@NetBSD.org
Subject: rc.subr leaks filedescriptors
X-Send-Pr-Version: 3.95

>Number:         49738
>Category:       misc
>Synopsis:       rc.subr leaks filedescriptors
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    misc-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Mar 09 07:45:00 +0000 2015
>Closed-Date:    
>Last-Modified:  Fri Oct 21 15:10:00 +0000 2016
>Originator:     mlelstv@serpens.de
>Release:        NetBSD 7.99.4
>Organization:

>Environment:


System: NetBSD pussyfoot 7.99.4 NetBSD 7.99.4 (PUSSYFOOT) #3: Sat Feb 21 14:53:08 CET 2015 mlelstv@pussyfoot:/home/netbsd-current/obj.amd64/home/netbsd-current/src/sys/arch/amd64/compile/PUSSYFOOT amd64
Architecture: x86_64
Machine: amd64
>Description:
When starting LVM at boot, it prints warnings like

 File descriptor 7 () leaked on lvm invocation. Parent PID 122:

This is because it is paranoid and checks for open filedescriptors
when started and emits warnings if any other than filedescriptor
0,1 or 2 are open.

Other filedescriptors however are used by our rc framework to enable
output postprocessing and these are passed to the individual rc scripts
which is a questionable thing to do.

The rc framework allows rc scripts that are not executed in a subshell
but sourced, it's probably impossible to sanitize the filedescriptors
for these scripts.

>How-To-Repeat:
Put lvm=YES in rc.conf and boot.

>Fix:
Either appease lvm to turn off the warnings or close filedescriptors
in rc.subr when calling into rc scripts.

>Release-Note:

>Audit-Trail:

State-Changed-From-To: open->feedback
State-Changed-By: dholland@NetBSD.org
State-Changed-When: Mon, 10 Oct 2016 01:35:36 +0000
State-Changed-Why:
didn't this get dealt with recently?


From: Michael van Elst <mlelstv@serpens.de>
To: gnats-bugs@netbsd.org
Cc: 
Subject: Re: misc/49738 rc.subr leaks filedescriptors
Date: Thu, 20 Oct 2016 07:48:36 +0200

 this was "dealt with", but not solved.

 this still happens on a very -current system.

 Configuring lvm devices.
 File descriptor 7 () leaked on lvm invocation. Parent PID 38: 
 File descriptor 8 () leaked on lvm invocation. Parent PID 38: 
 File descriptor 9 () leaked on lvm invocation. Parent PID 38: 
 File descriptor 7 () leaked on lvm invocation. Parent PID 38: 
 File descriptor 8 () leaked on lvm invocation. Parent PID 38: 
 File descriptor 9 () leaked on lvm invocation. Parent PID 38: 


 Greetings,
 -- 
                                 Michael van Elst
 Internet: mlelstv@serpens.de
                                 "A potential Snark may lurk in every tree."

From: christos@zoulas.com (Christos Zoulas)
To: gnats-bugs@NetBSD.org, misc-bug-people@netbsd.org, 
	gnats-admin@netbsd.org, netbsd-bugs@netbsd.org, mlelstv@serpens.de
Cc: 
Subject: Re: misc/49738 rc.subr leaks filedescriptors
Date: Thu, 20 Oct 2016 07:47:54 -0400

 On Oct 20,  5:50am, mlelstv@serpens.de (Michael van Elst) wrote:
 -- Subject: Re: misc/49738 rc.subr leaks filedescriptors

 | The following reply was made to PR misc/49738; it has been noted by GNATS.
 | 
 | From: Michael van Elst <mlelstv@serpens.de>
 | To: gnats-bugs@netbsd.org
 | Cc: 
 | Subject: Re: misc/49738 rc.subr leaks filedescriptors
 | Date: Thu, 20 Oct 2016 07:48:36 +0200
 | 
 |  this was "dealt with", but not solved.
 |  
 |  this still happens on a very -current system.
 |  
 |  Configuring lvm devices.
 |  File descriptor 7 () leaked on lvm invocation. Parent PID 38: 
 |  File descriptor 8 () leaked on lvm invocation. Parent PID 38: 
 |  File descriptor 9 () leaked on lvm invocation. Parent PID 38: 
 |  File descriptor 7 () leaked on lvm invocation. Parent PID 38: 
 |  File descriptor 8 () leaked on lvm invocation. Parent PID 38: 
 |  File descriptor 9 () leaked on lvm invocation. Parent PID 38: 
 |  

 Yup, it broke again due to lack of unit-tests.

 christos

State-Changed-From-To: feedback->open
State-Changed-By: dholland@NetBSD.org
State-Changed-When: Thu, 20 Oct 2016 12:49:05 +0000
State-Changed-Why:
boo.


From: christos@zoulas.com (Christos Zoulas)
To: gnats-bugs@NetBSD.org, misc-bug-people@netbsd.org, 
	gnats-admin@netbsd.org, netbsd-bugs@netbsd.org, mlelstv@serpens.de
Cc: kre@netbsd.org
Subject: Re: misc/49738 rc.subr leaks filedescriptors
Date: Thu, 20 Oct 2016 11:02:12 -0400

 On Oct 20,  5:50am, mlelstv@serpens.de (Michael van Elst) wrote:
 -- Subject: Re: misc/49738 rc.subr leaks filedescriptors


 How about:
 http://www.netbsd.org/~christos/cloexec.diff and adding:

 cloexec +7 +8 in /etc/rc?

 christos

From: Michael van Elst <mlelstv@serpens.de>
To: Christos Zoulas <christos@zoulas.com>
Cc: gnats-bugs@NetBSD.org, misc-bug-people@netbsd.org, gnats-admin@netbsd.org,
        netbsd-bugs@netbsd.org, kre@netbsd.org
Subject: Re: misc/49738 rc.subr leaks filedescriptors
Date: Thu, 20 Oct 2016 20:21:59 +0200

 On Thu, Oct 20, 2016 at 11:02:12AM -0400, Christos Zoulas wrote:
 > On Oct 20,  5:50am, mlelstv@serpens.de (Michael van Elst) wrote:
 > -- Subject: Re: misc/49738 rc.subr leaks filedescriptors
 > 
 > 
 > How about:
 > http://www.netbsd.org/~christos/cloexec.diff and adding:
 > 
 > cloexec +7 +8 in /etc/rc?

 That isn't POSIX, is it?


 -- 
                                 Michael van Elst
 Internet: mlelstv@serpens.de
                                 "A potential Snark may lurk in every tree."

From: Michael van Elst <mlelstv@serpens.de>
To: Christos Zoulas <christos@zoulas.com>
Cc: gnats-bugs@NetBSD.org, misc-bug-people@netbsd.org, gnats-admin@netbsd.org,
        netbsd-bugs@netbsd.org, kre@netbsd.org
Subject: Re: misc/49738 rc.subr leaks filedescriptors
Date: Thu, 20 Oct 2016 20:24:38 +0200

 On Thu, Oct 20, 2016 at 11:02:12AM -0400, Christos Zoulas wrote:
 > On Oct 20,  5:50am, mlelstv@serpens.de (Michael van Elst) wrote:
 > -- Subject: Re: misc/49738 rc.subr leaks filedescriptors
 > 
 > 
 > How about:
 > http://www.netbsd.org/~christos/cloexec.diff and adding:
 > 
 > cloexec +7 +8 in /etc/rc?

 That isn't POSIX, is it?


 -- 
                                 Michael van Elst
 Internet: mlelstv@serpens.de
                                 "A potential Snark may lurk in every tree."

From: christos@zoulas.com (Christos Zoulas)
To: Michael van Elst <mlelstv@serpens.de>
Cc: gnats-bugs@NetBSD.org, misc-bug-people@netbsd.org, 
	gnats-admin@netbsd.org, netbsd-bugs@netbsd.org, kre@netbsd.org
Subject: Re: misc/49738 rc.subr leaks filedescriptors
Date: Thu, 20 Oct 2016 14:34:32 -0400

 On Oct 20,  8:24pm, mlelstv@serpens.de (Michael van Elst) wrote:
 -- Subject: Re: misc/49738 rc.subr leaks filedescriptors

 | On Thu, Oct 20, 2016 at 11:02:12AM -0400, Christos Zoulas wrote:
 | > On Oct 20,  5:50am, mlelstv@serpens.de (Michael van Elst) wrote:
 | > -- Subject: Re: misc/49738 rc.subr leaks filedescriptors
 | > 
 | > 
 | > How about:
 | > http://www.netbsd.org/~christos/cloexec.diff and adding:
 | > 
 | > cloexec +7 +8 in /etc/rc?
 | 
 | That isn't POSIX, is it?

 There is no POSIX way to do this...

 christos

From: Robert Elz <kre@munnari.OZ.AU>
To: christos@zoulas.com (Christos Zoulas)
Cc: gnats-bugs@NetBSD.org, misc-bug-people@netbsd.org, gnats-admin@netbsd.org,
        netbsd-bugs@netbsd.org, mlelstv@serpens.de
Subject: Re: misc/49738 rc.subr leaks filedescriptors
Date: Fri, 21 Oct 2016 06:25:35 +0700

     Date:        Thu, 20 Oct 2016 11:02:12 -0400
     From:        christos@zoulas.com (Christos Zoulas)
     Message-ID:  <20161020150212.8EFD617FDAB@rebar.astron.com>

   | How about:
   | http://www.netbsd.org/~christos/cloexec.diff and adding:
   | 
   | cloexec +7 +8 in /etc/rc?

 It would want to include fd 9 as well ... but at the expense of adding
 more non-standard baggage to NetBSD's sh, and having the rc system not
 workable on any other sh, then that would work.

 I believe that mostly the rc system correctly closed the fd's it opens
 (which is the standard way to handle this) - but that this fails when the
 rc.d/script has its oeb start function (as for example, lvm does) which
 knows nothing about needing to close rc maintained (they are not from rc.subr
 the Subject of this PR is incorrect) file descriptors.

 An alternative would be to add a new function to the rc system for scripts
 to call, to close any fd's that the rc system has opened, and then have
 the relevant scripts call that function - it could be made reasonably general
 to allow for other similar future issues, perhaps "rc_exec_cleanup" or
 something.

 kre

From: Michael van Elst <mlelstv@serpens.de>
To: Robert Elz <kre@munnari.OZ.AU>
Cc: Christos Zoulas <christos@zoulas.com>, gnats-bugs@NetBSD.org,
        misc-bug-people@netbsd.org, gnats-admin@netbsd.org,
        netbsd-bugs@netbsd.org
Subject: Re: misc/49738 rc.subr leaks filedescriptors
Date: Fri, 21 Oct 2016 07:28:00 +0200

 On Fri, Oct 21, 2016 at 06:25:35AM +0700, Robert Elz wrote:

 > An alternative would be to add a new function to the rc system for scripts
 > to call

 You could simply close the descriptors when calling the rc script.


 -- 
                                 Michael van Elst
 Internet: mlelstv@serpens.de
                                 "A potential Snark may lurk in every tree."

From: Robert Elz <kre@munnari.OZ.AU>
To: Michael van Elst <mlelstv@serpens.de>
Cc: Christos Zoulas <christos@zoulas.com>, gnats-bugs@NetBSD.org,
        misc-bug-people@netbsd.org, gnats-admin@netbsd.org,
        netbsd-bugs@netbsd.org
Subject: Re: misc/49738 rc.subr leaks filedescriptors
Date: Fri, 21 Oct 2016 21:05:25 +0700

     Date:        Fri, 21 Oct 2016 07:28:00 +0200
     From:        Michael van Elst <mlelstv@serpens.de>
     Message-ID:  <20161021052756.GA1762@serpens.de>

   | On Fri, Oct 21, 2016 at 06:25:35AM +0700, Robert Elz wrote:
   | 
   | > An alternative would be to add a new function to the rc system for scripts
   | > to call
   | 
   | You could simply close the descriptors when calling the rc script.

 If it is run in a sub-shell, yes, but not for those that are sourced
 directly.   The rc system is complex...

 kre

From: Robert Elz <kre@munnari.OZ.AU>
To: Michael van Elst <mlelstv@serpens.de>
Cc: Christos Zoulas <christos@zoulas.com>, gnats-bugs@NetBSD.org,
        misc-bug-people@netbsd.org, gnats-admin@netbsd.org,
        netbsd-bugs@netbsd.org
Subject: Re: misc/49738 rc.subr leaks filedescriptors
Date: Fri, 21 Oct 2016 21:07:45 +0700

     Date:        Fri, 21 Oct 2016 07:28:00 +0200
     From:        Michael van Elst <mlelstv@serpens.de>
     Message-ID:  <20161021052756.GA1762@serpens.de>

   | You could simply close the descriptors when calling the rc script.

 And also, the fd that is open to connect to the postprocessor for
 logging the output needs to remain open, even there, that one only
 wants to be closed when calling something that is outside the rc system.

 kre

From: Michael van Elst <mlelstv@serpens.de>
To: gnats-bugs@NetBSD.org
Cc: misc-bug-people@netbsd.org, gnats-admin@netbsd.org, netbsd-bugs@netbsd.org
Subject: Re: misc/49738 rc.subr leaks filedescriptors
Date: Fri, 21 Oct 2016 16:23:55 +0200

 On Fri, Oct 21, 2016 at 02:10:01PM +0000, Robert Elz wrote:

 >  If it is run in a sub-shell, yes, but not for those that are sourced
 >  directly.   The rc system is complex...

 True, but those that are sourced are very special and currently there
 exists only bootconf.sh.


 -- 
                                 Michael van Elst
 Internet: mlelstv@serpens.de
                                 "A potential Snark may lurk in every tree."

From: christos@zoulas.com (Christos Zoulas)
To: Michael van Elst <mlelstv@serpens.de>, gnats-bugs@NetBSD.org
Cc: misc-bug-people@netbsd.org, gnats-admin@netbsd.org, 
	netbsd-bugs@netbsd.org
Subject: Re: misc/49738 rc.subr leaks filedescriptors
Date: Fri, 21 Oct 2016 11:06:26 -0400

 On Oct 21,  4:23pm, mlelstv@serpens.de (Michael van Elst) wrote:
 -- Subject: Re: misc/49738 rc.subr leaks filedescriptors

 | On Fri, Oct 21, 2016 at 02:10:01PM +0000, Robert Elz wrote:
 | 
 | >  If it is run in a sub-shell, yes, but not for those that are sourced
 | >  directly.   The rc system is complex...
 | 
 | True, but those that are sourced are very special and currently there
 | exists only bootconf.sh.

 My solution is simple and does not even break if the builtin is missing.

 christos

>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-2014 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.