A loadable kernel module (LKM) is an
executable
In computer science, executable code, an executable file, or an executable program, sometimes simply referred to as an executable or binary, causes a computer "to perform indicated tasks according to encoded instruction (computer science), in ...
library
A library is a collection of Book, books, and possibly other Document, materials and Media (communication), media, that is accessible for use by its members and members of allied institutions. Libraries provide physical (hard copies) or electron ...
that
extends the capabilities of a running
kernel, or so-called ''base kernel'', of an
operating system
An operating system (OS) is system software that manages computer hardware and software resources, and provides common daemon (computing), services for computer programs.
Time-sharing operating systems scheduler (computing), schedule tasks for ...
. LKMs are typically used to add support for new
hardware (as
device driver
In the context of an operating system, a device driver is a computer program that operates or controls a particular type of device that is attached to a computer or automaton. A driver provides a software interface to hardware devices, enabli ...
s) and/or
filesystems, or for adding
system call
In computing, a system call (syscall) is the programmatic way in which a computer program requests a service from the operating system on which it is executed. This may include hardware-related services (for example, accessing a hard disk drive ...
s. When the functionality provided by an LKM is no longer required, it can be unloaded in order to free
memory
Memory is the faculty of the mind by which data or information is encoded, stored, and retrieved when needed. It is the retention of information over time for the purpose of influencing future action. If past events could not be remembe ...
and other resources.
Most current
Unix-like
A Unix-like (sometimes referred to as UN*X, *nix or *NIX) operating system is one that behaves in a manner similar to a Unix system, although not necessarily conforming to or being certified to any version of the Single UNIX Specification. A Uni ...
systems and
Windows
Windows is a Product lining, product line of Proprietary software, proprietary graphical user interface, graphical operating systems developed and marketed by Microsoft. It is grouped into families and subfamilies that cater to particular sec ...
support loadable kernel modules but with different names, such as kernel loadable module (kld) in
FreeBSD
FreeBSD is a free-software Unix-like operating system descended from the Berkeley Software Distribution (BSD). The first version was released in 1993 developed from 386BSD, one of the first fully functional and free Unix clones on affordable ...
, kernel extension (kext) in
macOS
macOS, previously OS X and originally Mac OS X, is a Unix, Unix-based operating system developed and marketed by Apple Inc., Apple since 2001. It is the current operating system for Apple's Mac (computer), Mac computers. With ...
(although support for third-party modules is being dropped), kernel extension module in
AIX, dynamically loadable kernel module in
HP-UX
HP-UX (from "Hewlett Packard Unix") is a proprietary software, proprietary implementation of the Unix operating system developed by Hewlett Packard Enterprise; current versions support HPE Integrity Servers, based on Intel's Itanium architect ...
, kernel-mode driver in
Windows NT
Windows NT is a Proprietary software, proprietary Graphical user interface, graphical operating system produced by Microsoft as part of its Windows product line, the first version of which, Windows NT 3.1, was released on July 27, 1993. Original ...
and downloadable kernel module (DKM) in
VxWorks
VxWorks is a real-time operating system (or RTOS) developed as proprietary software by Wind River Systems, a subsidiary of Aptiv. First released in 1987, VxWorks is designed for use in embedded systems requiring real-time, Deterministic system, ...
. They are also known as kernel loadable module (KLM), or simply as kernel module (KMOD).
Advantages
Without loadable kernel modules, an operating system would have to include all possible anticipated functionality compiled directly into the base kernel. Much of that functionality would reside in memory without being used, wasting memory , and would require that users rebuild and reboot the base kernel every time they require new functionality.
Disadvantages
One minor criticism of preferring a modular kernel over a static kernel is the so-called ''
fragmentation penalty''. The base kernel is always unpacked into real contiguous
memory
Memory is the faculty of the mind by which data or information is encoded, stored, and retrieved when needed. It is the retention of information over time for the purpose of influencing future action. If past events could not be remembe ...
by its setup routines; thus, the base kernel code is never fragmented. Once the system is in a state in which modules may be inserted, for example once the
filesystems have been
mounted that contain the modules, it is likely that any new kernel code insertion will cause the kernel to become fragmented, thereby introducing a minor performance penalty by using more
TLB entries, causing more TLB misses.
Implementations in different operating systems
Linux
Loadable kernel modules in Linux are loaded (and unloaded) by the
modprobe
command. They are located in
/lib/modules
or
/usr/lib/modules
and have had the extension
.ko
("kernel object") since version 2.6 (previous versions used the
.o
extension). The
lsmod
command lists the loaded kernel modules. In emergency cases, when the system fails to boot due to e.g. broken modules, specific modules can be enabled or disabled by modifying the kernel boot parameters list (for example, if using
GRUB, by pressing 'e' in the GRUB start menu, then editing the kernel parameter line).
License issues
In the opinion of Linux maintainers, LKM are
derived works of the kernel. The Linux maintainers tolerate the distribution of
proprietary modules (such as
NVIDIA GPU
This list contains general information about graphics processing units (GPUs) and video cards from Nvidia, based on official specifications. In addition some Comparison of Nvidia nForce chipsets, Nvidia motherboards come with integrated onboard GP ...
drivers), but allow only
GNU General Public License
The GNU General Public Licenses (GNU GPL or simply GPL) are a series of widely used free software licenses, or ''copyleft'' licenses, that guarantee end users the freedom to run, study, share, or modify the software. The GPL was the first ...
(GPL) modules to merge to kernel tree of mainline Linux kernel.
Loading a proprietary or non-GPL-compatible module will set a 'taint' flag in the running kernel—meaning that any problems or bugs experienced will be less likely to be investigated by the maintainers. LKMs effectively become part of the running kernel, so can corrupt kernel data structures and produce bugs that may not be able to be investigated if the module is indeed proprietary.
Linuxant controversy
In 2004, Linuxant, a consulting company that releases proprietary
device driver
In the context of an operating system, a device driver is a computer program that operates or controls a particular type of device that is attached to a computer or automaton. A driver provides a software interface to hardware devices, enabli ...
s as loadable kernel modules, attempted to abuse a
null terminator in their
MODULE_LICENSE
, as visible in the following code excerpt:
MODULE_LICENSE("GPL\0for files in the \"GPL\" directory; for others, only LICENSE file applies");
The string comparison code used by the kernel at the time tried to determine whether the module was GPLed stopped when it reached a null character (
\0
), so it was fooled into thinking that the module was declaring its license to be just "GPL".
FreeBSD
Kernel modules for
FreeBSD
FreeBSD is a free-software Unix-like operating system descended from the Berkeley Software Distribution (BSD). The first version was released in 1993 developed from 386BSD, one of the first fully functional and free Unix clones on affordable ...
are stored within
/boot/kernel/
for modules distributed with the
operating system
An operating system (OS) is system software that manages computer hardware and software resources, and provides common daemon (computing), services for computer programs.
Time-sharing operating systems scheduler (computing), schedule tasks for ...
, or usually
/boot/modules/
for modules installed from
FreeBSD ports
The FreeBSD Ports collection is a package management system for the FreeBSD operating system. Ports in the collection vary with contributed software. There were 38,487 ports available in February 2020 and 36,504 in September 2024. It has also be ...
or
FreeBSD packages, or for proprietary or otherwise binary-only modules. FreeBSD kernel modules usually have the extension
.ko
. Once the machine has booted, they may be loaded with the
kldload
command, unloaded with
kldunload
, and listed with
kldstat
. Modules can also be loaded from the loader before the kernel starts, either automatically (through
/boot/loader.conf
) or by hand.
macOS
Some loadable kernel modules in macOS can be loaded automatically. Loadable kernel modules can also be loaded by the
kextload
command. They can be listed by the
kextstat
command. Loadable kernel modules are located in
bundles with the extension
.kext
. Modules supplied with the operating system are stored in the
/System/Library/Extensions
directory; modules supplied by third parties are in various other directories.
NetWare
A NetWare kernel module is referred to as a
NetWare Loadable Module (NLM). NLMs are inserted into the NetWare kernel by means of the LOAD command, and removed by means of the UNLOAD command; the
modules
command lists currently loaded kernel modules. NLMs may reside in any valid search path assigned on the NetWare server, and they have
.NLM
as the file name extension.
VxWorks
A downloadable kernel module (DKM) type project can be created to generate a ".out" file which can then be loaded to kernel space using "ld" command. This downloadable kernel module can be unloaded using "unld" command.
Solaris
Solaris has a configurable kernel module load path, which defaults to
/platform/platform-name/kernel /kernel /usr/kernel
. Most kernel modules live in subdirectories under
/kernel
; those not considered necessary to boot the system to the point that init can start are often (but not always) found in
/usr/kernel
. When running a DEBUG kernel build the system actively attempts to unload modules.
Binary compatibility
Linux does not provide a stable
API
An application programming interface (API) is a connection between computers or between computer programs. It is a type of software interface, offering a service to other pieces of software. A document or standard that describes how to build ...
or
ABI for kernel modules. This means that there are differences in internal structure and function between different kernel versions, which can cause compatibility problems. In an attempt to combat those problems, symbol versioning data is placed within the
.modinfo
section of loadable
ELF
An elf (: elves) is a type of humanoid supernatural being in Germanic peoples, Germanic folklore. Elves appear especially in Norse mythology, North Germanic mythology, being mentioned in the Icelandic ''Poetic Edda'' and the ''Prose Edda'' ...
modules. This versioning information can be compared with that of the running kernel before loading a module; if the versions are incompatible, the module will not be loaded.
Other operating systems, such as
Solaris,
FreeBSD
FreeBSD is a free-software Unix-like operating system descended from the Berkeley Software Distribution (BSD). The first version was released in 1993 developed from 386BSD, one of the first fully functional and free Unix clones on affordable ...
,
macOS
macOS, previously OS X and originally Mac OS X, is a Unix, Unix-based operating system developed and marketed by Apple Inc., Apple since 2001. It is the current operating system for Apple's Mac (computer), Mac computers. With ...
, and
Windows
Windows is a Product lining, product line of Proprietary software, proprietary graphical user interface, graphical operating systems developed and marketed by Microsoft. It is grouped into families and subfamilies that cater to particular sec ...
keep the kernel
API
An application programming interface (API) is a connection between computers or between computer programs. It is a type of software interface, offering a service to other pieces of software. A document or standard that describes how to build ...
and
ABI relatively stable, thus avoiding this problem. For example,
FreeBSD
FreeBSD is a free-software Unix-like operating system descended from the Berkeley Software Distribution (BSD). The first version was released in 1993 developed from 386BSD, one of the first fully functional and free Unix clones on affordable ...
kernel modules compiled against kernel version 6.0 will work without recompilation on any other FreeBSD 6.x version, e.g. 6.4. However, they are not compatible with other major versions and must be recompiled for use with FreeBSD 7.x, as API and ABI compatibility is maintained only within a branch.
Security
While loadable kernel modules are a convenient method of modifying the running kernel, this can be abused by attackers on a compromised system to prevent detection of their
processes or
files, allowing them to maintain control over the system. Many
rootkit
A rootkit is a collection of computer software, typically malicious, designed to enable access to a computer or an area of its software that is not otherwise allowed (for example, to an unauthorized user) and often masks its existence or the exist ...
s make use of LKMs in this way. Note that, on most operating systems, modules do not help
privilege elevation in any way, as elevated privilege is required to load a LKM; they merely make it easier for the attacker to hide the break-in.
Linux
Linux allows disabling module loading via
sysctl option
/proc/sys/kernel/modules_disabled
. An
initramfs system may load specific modules needed for a machine at boot and then disable module loading. This makes the security very similar to a monolithic kernel. If an attacker can change the initramfs, they can change the kernel binary.
macOS
In
OS X Yosemite
OS X Yosemite ( ; version 10.10) is the eleventh major release of macOS, Apple Inc.'s desktop and server operating system for Macintosh computers.
OS X Yosemite was announced and released to developers on June 2, 2014, at WWDC 2014 and re ...
and later releases, a kernel extension has to be
code-signed with a developer certificate that holds a particular "entitlement." Such a developer certificate is only provided by Apple on request and not automatically given to
Apple Developer
Apple Developer (formerly Apple Developer Connection) is Apple Inc.'s website for software development tools, application programming interfaces (APIs), and technical resources. It contains resources to help software developers write software for ...
members. This feature, called "kext signing", is enabled by default and it instructs the kernel to stop booting if unsigned kernel extensions are present. In
El Capitan and later releases, it is part of
System Integrity Protection.
In older versions of macOS, or if kext signing is disabled, a loadable kernel module in a kernel extension bundle can be loaded by non-root users if the OSBundleAllowUserLoad property is set to True in the bundle's property list. However, if any of the files in the bundle, including the executable code file, are not owned by root and group wheel, or are writable by the group or "other", the attempt to load the kernel loadable module will fail.
Solaris
Kernel modules can optionally have a cryptographic signature ELF section which is verified on load depending on the Verified Boot policy settings. The kernel can enforce that modules are cryptographically signed by a set of trusted certificates; the list of trusted certificates is held outside of the OS in the ILOM on some SPARC based platforms. Userspace initiated kernel module loading is only possible from the Trusted Path when the system is running with the Immutable Global Zone feature enabled.
See also
*
*
*
References
{{FreeBSD
FreeBSD
Linux kernel
Operating system kernels
Device drivers