Bug #174

Unloading md module causes a panic

Added by swildner about 12 years ago. Updated over 8 years ago.

Target version:
Start date:
Due date:
% Done:


Estimated time:



the following sequence of commands easily make my box (running HEAD) panic:

# kldload md
# kldunload md

Backtrace and dump available.


md_module.jpg (118 KB) md_module.jpg tuxillo, 01/22/2009 12:20 AM


#1 Updated by justin over 12 years ago

Still present on 1.6.2-RELEASE, as I just found out.

#2 Updated by corecode over 12 years ago

md does not have any means to be unloaded. we should either prevent that or add
unload code.

#3 Updated by aix-d over 12 years ago

how to reproduce kernel panic on 1.9.0-DEVEL:

cd /dev
sh MAKEDEV md0
disklabel md0

#4 Updated by tuxillo over 12 years ago

Still happening on 2.0.1
See attached image.

#5 Updated by nthery over 12 years ago

2009/1/22 Antonio Huete Jimenez (via DragonFly issue tracker)
> Antonio Huete Jimenez <> added the comment:
> Still happening on 2.0.1
> See attached image.

I can reproduce it if and only if md is already compiled in the kernel.

What happens is that when kldloading md, the kernel tries to register
the debug.mddebug sysctl a second time (as md is already in the
kernel). It complains (the "can't re-use a leaf" msg) and stops the
registration but carries on loading the module.

When kldunloading, the kernel tries to unregister the module instance
of debug.mddebug and panics because it was not registered in the first

Is there a way to detect during kldload that the module is already
part of the kernel?

I propose to close this bug as it is caused by incorrect user manipulation.

#6 Updated by nthery over 12 years ago

Well, actually as Simon mentioned earlier, md has not been updated to
work as a module and it leaks memory when unloaded. I'm looking into

#7 Updated by alexh over 12 years ago

Any news about this? If not, disabling the option to unload should be trivial
and would offer a quick fix.

Alex Hornung

#8 Updated by tuxillo over 12 years ago


I think what is happening here is , despite md is already included in the
kernel, the module is not registered and thus modlist_lookup2() doesn't find it,
so kldload() syscall succeeds instead of failing in EEXIST as it should be.

I'm going to try to provide a patch to fix this based on some recommendatiosn
given by Alex.

Antonio Huete

#9 Updated by tuxillo over 12 years ago

Committed a fix on 89adea1539ab67184124a82cc811031f3334024f

Also available in: Atom PDF