NetBSD Problem Report #47805

From yamt@NetBSD.org  Wed May  8 04:50:41 2013
Return-Path: <yamt@NetBSD.org>
Received: by www.NetBSD.org (Postfix, from userid 1270)
	id 89D0663F174; Wed,  8 May 2013 04:50:41 +0000 (UTC)
Message-Id: <20130508045041.89D0663F174@www.NetBSD.org>
Date: Wed,  8 May 2013 04:50:41 +0000 (UTC)
From: yamt@NetBSD.org
Reply-To: yamt@NetBSD.org
To: gnats-bugs@NetBSD.org
Subject: /bin/sh descriptor leak
X-Send-Pr-Version: 3.95

>Number:         47805
>Category:       bin
>Synopsis:       /bin/sh descriptor leak
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    bin-bug-people
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed May 08 04:55:00 +0000 2013
>Closed-Date:    Thu Sep 05 04:56:55 +0000 2013
>Last-Modified:  Thu Sep 05 04:56:55 +0000 2013
>Originator:     YAMAMOTO Takashi
>Release:        NetBSD current
>Organization:

>Environment:


>Description:
	/bin/sh sometimes leak descriptors on redirection.
	it causes silly renames on nfs and "git rebase -i" fail with ENOTEMPTY.

>How-To-Repeat:

$ fstat -p$$
USER     CMD          PID   FD MOUNT       INUM MODE         SZ|DV R/W
takashi  sh          5922   wd /home    2399488 drwxr-xr-x    8192 r 
takashi  sh          5922    0 /dev/pts      15 crw--w----   pts/6 rw
takashi  sh          5922    1 /dev/pts      15 crw--w----   pts/6 rw
takashi  sh          5922    2 /dev/pts      15 crw--w----   pts/6 rw
takashi  sh          5922 1023 /         691216 crw-rw-rw-     tty rw
$ echo 3>/dev/null

$ fstat -p$$
USER     CMD          PID   FD MOUNT       INUM MODE         SZ|DV R/W
takashi  sh          5922   wd /home    2399488 drwxr-xr-x    8192 r 
takashi  sh          5922    0 /dev/pts      15 crw--w----   pts/6 rw
takashi  sh          5922    1 /dev/pts      15 crw--w----   pts/6 rw
takashi  sh          5922    2 /dev/pts      15 crw--w----   pts/6 rw
takashi  sh          5922    3 /         691212 crw-rw-rw-    null w 
takashi  sh          5922   10 /         691212 crw-rw-rw-    null w 
takashi  sh          5922 1023 /         691216 crw-rw-rw-     tty rw
$ 

>Fix:
	FreeBSD SVN rev 199953 seems like a fix for this problem.
http://lists.freebsd.org/pipermail/svn-src-head/2009-November/012085.html

>Release-Note:

>Audit-Trail:
From: "YAMAMOTO Takashi" <yamt@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/47805 CVS commit: src/bin/sh
Date: Thu, 27 Jun 2013 23:22:04 +0000

 Module Name:	src
 Committed By:	yamt
 Date:		Thu Jun 27 23:22:04 UTC 2013

 Modified Files:
 	src/bin/sh: eval.c redir.c

 Log Message:
 fix descriptor leaks.  PR/47805

 this fix was taken from FreeBSD SVN rev 199953 (Jilles Tjoelker)
     ------------------------------------------------------------------------
     r199953 | jilles | 2009-11-30 07:33:59 +0900 (Mon, 30 Nov 2009) | 16 lines

     Fix some cases where file descriptors from redirections leak to programs.

     - Redirecting fds that were not open before kept two copies of the
       redirected file.
 	sh -c '{ :; } 7>/dev/null; fstat -p $$; true'
 	(both fd 7 and 10 remained open)
     - File descriptors used to restore things after redirection were not
       set close-on-exec, instead they were explicitly closed before executing
       a program normally and before executing a shell procedure. The latter
       must remain but the former is replaced by close-on-exec.
 	sh -c 'exec 7</; { exec fstat -p $$; } 7>/dev/null; true'
 	(fd 10 remained open)

     The examples above are simpler than the testsuite because I do not want to
     use fstat or procstat in the testsuite.


 To generate a diff of this commit:
 cvs rdiff -u -r1.106 -r1.107 src/bin/sh/eval.c
 cvs rdiff -u -r1.34 -r1.35 src/bin/sh/redir.c

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

State-Changed-From-To: open->closed
State-Changed-By: dholland@NetBSD.org
State-Changed-When: Thu, 05 Sep 2013 04:56:55 +0000
State-Changed-Why:
yamt fixed it himself back in June


>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.