Bug 24392

Summary: panic() if kldload used to load module which is already compiled into kernel
Product: Base System Reporter: nick <nick>
Component: kernAssignee: freebsd-bugs (Nobody) <bugs>
Status: Closed FIXED    
Severity: Affects Only Me    
Priority: Normal    
Version: 4.2-STABLE   
Hardware: Any   
OS: Any   

Description nick 2001-01-16 20:20:02 UTC
	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).

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.
How-To-Repeat: 
	Create kernel with ipfw compiled in statically, then:
	# kldload ipfw
	# kldunload ipfw
	<bang!>
Comment 1 dwmalone 2001-11-02 14:48:25 UTC
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.
Comment 2 Luigi Rizzo freebsd_committer freebsd_triage 2001-11-22 23:15:15 UTC
State Changed
From-To: open->closed

Just committed a fix for stable.