In Linux, the kernel provides the core functionality of the operating system, managing hardware, resources, and providing essential services. However, to keep the kernel itself relatively small and modular, additional functionalities can be added dynamically through kernel modules.
Kernel modules are pieces of code that can be loaded into the running kernel, extending its capabilities without the need to reboot the entire system.
Use Cases:
Security Considerations:
Example Commands:
sudo modprobe <module-name>
sudo rmmod <module-name>
lsmod
modinfo <module-name>
Enhance security by controlling and restricting the loading of kernel modules in a Linux system. This helps prevent unauthorized or malicious modules from being loaded, reducing potential attack vectors.
Methods:
sysctl
command to configure kernel module loading parameters.Edit /etc/sysctl.conf
or create a new file in /etc/sysctl.d/
for persistent settings.
# Disable loading of kernel modules
kernel.modules_disabled = 1
Apply changes:
sudo sysctl -p
Configure modprobe, the kernel module loader, to restrict module loading.
Example modprobe.conf:
# Restrict loading of USB modules
install usb-storage /bin/true
Apply changes:
sudo modprobe -r <module-name>
Create or edit /etc/modprobe.d/blacklist.conf
.
Example blacklist.conf:
# Blacklist a specific module
blacklist <module-name>
Apply changes:
sudo update-initramfs -u
We can also reboot the server and check lsmod again.
shutdown -r now
lsmod | grep <module>
Caution:
/etc/sysctl.conf
or create a new file in /etc/sysctl.d/
:
# Disable loading of kernel modules
kernel.modules_disabled = 1
Apply changes:
sudo sysctl -p
/etc/modprobe.d/blacklist-usb-storage.conf
:
# Blacklist USB storage modules
blacklist usb-storage
Apply changes:
sudo update-initramfs -u
Another module that we can disable is the Datagram Congestion Control Protocol (DCCP) Module.
## /etc/modprobe.d/blacklist.conf
blacklist dccp
shutdown -r now
lsmod | grep dccp