From nobody@FreeBSD.org  Mon Jan  7 20:47:21 2002
Return-Path: <nobody@FreeBSD.org>
Received: from freefall.freebsd.org (freefall.FreeBSD.org [216.136.204.21])
	by hub.freebsd.org (Postfix) with ESMTP id C7F0337B400
	for <freebsd-gnats-submit@FreeBSD.org>; Mon,  7 Jan 2002 20:47:19 -0800 (PST)
Received: (from nobody@localhost)
	by freefall.freebsd.org (8.11.6/8.11.6) id g084lJW29086;
	Mon, 7 Jan 2002 20:47:19 -0800 (PST)
	(envelope-from nobody)
Message-Id: <200201080447.g084lJW29086@freefall.freebsd.org>
Date: Mon, 7 Jan 2002 20:47:19 -0800 (PST)
From: Umesh Krishnaswamy <umesh@juniper.net>
To: freebsd-gnats-submit@FreeBSD.org
Subject: telnetd and mount_mfs signal handlers call exit() which can hang process.
X-Send-Pr-Version: www-1.0

>Number:         33672
>Category:       bin
>Synopsis:       [patch] telnetd and mount_mfs signal handlers call exit() which can hang process.
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Jan 07 20:50:00 PST 2002
>Closed-Date:    Tue Feb 13 08:38:37 GMT 2007
>Last-Modified:  Tue Feb 13 08:38:37 GMT 2007
>Originator:     Umesh Krishnaswamy
>Release:        4.2
>Organization:
Juniper Networks
>Environment:
FreeBSD arisia.juniper.net 4.2-RELEASE FreeBSD 4.2-RELEASE #0: Tue Apr 10 19:09:01 PDT 2001     root@:/usr/src/sys/compile/ARISIA  i386

>Description:
We have observed multiple telnetd hangs with the following backtrace.

#0  0x88055ed4 in nanosleep () at ./i386/reloc.c:248
#1  0x88054bb1 in wlock_acquire (lock=0x88067000) at ./i386/lockdflt.c:194
#2  0x880539d2 in rtld_exit () at rtld.c:1408
#3  0x88128fc4 in exit (status=1) at ./../libc/stdlib/exit.c:71
#4  0x804bdbd in cleanup () <-- telnetd() SIGCHLD signal handler
#5  0xbfbfffa4 in ?? ()
#6  0x88054372 in symlook_default (name=0x8048c45 "logout", hash=120972996, 
    refobj=0x88065000, defobj_out=0xbfbff5d4, in_plt=1 '\001') at rtld.c:1827
#7  0x88052ea4 in find_symdef (symnum=50, refobj=0x88065000, 
    defobj_out=0xbfbff5fc, in_plt=1 '\001') at rtld.c:837
#8  0x88052787 in _rtld_bind (obj=0x88065000, reloff=512) at rtld.c:430
#9  0x880521e9 in _rtld_bind_start () from /usr/libexec/ld-elf.so.1
#10 0x804d11f in telnet ()
#11 0x804c879 in doit ()
#12 0x804c35f in main ()
#13 0x804966d in _start ()

(gdb) p lockinfo
$2 = {context = 0x0, thelock = 0x88067000, rcount = 1, wcount = 0, 
  lock_create = 0x880549ec <lock_create>, 
  rlock_acquire = 0x88054b1c <rlock_acquire>, 
  wlock_acquire = 0x88054b5c <wlock_acquire>, 
  rlock_release = 0x88054be4 <rlock_release>, 
  wlock_release = 0x88054bf4 <wlock_release>, 
  lock_destroy = 0x88054a38 <lock_destroy>, context_destroy = 0}
(gdb) x/x lockinfo.thelock
0x88067000:     0x00000002

When the signal comes in, telnetd was trying to resolve a symbol and
had acquired a read lock in rtld_bind. Hence the reader count of
1. The signal handler calls exit, which vectors to rtld_exit which
tries to acquire a write lock and gets locked out against itself.

One fix is to call _exit() in the signal handler. Turns out OpenBSD did the same fix
2 months ago in telnetd. Not sure how many other apps need such a fix.
For 4.2, mount_mfs also needs a patch.

>How-To-Repeat:
This is a tough one. Need to hit the right test case (which I do not
have access to). After that it is reproducible.

>Fix:
Here is a patch. 

RCS file: /home/ncvs/src/libexec/telnetd/sys_term.c,v
retrieving revision 1.36
diff -u -p -r1.36 sys_term.c
--- sys_term.c  2001/12/03 12:41:18     1.36
+++ sys_term.c  2002/01/08 04:42:31
@@ -1180,5 +1180,5 @@ cleanup(int sig __unused)
        (void)chmod(line, 0666);
        (void)chown(line, 0, 0);
        (void) shutdown(net, 2);
-       exit(1);
+       _exit(1);
 }

>Release-Note:
>Audit-Trail:

From: "Umesh Krishnaswamy" <umesh.k@mindspring.com>
To: <freebsd-gnats-submit@FreeBSD.org>,
	"Umesh Krishnaswamy" <umesh@juniper.net>
