.ko) that can be loaded into and removed from the running kernel without rebooting. They extend the kernel with device drivers, filesystem support, network protocols, and other functionality.
What are kernel modules?
Modules are compiled kernel code that lives outside the main kernel image. When loaded, they run in kernel space with full kernel privileges. Most hardware drivers, filesystem implementations, and many network protocols ship as modules rather than being compiled directly into the kernel (vmlinuz).
Managing modules
lsmod
List all currently loaded modules, their sizes, and usage counts.
modprobe
Load or remove a module and automatically handle dependencies.
insmod
Load a module directly from a
.ko file, without dependency resolution.rmmod
Remove a loaded module (must not be in use).
Listing loaded modules
Used by column shows the use count and which other modules depend on a given module.
Loading modules
Use
modprobe rather than insmod for everyday use. modprobe reads the module dependency database (modules.dep) and loads any required dependencies automatically.Unloading modules
Module parameters
Modules expose parameters that can be set at load time or (for some) at runtime:Persistent parameters with modprobe.d
Create a.conf file in /etc/modprobe.d/ to set parameters every time a module is loaded:
Automatic module loading
udev and module aliases
When hardware is detected,udev reads the device’s vendor/product IDs and looks up the corresponding module via modalias. The kernel then calls request_module() to load it automatically.
/etc/modules-load.d/
For modules that should always be loaded at boot regardless of hardware detection:systemd-modules-load.service processes these files during early boot.
Blacklisting modules
Blacklisting prevents a module from being loaded automatically. It does not prevent manual loading withmodprobe -f or insmod.
install directive replaces the module’s load action with an arbitrary command. Using /bin/false makes any attempt to load the module via modprobe silently fail.
Module signing
The kernel module signing facility cryptographically signs modules during installation and verifies signatures when modules are loaded. This prevents loading of tampered or malicious modules, and is required for Secure Boot.How it works
Build-time key generation
When The public key is embedded in the kernel binary. The private key is only needed during the build.
CONFIG_MODULE_SIG=y is set, the kernel build system automatically generates a private/public keypair in certs/signing_key.pem (if one does not exist):Module signing at install time
With
CONFIG_MODULE_SIG_ALL=y, all modules are signed automatically during make modules_install.To manually sign a module:Kernel configuration options
| Config option | Effect |
|---|---|
CONFIG_MODULE_SIG | Enable module signature verification |
CONFIG_MODULE_SIG_FORCE | Refuse to load unsigned or incorrectly signed modules |
CONFIG_MODULE_SIG_ALL | Automatically sign all modules at install time |
CONFIG_MODULE_SIG_SHA512 | Use SHA-512 for module signatures |
CONFIG_MODULE_SIG_KEY | Path to the signing key (default: certs/signing_key.pem) |
CONFIG_SYSTEM_TRUSTED_KEYS | PEM file with additional trusted certificates |
Enforcement modes
IfCONFIG_MODULE_SIG_FORCE is off (permissive mode): unsigned modules load but taint the kernel with the E flag.
If CONFIG_MODULE_SIG_FORCE is on (or module.sig_enforce=1 is set on the kernel command line): only validly signed modules load; all others are rejected with an error.
Protecting the private key
Out-of-tree modules
Modules not included in the mainline kernel source are called out-of-tree (OOT) modules. Common examples include proprietary GPU drivers (NVIDIA), ZFS, VirtualBox kernel modules, and vendor-specific drivers.Building an out-of-tree module
DKMS — Dynamic Kernel Module Support
DKMS automatically rebuilds out-of-tree modules when a new kernel is installed:Tainted kernels
The kernel marks itself as “tainted” when certain events occur that may affect its reliability or supportability. Taint flags are visible in kernel oops and panic messages, and via/proc/sys/kernel/tainted.
Taint flag reference
| Bit | Flag | Value | Reason |
|---|---|---|---|
| 0 | P | 1 | Proprietary module loaded |
| 1 | F | 2 | Module force-loaded (insmod -f) |
| 2 | S | 4 | Kernel running on out-of-specification hardware |
| 3 | R | 8 | Module force-unloaded (rmmod -f) |
| 4 | M | 16 | Machine Check Exception (MCE) occurred |
| 5 | B | 32 | Bad page reference or unexpected page flags |
| 6 | U | 64 | Taint requested by userspace |
| 7 | D | 128 | Kernel died recently (oops or BUG) |
| 8 | A | 256 | ACPI table overridden by user |
| 9 | W | 512 | Kernel issued a warning |
| 10 | C | 1024 | Staging driver loaded |
| 11 | I | 2048 | Workaround applied for platform firmware bug |
| 12 | O | 4096 | Out-of-tree module loaded |
| 13 | E | 8192 | Unsigned module loaded |
| 14 | L | 16384 | Soft lockup occurred |
| 15 | K | 32768 | Kernel has been live-patched |
| 16 | X | 65536 | Auxiliary taint (used by Linux distributors) |
| 17 | T | 131072 | Kernel built with struct randomization plugin |
| 18 | N | 262144 | In-kernel test (e.g., KUnit) was run |
| 19 | J | 524288 | Userspace used a mutating debug operation via fwctl |
Reading taint flags in oops messages
P= proprietary module loaded (bit 0)W= kernel issued a warning (bit 9)O= out-of-tree module loaded (bit 12)
Kernel developers frequently decline to investigate bug reports from tainted kernels, because the taint event itself could be the cause of the bug. Always try to reproduce issues on an untainted kernel before filing a bug report.
