|File: [cvs.NetBSD.org] / src / share / man / man7 / module.7 (download)
Revision 1.5, Tue Sep 22 08:29:30 2015 UTC (4 years, 10 months ago) by wiz
CVS Tags: prg-localcount2-base3, prg-localcount2-base2, prg-localcount2-base1, prg-localcount2-base, prg-localcount2, pgoyette-localcount-base, pgoyette-localcount-20170426, pgoyette-localcount-20170320, pgoyette-localcount-20170107, pgoyette-localcount-20161104, pgoyette-localcount-20160806, pgoyette-localcount-20160726, pgoyette-localcount, perseant-stdc-iso10646-base, perseant-stdc-iso10646, netbsd-8-base, netbsd-8-2-RELEASE, netbsd-8-1-RELEASE, netbsd-8-1-RC1, netbsd-8-0-RELEASE, netbsd-8-0-RC2, netbsd-8-0-RC1, netbsd-8, matt-nb8-mediatek-base, matt-nb8-mediatek, localcount-20160914, bouyer-socketcan-base1, bouyer-socketcan-base, bouyer-socketcan
Changes since 1.4: +2 -2
Bump date for previous.
.\" $NetBSD: module.7,v 1.5 2015/09/22 08:29:30 wiz Exp $
.\" Copyright (c) 2010 The NetBSD Foundation, Inc.
.\" All rights reserved.
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.Dd September 22, 2015
.Dt MODULE 7
.Nd Kernel Modules interface
.Cd "options MODULAR"
Kernel modules allow the system administrator to
dynamically add and remove functionality from a running system.
This also helps software developers add
new parts of the kernel without constantly rebooting to
test their changes.
The kernel may automatically load software modules as
needed to perform requested operations.
For example, an
module can be loaded automatically when an
attempt is made to mount an
Modules can also depend on other modules, and dependent modules are
When a module is no longer needed, it can be automatically unloaded.
An in-kernel linker resolves symbol references between the module
and the rest of the kernel.
interface is accessed with the
.Xr modctl 2
All common operations involving
kernel modules are handled by the
.Xr modload 8 ,
.Xr modunload 8 ,
.Xr modstat 8
Users should never have to interact with
.Xr modctl 2
.Sh MODULE CLASSES
.Ss Virtual File System modules
Virtual file systems may be added via the
.Ss Device Driver modules
Many device drivers can be loaded as a kernel module.
One potential problem specific to block and character device drivers
is that the device nodes must exist for the devices to be accessed.
These need to be created manually, after the driver module has been
Most device driver modules do not
need any manual intervention to function properly.
.Ss Execution Interpreters
Execution Interpreters can be loaded to provide support for executing
binaries not normally supported by the kernel.
This also allows loading
support for executing foreign system binaries.
Execution Interpreters may require that an appropriate
emulation module also be loaded.
.Ss Miscellaneous modules
Miscellaneous modules are modules for which there are not currently
well-defined or well-used interfaces for extension.
They are provided for extension, and the user-provided module
initialization routine is expected to install the necessary "hooks"
into the rest of the operating system.
An example of a "miscellaneous module" might be a loader for
card-specific VGA drivers or alternate terminal emulations in
an appropriately layered console driver.
.Ss Security-Model modules
Alternate system security models also may be loaded using
The common build tool of
.Dq build.sh ,
automatically compiles and installs all
modules during a full system build and install.
However, sometimes it is useful to update only modules.
The following example demonstrates one way to do this.
It is assumed that the source code is under
.Pa /usr/src ,
while the object and toolchain directories are under
.Pa /usr/tools ,
.Bd -literal -offset indent
.Sh SEE ALSO
.Xr modctl 2 ,
.Xr modload 8 ,
.Xr modstat 8 ,
.Xr modunload 8 ,
.Xr module 9
facility was designed to be similar in functionality
to the loadable kernel modules facility provided by
.Tn "SunOS 4.1.3" .
interface was replaced by
.Nx 5.0 .
subsystem was implemented by
.An Andrew Doran
.Aq firstname.lastname@example.org .
framework is still under active development.
At least two potential caveats can be mentioned.
.Bl -enum -offset 2n
Kernel modules are built to operate only with a specific version of the
When the kernel is updated to a new version, the contents of the
directory should be updated as well.
(This location has been the subject of much discussion, and may change
in future versions of
.Nx . )
If an attempt is made to boot the operating system from a file system for
which the module is not built into the kernel, the boot may fail
with the message
.Dq "Cannot mount root, error 79" .
On certain architectures (currently, i386 and amd64), one may be able to
recover from this error by using the
.Dq "load xxxfs"
command before trying to boot.
This command is only available on newer bootloaders.
The absence of required modules or the inability of the bootloader
to load the modules are common reasons for failures to boot a
It may be a good practice to maintain a non-MODULAR kernel
in the root file system for recovery purposes.
.Sh SECURITY CONSIDERATIONS
A module becomes part of the kernel once loaded.
Unlike in userland programs, fatal errors in kernel modules
may crash the operating system.
There is no memory protection between modules and the rest of the kernel.
Hence, a potential attacker with access to the
.Xr modctl 2
system call can acquire total control over the system.
To avoid such security risks, new modules can only be loaded when
is less than or equal to zero, or if the kernel was built with
.Cd options INSECURE .
.Xr secmodel_securelevel 9
for additional details on the
.Pa securelevel .
Only use modules from trusted sources.