xref: /netbsd-src/share/man/man7/module.7 (revision 78e3bc6422c48794a971c2fa1aba250cbddf127f)
1*78e3bc64Spgoyette.\" $NetBSD: module.7,v 1.9 2020/07/13 13:42:51 pgoyette Exp $
2674e0899Sjruoho.\"
37ebf1407Spgoyette.\" Copyright (c) 2010 The NetBSD Foundation, Inc.
4674e0899Sjruoho.\" All rights reserved.
5674e0899Sjruoho.\"
6674e0899Sjruoho.\" Redistribution and use in source and binary forms, with or without
7674e0899Sjruoho.\" modification, are permitted provided that the following conditions
8674e0899Sjruoho.\" are met:
9674e0899Sjruoho.\" 1. Redistributions of source code must retain the above copyright
10674e0899Sjruoho.\"    notice, this list of conditions and the following disclaimer.
11674e0899Sjruoho.\" 2. Redistributions in binary form must reproduce the above copyright
12674e0899Sjruoho.\"    notice, this list of conditions and the following disclaimer in the
13674e0899Sjruoho.\"    documentation and/or other materials provided with the distribution.
14674e0899Sjruoho.\"
157ebf1407Spgoyette.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
167ebf1407Spgoyette.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
177ebf1407Spgoyette.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
187ebf1407Spgoyette.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
197ebf1407Spgoyette.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
207ebf1407Spgoyette.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
217ebf1407Spgoyette.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
227ebf1407Spgoyette.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
237ebf1407Spgoyette.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
247ebf1407Spgoyette.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
257ebf1407Spgoyette.\" POSSIBILITY OF SUCH DAMAGE.
26674e0899Sjruoho.\"
27f2ada8aeSjruoho.Dd July 13, 2020
28674e0899Sjruoho.Dt MODULE 7
29674e0899Sjruoho.Os
30674e0899Sjruoho.Sh NAME
31674e0899Sjruoho.Nm module
32674e0899Sjruoho.Nd Kernel Modules interface
33674e0899Sjruoho.Sh SYNOPSIS
34674e0899Sjruoho.Cd "options MODULAR"
35674e0899Sjruoho.Sh DESCRIPTION
36674e0899SjruohoKernel modules allow the system administrator to
37674e0899Sjruohodynamically add and remove functionality from a running system.
380ab10d25SpgoyetteThis also helps software developers add
39674e0899Sjruohonew parts of the kernel without constantly rebooting to
40674e0899Sjruohotest their changes.
41674e0899Sjruoho.Pp
420ab10d25SpgoyetteThe kernel may automatically load software modules as
43674e0899Sjruohoneeded to perform requested operations.
44674e0899SjruohoFor example, an
45674e0899Sjruoho.Dq xyzfs
46674e0899Sjruohomodule can be loaded automatically when an
47674e0899Sjruohoattempt is made to mount an
48674e0899Sjruoho.Dq xyzfs
49674e0899Sjruohofile system.
504cbd24b2SwizModules can also depend on other modules, and dependent modules are
51674e0899Sjruohoautomatically loaded.
52674e0899SjruohoWhen a module is no longer needed, it can be automatically unloaded.
53674e0899Sjruoho.Pp
54674e0899SjruohoAn in-kernel linker resolves symbol references between the module
55674e0899Sjruohoand the rest of the kernel.
56674e0899Sjruoho.Pp
57674e0899SjruohoThe
58674e0899Sjruoho.Nm
59674e0899Sjruohointerface is accessed with the
60674e0899Sjruoho.Xr modctl 2
61674e0899Sjruohosystem call.
62674e0899SjruohoAll common operations involving
63674e0899Sjruohokernel modules are handled by the
64674e0899Sjruoho.Xr modload 8 ,
65674e0899Sjruoho.Xr modunload 8 ,
66674e0899Sjruohoand
67674e0899Sjruoho.Xr modstat 8
68674e0899Sjruohoprograms.
69674e0899SjruohoUsers should never have to interact with
70674e0899Sjruoho.Xr modctl 2
71674e0899Sjruohodirectly.
72674e0899Sjruoho.Sh MODULE CLASSES
73674e0899Sjruoho.Ss Virtual File System modules
74674e0899SjruohoVirtual file systems may be added via the
75674e0899Sjruoho.Nm
76674e0899Sjruohointerface.
77674e0899Sjruoho.Ss Device Driver modules
78674e0899SjruohoMany device drivers can be loaded as a kernel module.
79674e0899SjruohoOne potential problem specific to block and character device drivers
80674e0899Sjruohois that the device nodes must exist for the devices to be accessed.
81674e0899SjruohoThese need to be created manually, after the driver module has been
82674e0899Sjruohosuccessfully loaded.
830ab10d25SpgoyetteMost device driver modules do not
84674e0899Sjruohoneed any manual intervention to function properly.
85674e0899Sjruoho.Ss Execution Interpreters
86674e0899SjruohoExecution Interpreters can be loaded to provide support for executing
870ab10d25Spgoyettebinaries not normally supported by the kernel.
88674e0899SjruohoThis also allows loading
89674e0899Sjruohosupport for executing foreign system binaries.
90674e0899SjruohoExecution Interpreters may require that an appropriate
91674e0899Sjruohoemulation module also be loaded.
92674e0899Sjruoho.Ss Miscellaneous modules
93674e0899SjruohoMiscellaneous modules are modules for which there are not currently
94674e0899Sjruohowell-defined or well-used interfaces for extension.
95674e0899SjruohoThey are provided for extension, and the user-provided module
96674e0899Sjruohoinitialization routine is expected to install the necessary "hooks"
97674e0899Sjruohointo the rest of the operating system.
98674e0899SjruohoAn example of a "miscellaneous module" might be a loader for
99674e0899Sjruohocard-specific VGA drivers or alternate terminal emulations in
100674e0899Sjruohoan appropriately layered console driver.
101674e0899Sjruoho.Ss Security-Model modules
1020ab10d25SpgoyetteAlternate system security models also may be loaded using
1030ab10d25Spgoyette.Nm .
104674e0899Sjruoho.Sh EXAMPLES
105674e0899SjruohoThe common build tool of
106674e0899Sjruoho.Nx ,
107674e0899Sjruoho.Dq build.sh ,
108dbfbddfdSpgoyetteautomatically compiles and installs most
109674e0899Sjruohomodules during a full system build and install.
110dbfbddfdSpgoyette(The exceptions are some modules from external sources which, due to
111dbfbddfdSpgoyettelicensing concerns, can be built only as separately-loaded modules.)
1120ab10d25SpgoyetteHowever, sometimes it is useful to update only modules.
113674e0899SjruohoThe following example demonstrates one way to do this.
114674e0899SjruohoIt is assumed that the source code is under
115674e0899Sjruoho.Pa /usr/src ,
116674e0899Sjruohowhile the object and toolchain directories are under
117674e0899Sjruoho.Pa /usr/obj
118674e0899Sjruohoand
119674e0899Sjruoho.Pa /usr/tools ,
120674e0899Sjruohorespectively.
121674e0899Sjruoho.Bd -literal -offset indent
122674e0899Sjruohocd /usr/src/sys/modules
123674e0899Sjruoho
124674e0899Sjruohoexport OBJDIR=/usr/obj
125674e0899Sjruohoexport TOOLDIR=/usr/tools
126674e0899Sjruoho
127674e0899Sjruohomake clean
128674e0899Sjruohomake
129674e0899Sjruohomake install
130674e0899Sjruoho.Ed
131dbfbddfdSpgoyette.Pp
132dbfbddfdSpgoyetteAlternatively, the
133dbfbddfdSpgoyette.Dq build.sh
134*78e3bc64Spgoyettetool can be used to build and install only the modules:
135dbfbddfdSpgoyette.Bd -literal -offset indent
136dbfbddfdSpgoyettecd /usr/src
137dbfbddfdSpgoyette\&./build.sh -O /usr/obj -T /usr/tools modules
138f2ada8aeSjruoho\&./build.sh -O /usr/obj -T /usr/tools installmodules=/
139dbfbddfdSpgoyette.Ed
140674e0899Sjruoho.Sh SEE ALSO
141674e0899Sjruoho.Xr modctl 2 ,
142674e0899Sjruoho.Xr modload 8 ,
143674e0899Sjruoho.Xr modstat 8 ,
144674e0899Sjruoho.Xr modunload 8 ,
145674e0899Sjruoho.Xr module 9
146674e0899Sjruoho.Sh HISTORY
147674e0899SjruohoThe
148674e0899Sjruoho.Nm
149674e0899Sjruohofacility was designed to be similar in functionality
150674e0899Sjruohoto the loadable kernel modules facility provided by
1511209ffc3SwizSunOS 4.1.3.
152674e0899SjruohoThe old
153674e0899Sjruoho.Dv LKM
154674e0899Sjruohointerface was replaced by
155674e0899Sjruoho.Nm
156674e0899Sjruohoin
157674e0899Sjruoho.Nx 5.0 .
158674e0899Sjruoho.Sh AUTHORS
159674e0899SjruohoThe
160674e0899Sjruoho.Nm
161674e0899Sjruohosubsystem was implemented by
162674e0899Sjruoho.An Andrew Doran
163674e0899Sjruoho.Aq ad@netbsd.org .
164674e0899Sjruoho.Sh CAVEATS
165674e0899SjruohoThe
166674e0899Sjruoho.Nm
167674e0899Sjruohoframework is still under active development.
168674e0899SjruohoAt least two potential caveats can be mentioned.
169674e0899Sjruoho.Bl -enum -offset 2n
170674e0899Sjruoho.It
171674e0899SjruohoKernel modules are built to operate only with a specific version of the
172674e0899Sjruoho.Nx
173674e0899Sjruohokernel.
174674e0899SjruohoWhen the kernel is updated to a new version, the contents of the
175674e0899Sjruoho.Pa /stand/${ARCH}/${VERSION}/modules/
176674e0899Sjruohodirectory should be updated as well.
177674e0899Sjruoho(This location has been the subject of much discussion, and may change
178674e0899Sjruohoin future versions of
179674e0899Sjruoho.Nx . )
180674e0899Sjruoho.It
181674e0899SjruohoIf an attempt is made to boot the operating system from a file system for
182674e0899Sjruohowhich the module is not built into the kernel, the boot may fail
183674e0899Sjruohowith the message
184674e0899Sjruoho.Dq "Cannot mount root, error 79" .
185674e0899SjruohoOn certain architectures (currently, i386 and amd64), one may be able to
186674e0899Sjruohorecover from this error by using the
187674e0899Sjruoho.Dq "load xxxfs"
188674e0899Sjruohocommand before trying to boot.
189674e0899SjruohoThis command is only available on newer bootloaders.
190674e0899Sjruoho.El
191674e0899Sjruoho.Pp
192674e0899SjruohoThe absence of required modules or the inability of the bootloader
193674e0899Sjruohoto load the modules are common reasons for failures to boot a
194674e0899Sjruoho.Cd MODULAR
195674e0899Sjruohokernel.
196674e0899SjruohoIt may be a good practice to maintain a non-MODULAR kernel
197674e0899Sjruohoin the root file system for recovery purposes.
198674e0899Sjruoho.Sh SECURITY CONSIDERATIONS
199674e0899SjruohoA module becomes part of the kernel once loaded.
2000ab10d25SpgoyetteUnlike in userland programs, fatal errors in kernel modules
2010ab10d25Spgoyettemay crash the operating system.
202674e0899SjruohoThere is no memory protection between modules and the rest of the kernel.
203674e0899SjruohoHence, a potential attacker with access to the
204674e0899Sjruoho.Xr modctl 2
2050ab10d25Spgoyettesystem call can acquire total control over the system.
206674e0899Sjruoho.Pp
2070ab10d25SpgoyetteTo avoid such security risks, new modules can only be loaded when
208674e0899Sjruoho.Pa securelevel
209674e0899Sjruohois less than or equal to zero, or if the kernel was built with
210674e0899Sjruoho.Cd options INSECURE .
211674e0899SjruohoRefer to
212674e0899Sjruoho.Xr secmodel_securelevel 9
213674e0899Sjruohofor additional details on the
214674e0899Sjruoho.Pa securelevel .
2151209ffc3SwizOnly use modules from trusted sources.
216