Linux Kernel Modules Explained: lsmod, modprobe and the Risks of Loading Code Into the Kernel
Linux is modular. Instead of building every driver and feature into the kernel itself, Linux loads most of them as separate pieces of code — kernel modules — while the system is running. Your Wi-Fi driver, your filesystem support, even your webcam: all probably loaded as modules. That flexibility is powerful, and it’s also a security boundary worth understanding.
What Is a Kernel Module?
A kernel module is a chunk of code the kernel can load and unload on demand. It runs with the highest possible privilege — inside the kernel itself, with full access to memory, hardware and every process. There’s no sandbox around it. That’s the trade-off: modules make Linux flexible, but a bad module owns the whole machine.
Seeing What’s Loaded
List the modules currently running on your system:
lsmod
You’ll see three columns: the module name, its size, and how many other things use it. To see details about one module:
modinfo iwlwifi
This shows the author, description, license, and the parameters the module accepts — useful when you’re checking whether a module is legitimate.
Loading and Unloading Modules
sudo modprobe usb-storage (load a module)
sudo modprobe -r usb-storage (unload it)
sudo modprobe --show-depends ext4 (see what a module needs)
modprobe is smarter than the older insmod — it loads dependencies automatically and reads configuration from /etc/modprobe.d/.
Why Attackers Love Kernel Modules
A malicious kernel module — a “rootkit” in the classic sense — is the ultimate hiding place. Because it runs inside the kernel, it can:
- Hide files, processes and network connections from every tool that asks the kernel what exists.
- Intercept system calls, so security tools see a clean system while malware runs underneath.
- Survive user-level cleanup, because reinstalling applications doesn’t touch the kernel.
This is why kernel-level compromise is treated as a full rebuild scenario: once the kernel can’t be trusted, nothing running on it can be trusted either.
How to Defend Your Kernel
- Lock module loading. On a server that doesn’t need new hardware, set kernel.modules_disabled=1 after boot — the kernel then refuses to load any new module until reboot.
- Require signed modules. Secure Boot and module signing mean only modules signed with a trusted key can load.
- Watch for unexpected modules. Compare lsmod output against a known-good baseline. A module you don’t recognize is a red flag.
- Restrict who can load modules. Only root can load modules — so protect root access fiercely, and audit sudo usage.
- Keep the kernel updated. Most kernel vulnerabilities are fixed by updating; an unpatched kernel is the easiest way in.
The Bottom Line
Kernel modules are how Linux stays flexible — and how attackers stay invisible. Know what’s loaded on your systems, lock down module loading where you can, and treat any unknown module as an incident, not a curiosity.



Comments
Post a Comment