From nick@pancake.netability.ie  Tue Jan 16 12:13:55 2001
Return-Path: <nick@pancake.netability.ie>
Received: from pancake.netability.ie (unknown [159.134.183.12])
	by hub.freebsd.org (Postfix) with ESMTP id 9041537B401
	for <FreeBSD-gnats-submit@freebsd.org>; Tue, 16 Jan 2001 12:13:52 -0800 (PST)
Received: (from nick@localhost)
	by pancake.netability.ie (8.11.1/8.11.0) id f0GKDqG04219;
	Tue, 16 Jan 2001 20:13:52 GMT
	(envelope-from nick)
Message-Id: <200101162013.f0GKDqG04219@pancake.netability.ie>
Date: Tue, 16 Jan 2001 20:13:52 GMT
From: nick@netability.ie
Reply-To: nick@netability.ie
To: FreeBSD-gnats-submit@freebsd.org
Subject: bogons in kernel linker
X-Send-Pr-Version: 3.2

>Number:         24392
>Category:       kern
>Synopsis:       panic() if kldload used to load module which is already compiled into kernel
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue Jan 16 12:20:02 PST 2001
>Closed-Date:    Thu Nov 22 15:15:15 PST 2001
>Last-Modified:  Thu Nov 22 15:15:57 PST 2001
>Originator:     Nick Hilliard
>Release:        FreeBSD 4.2-STABLE i386
>Organization:
Network Ability Ltd.
>Environment:

	ipfw statically compiled into kernel

>Description:

	FreeBSD will reliably panic if ipfw is compiled into the kernel, and
	if an attempt is then made to load it dynamically and then unload it
	using kldload/kldunload. Looking at the code, I'd say that there was
	nothing particularly special about ipfw, and that it was a more generic
	problem which affects all kernel modules which register sysctls.

	What appears to be happening is this:

	"kldload ipfw" attempts to register ipfw module.  This first
	registers all of the sysctls (kern/kern_linker.c:284 in
	linker_load_file()), and the on the next line attempts to initialise
	the module using linker_file_sysinit().  This function calls
	module_register() which then returns an error (EEXIST), but this
	error is ignored, and the registration of the module completes
	further on down the function (oopsie - this is bad!)

	"kldload ipfw" then unloads the kernel module and de-registers the
	sysctls which are in use by the statically compiled ipfw module, and 
	panic occurs (didn't get any time to look into what's going on
	here).
	

>How-To-Repeat:

	Create kernel with ipfw compiled in statically, then:
	# kldload ipfw
	# kldunload ipfw
	<bang!>

>Fix:

	Ran out of time for a fix. Looks relatively easy to put in a quick
	fix, but I'm not familiar enough with the code to feel confident
	about fixing it - it's very likely that some sublety has escaped me.


>Release-Note:
>Audit-Trail:

From: David Malone <dwmalone@maths.tcd.ie>
To: freebsd-gnats-submit@FreeBSD.org
Cc: nick@netability.ie
Subject: Re: kern/24392: panic() if kldload used to load module which is already compiled into kernel
Date: Fri, 02 Nov 2001 14:48:25 +0000

 Just to note that this issure also arose in PRs 31566, 31166 and
 25130 in relation to the vesa, smbfs and md modules. I have closed
 these as duplicates of this PR.
 
 	David.
State-Changed-From-To: open->closed 
State-Changed-By: luigi 
State-Changed-When: Thu Nov 22 15:15:15 PST 2001 
State-Changed-Why:  
Just committed a fix for stable. 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=24392 
>Unformatted:
