Loadable Kernel Modules
Loadable Kernel Modules (LKMs) are an integral feature in modern operating systems such as Linux, FreeBSD, macOS, and Windows. They allow the addition of new functionalities to an already running kernel without the need to reboot the system. This modular approach provides flexibility and extensibility for the operating system, enabling it to support new hardware or file systems dynamically.
A loadable kernel module is an object file that contains code to extend the capabilities of the kernel. When loaded, it becomes part of the running kernel, inheriting its privileges and memory space. This approach allows for enhanced system performance and functionality without compromising stability.
Most Unix-like systems support LKMs, albeit with different terminology. In FreeBSD, they are known as kernel loadable modules (kld), while in macOS, they are referred to as kernel extensions (kexts). However, Apple is gradually phasing out support for third-party kexts to enhance security.
In Linux, LKMs are loaded and managed using the modprobe command. This command allows users to insert modules into the kernel and remove them when they are no longer needed. The ability to load and unload modules at runtime adds a significant level of versatility to Linux, making it ideal for a wide range of applications from personal computing to enterprise systems.
In the Windows NT family, LKMs are known as kernel-mode drivers. These drivers provide a similar function to their Unix-like counterparts, enabling the system to support new hardware and software features dynamically.
Other systems such as AIX, HP-UX, and VxWorks have their own implementations of LKMs, each tailored to fit the specific requirements and architecture of the operating system.
LKMs should be carefully designed to avoid fragmentation of the kernel’s Translation Lookaside Buffer (TLB). Fragmentation can lead to performance penalties due to increased TLB misses. As modules become part of the kernel's code, they must adhere to the kernel's coding standards to minimize the risk of introducing instability or security vulnerabilities.
Since LKMs run with the same privileges as the kernel, they can potentially corrupt kernel data structures, leading to system instability or security breaches. This risk is particularly concerning when dealing with proprietary LKMs, as the source code may not be available for audit.
In Linux, the MODULE_LICENSE field is used to declare the licensing of a module. A notable incident in 2004 involved Linuxant, a consulting company, utilizing a null terminator in their MODULE_LICENSE to circumvent licensing requirements, highlighting the necessity for strict adherence to open-source licensing norms.