Cc:  
Subject: Re: misc/33672: telnetd and mount_mfs signal handlers call exit() which can hang process.
Date: Thu, 31 Jan 2002 01:35:03 -0800

 This is a multi-part message in MIME format.
 
 ------=_NextPart_000_0004_01C1A9F7.81726A60
 Content-Type: text/plain;
 	charset="iso-8859-1"
 Content-Transfer-Encoding: 7bit
 
 Hi,
 
 A patch is attached with this PR. Could somebody approve and commit the fix.
 
 Thanks.
 Umesh.
 
 
 ------=_NextPart_000_0004_01C1A9F7.81726A60
 Content-Type: text/html;
 	charset="iso-8859-1"
 Content-Transfer-Encoding: quoted-printable
 
 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
 <HTML><HEAD>
 <META http-equiv=3DContent-Type content=3D"text/html; =
 charset=3Diso-8859-1">
 <META content=3D"MSHTML 6.00.2712.300" name=3DGENERATOR></HEAD>
 <BODY>
 <DIV><SPAN class=3D037063309-31012002><FONT face=3DArial=20
 size=3D2>Hi,</FONT></SPAN></DIV>
 <DIV><SPAN class=3D037063309-31012002><FONT face=3DArial=20
 size=3D2></FONT></SPAN>&nbsp;</DIV>
 <DIV><SPAN class=3D037063309-31012002><FONT face=3DArial size=3D2>A =
 patch is attached=20
 with this PR. Could somebody approve and commit the =
 fix.</FONT></SPAN></DIV>
 <DIV><SPAN class=3D037063309-31012002><FONT face=3DArial=20
 size=3D2></FONT></SPAN>&nbsp;</DIV>
 <DIV><SPAN class=3D037063309-31012002><FONT face=3DArial=20
 size=3D2>Thanks.</FONT></SPAN></DIV>
 <DIV><SPAN class=3D037063309-31012002><FONT face=3DArial=20
 size=3D2>Umesh.</FONT></SPAN></DIV>
 <DIV><SPAN class=3D037063309-31012002><FONT face=3DArial=20
 size=3D2></FONT></SPAN>&nbsp;</DIV></BODY></HTML>
 
 ------=_NextPart_000_0004_01C1A9F7.81726A60--
 

From: Sheldon Hearn <sheldonh@starjuice.net>
To: markm@FreeBSD.org
Cc: "Umesh Krishnaswamy" <umesh.k@mindspring.com>,
	bug-followup@freebsd.org
Subject: Re: misc/33672: telnetd and mount_mfs signal handlers call exit() which can hang process. 
Date: Mon, 04 Feb 2002 17:26:37 +0200

 On Thu, 31 Jan 2002 01:40:02 PST, "Umesh Krishnaswamy" wrote:
 
 > Subject: Re: misc/33672: telnetd and mount_mfs signal handlers call exit() which can hang process.
 
 Hi Mark,
 
 PR misc/33672 contains a patch which removes the use of non-signal-safe
 library calls from a signal handler in telnetd.
 
 I can't remember which way around we're supposed to commit to the
 telnetd sources these days.
 
 How do we commit changes to telnetd now?
 
 Ciao,
 Sheldon.

From: Mark Murray <mark@grondar.za>
To: Sheldon Hearn <sheldonh@starjuice.net>
Cc: "Umesh Krishnaswamy" <umesh.k@mindspring.com>,
	bug-followup@FreeBSD.org
Subject: Re: misc/33672: telnetd and mount_mfs signal handlers call exit() which can hang process. 
Date: Mon, 04 Feb 2002 15:58:52 +0000

 > I can't remember which way around we're supposed to commit to the
 > telnetd sources these days.
 > 
 > How do we commit changes to telnetd now?
 
 src/crypto/telnet/* first, then go to the equivalent place in
 src/*/*telnet* and "make unifdef" (and eyeball the diffs) before
 committing there.
 
 M
 -- 
 o       Mark Murray
 \_      FreeBSD Services Limited
 O.\_    Warning: this .sig is umop ap!sdn
Responsible-Changed-From-To: freebsd-bugs->sheldonh 
Responsible-Changed-By: sheldonh 
Responsible-Changed-When: Tue Feb 5 01:19:14 PST 2002 
Responsible-Changed-Why:  
I'll take this one. 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=33672 
Responsible-Changed-From-To: sheldonh->freebsd-bugs 
Responsible-Changed-By: sheldonh 
Responsible-Changed-When: Tue Feb 17 03:19:07 PST 2004 
Responsible-Changed-Why:  
Release. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=3170 
Responsible-Changed-From-To: sheldonh->freebsd-bugs 
Responsible-Changed-By: sheldonh 
Responsible-Changed-When: Tue Feb 17 03:19:07 PST 2004 
Responsible-Changed-Why:  
Release. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=26869 
Responsible-Changed-From-To: sheldonh->freebsd-bugs 
Responsible-Changed-By: sheldonh 
Responsible-Changed-When: Tue Feb 17 03:19:07 PST 2004 
Responsible-Changed-Why:  
Release. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=33672 
State-Changed-From-To: open->closed 
State-Changed-By: matteo 
State-Changed-When: Tue Feb 13 08:36:02 UTC 2007 
State-Changed-Why:  
telnetd was fixed back in 2002 (rev.1.16) and mdmfs doesn't need to be patched anymore. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=33672 
>Unformatted:
