From chris@haakonia.hitnet.rwth-aachen.de  Sat Apr  2 23:08:36 2005
Return-Path: <chris@haakonia.hitnet.rwth-aachen.de>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 00E3C16A4CE
	for <FreeBSD-gnats-submit@freebsd.org>; Sat,  2 Apr 2005 23:08:36 +0000 (GMT)
Received: from ms-dienst.rz.rwth-aachen.de (ms-2.rz.RWTH-Aachen.DE [134.130.3.131])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 7E1D843D41
	for <FreeBSD-gnats-submit@freebsd.org>; Sat,  2 Apr 2005 23:08:35 +0000 (GMT)
	(envelope-from chris@haakonia.hitnet.rwth-aachen.de)
Received: from r220-1 (r220-1.rz.RWTH-Aachen.DE [134.130.3.31])
 by ms-dienst.rz.rwth-aachen.de
 (iPlanet Messaging Server 5.2 HotFix 1.12 (built Feb 13 2003))
 with ESMTP id <0IEC006P4DM916@ms-dienst.rz.rwth-aachen.de> for
 FreeBSD-gnats-submit@freebsd.org; Sun, 03 Apr 2005 01:08:34 +0200 (MEST)
Received: from relay.rwth-aachen.de ([134.130.3.1])
	by r220-1 (MailMonitor for SMTP v1.2.2 ) ; Sun,
 03 Apr 2005 01:08:33 +0200 (MEST)
Received: from haakonia.hitnet.rwth-aachen.de
 (haakonia.hitnet.RWTH-Aachen.DE [137.226.181.92])
	by relay.rwth-aachen.de (8.13.3/8.13.3/1) with ESMTP id j32N8XT5020959	for
 <FreeBSD-gnats-submit@freebsd.org>; Sun, 03 Apr 2005 01:08:33 +0200 (MEST)
Received: by haakonia.hitnet.rwth-aachen.de (Postfix, from userid 1001)
	id D425828452; Sun, 03 Apr 2005 01:08:27 +0200 (CEST)
Message-Id: <20050402230827.D425828452@haakonia.hitnet.rwth-aachen.de>
Date: Sun, 03 Apr 2005 01:08:27 +0200 (CEST)
From: Christian Brueffer <chris@unixpages.org>
Reply-To: Christian Brueffer <chris@unixpages.org>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: [PATCH] Reproducible if_tun panic
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         79493
>Category:       kern
>Synopsis:       [if_tun] [patch] Reproducible if_tun panic
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sat Apr 02 23:10:02 GMT 2005
>Closed-Date:    Tue Aug 08 17:19:16 GMT 2006
>Last-Modified:  Tue Aug 08 17:19:16 GMT 2006
>Originator:     Christian Brueffer
>Release:        FreeBSD 5.3-STABLE i386
>Organization:
>Environment:
	
>Description:
	It's possible to trigger a panic by kldload'ing if_tun
	if it is already compiled into the kernel or loaded as
	a module.
	This doesn't happen on 5.4-PRERELEASE systems.
>How-To-Repeat:
	kldload if_tun
	
>Fix:
The following patch works for me, though I'm not sure it's
the correct thing to do.

Index: if_tun.c
===================================================================
RCS file: /data/ncvs/freebsd/src/sys/net/if_tun.c,v
retrieving revision 1.149
diff -u -r1.149 if_tun.c
--- if_tun.c    31 Mar 2005 12:19:44 -0000      1.149
+++ if_tun.c    2 Apr 2005 23:05:32 -0000
@@ -856,3 +856,5 @@
        splx(s);
        return (revents);
 }
+
+MODULE_VERSION(tun, 1);
	



>Release-Note:
>Audit-Trail:

From: Christian Brueffer <chris@unixpages.org>
To: FreeBSD-gnats-submit@FreeBSD.org, freebsd-bugs@FreeBSD.org
Cc:  
Subject: Re: kern/79493: [PATCH] Reproducible if_tun panic
Date: Mon, 04 Apr 2005 14:37:55 +0200

 --AdjLlRqdF7kYRNze
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: inline
 Content-Transfer-Encoding: quoted-printable
 
 More information:
 
 The kernel config is located here:
 
 http://people.freebsd.org/~brueffer/FANGORN
 
 The stack trace for the panic:
 
 module_register: module if_tun already exists!
 Module if_tun failed to register: 17
 can't re-use a leaf (if_run_debug)!
 panic: mutex "tunmtx" 0xc089c780 already initialized
 KDB: enter: panic
 [thread pid 525 tid 100078]
 Stopped at      kdb_enter+0x30: leave
 db> tr
 Tracing pid 525 tid 100078 0xc1be1a10
 kdb_enter()
 panic()
 mtx_init()
 tunmodevent()
 module_register_init()
 linker_file_sysinit()
 linker_load_file()
 linker_load_module()
 kldload()
 syscall()
 Xint0x80_syscall()
 
 - Christian
 
 --=20
 Christian Brueffer	chris@unixpages.org	brueffer@FreeBSD.org
 GPG Key:	 http://people.freebsd.org/~brueffer/brueffer.key.asc
 GPG Fingerprint: A5C8 2099 19FF AACA F41B  B29B 6C76 178C A0ED 982D
 
 --AdjLlRqdF7kYRNze
 Content-Type: application/pgp-signature
 Content-Disposition: inline
 
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v1.4.0 (FreeBSD)
 
 iD8DBQFCUTUibHYXjKDtmC0RAkhbAKCoq5x16YB4lWVQxZFDv+V606x5IQCgh6OF
 +DTXSj6OrvNWnFcvdpa75oU=
 =x1f2
 -----END PGP SIGNATURE-----
 
 --AdjLlRqdF7kYRNze--
 

From: "Wojciech A. Koszek" <dunstan@freebsd.czest.pl>
To: freebsd-gnats-submit@FreeBSD.org, chris@unixpages.org
Cc:  
Subject: Re: kern/79493: [PATCH] Reproducible if_tun panic
Date: Mon, 4 Apr 2005 16:39:31 +0000

 Hello Christian,
 Thanks for additional information! As I said in my mail, it because of
 mutex initialization, which is done twice -- either while loading if_tun.ko,
 or if_ppp.ko. I reported this earlier to one of developers, but even I
 didn't like my patches. It only happens with debugging options enabled in
 your kernel configuration. This is due assertion made in mtx_init()
 (/sys/kern/kern_mutex.c):
 
         KASSERT((lock->lo_flags & LO_INITIALIZED) == 0,
             ("mutex \"%s\" %p already initialized", name, m));
 
 Christian proposed solution with MODULE_VERSION, but my question is: do we
 really need KASSERT in mtx_init()? Couldn't it just be replaced with
 conditional printf()?:
 http://freebsd.czest.pl/dunstan/FreeBSD/diff.0.kern_mutex.c
 
 Regards,
 -- 
 * Wojciech A. Koszek && dunstan@FreeBSD.czest.pl
State-Changed-From-To: open->closed 
State-Changed-By: jhb 
State-Changed-When: Tue Aug 8 17:18:39 UTC 2006 
State-Changed-Why:  
Submitter reports this was fixed in 5.4-PRELEASE and later, and at this 
point we aren't going to fix a panic like this in the 5.3 branch. 

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