A kernel-mode driver is a software component that runs in the privileged kernel address space of an operating system and controls a hardware device, a bus or a virtual device on behalf of the rest of the system. In the field of drivers & devices, it is the layer that translates generic requests from the operating system into the register writes, interrupts and DMA transfers a specific piece of hardware understands.
Because it executes at the highest processor privilege level (ring 0 on x86, EL1 on Arm), a kernel-mode driver can touch any memory and any device. That power gives it low latency and direct hardware access, but it also means that a single defect can crash or compromise the entire system, which is why every major operating system wraps such drivers in strict rules for design, testing and signing.
How a kernel-mode driver works inside the operating system
A kernel-mode driver works by registering entry points with the kernel, which then calls those routines when a device appears, when an application issues I/O, or when the hardware raises an interrupt. On Windows the driver exports a DriverEntry routine and dispatch functions for I/O request packets (IRPs); on Linux it registers a structure of callbacks such as probe, remove, read and ioctl with the relevant subsystem.
The typical life cycle has distinct phases. During device enumeration, the bus driver discovers the hardware and the plug and play manager loads the matching driver. The driver then maps device registers through memory-mapped I/O or port-mapped I/O, allocates buffers and connects an interrupt service routine. At run time it queues requests, programs the device, and completes requests when the hardware signals that work is done.
The following table summarizes the main responsibilities and the kernel mechanism each one relies on.
| Responsibility | Kernel mechanism | Typical constraint |
|---|---|---|
| Initialization | Driver entry point, probe callback | Must fail cleanly if hardware is absent |
| Request handling | IRPs, file operations, request queues | Must validate every user buffer |
| Interrupt handling | ISR plus deferred procedure or bottom half | ISR must finish in microseconds |
| Data transfer | DMA mapping, scatter-gather lists | Buffers must be pinned and IOMMU-mapped |
| Power management | Suspend, resume and idle callbacks | Device state must survive sleep transitions |
| Teardown | Remove and unload routines | All resources released, no dangling references |
Execution context and the rules drivers must follow
A kernel-mode driver must respect the execution context in which each routine runs, because the kernel restricts what code may do depending on whether it can sleep. An interrupt service routine runs with interrupts masked at an elevated level, so it may only acknowledge the device and schedule deferred work; blocking, page faults or waiting on a lock that can sleep are forbidden there.
Windows expresses these rules through interrupt request levels (IRQLs), while Linux distinguishes process context from atomic context. The table below compares the most important levels.
| Context | Windows equivalent | Linux equivalent | May sleep or page fault |
|---|---|---|---|
| Normal thread | PASSIVE_LEVEL | Process context | Yes |
| Deferred work | DISPATCH_LEVEL (DPC) | Softirq or tasklet | No |
| Hardware interrupt | DIRQL | Hard IRQ handler | No |
| Worker thread | Work item at PASSIVE_LEVEL | Workqueue | Yes |
Violating these rules produces some of the hardest bugs in systems programming: deadlocks, priority inversions and crashes that appear only under load. Good drivers keep the interrupt path short, move heavy processing to worker threads, and use spinlocks only for brief critical sections shared with interrupt code.
Kernel-mode driver versus user-mode driver
The essential difference is isolation versus performance: a kernel-mode driver shares the kernel address space and can stop the whole machine, whereas a user-mode driver runs as an ordinary process and fails alone. Modern platforms push as much code as possible into user mode, keeping only the parts that genuinely need privilege in the kernel.
| Property | Kernel-mode driver | User-mode driver |
|---|---|---|
| Privilege level | Ring 0 or EL1, full access | Ring 3 or EL0, restricted |
| Failure impact | System crash or hang | Process restart, system survives |
| Latency | Lowest, no context switch | Higher, crosses the kernel boundary |
| Interrupt access | Direct ISR registration | Indirect, through a kernel stub |
| Debugging | Kernel debugger, crash dumps | Standard user-space debuggers |
| Typical examples | Storage, network, GPU kernel parts | Printers, cameras, many USB devices |
Windows offers both models through the Kernel-Mode Driver Framework (KMDF) and the User-Mode Driver Framework (UMDF). Linux has supported user-space drivers through UIO and VFIO, and macOS has moved most third-party drivers out of the kernel with DriverKit system extensions, deprecating classic kernel extensions.
Driver stacks and kernel-mode driver roles
Kernel-mode drivers rarely act alone; they are arranged in a driver stack in which each layer handles one level of abstraction and passes requests down. A request to read a file, for example, passes through file system, volume, partition and storage port drivers before it reaches the controller.
| Role | Position in stack | Main task |
|---|---|---|
| Bus driver | Bottom | Enumerates child devices on PCIe, USB or I2C |
| Function driver | Middle | Implements the main logic for one device |
| Filter driver | Above or below function driver | Monitors or modifies requests |
| Class driver | Above function drivers | Provides shared behavior for a device class |
| Miniport driver | Paired with a port or class driver | Supplies hardware-specific code only |
This layered design lets vendors write a small miniport instead of a complete driver, while the operating system supplies tested common code. It also explains why antivirus products and backup tools install filter drivers: they intercept traffic in the kernel without replacing the device’s own driver.
Security, signing and stability of kernel-mode drivers
Since a kernel-mode driver runs with full privileges, it is a prime target for attackers and a frequent source of system instability. Operating systems therefore enforce mandatory driver signing: 64-bit Windows refuses to load unsigned kernel drivers, and Secure Boot extends that chain of trust from firmware to the kernel.
- Bring-your-own-vulnerable-driver attacks load a legitimately signed but flawed driver to gain kernel access, which is why Windows maintains a vulnerable driver blocklist.
- Hypervisor-protected code integrity (HVCI) prevents drivers from allocating executable, writable kernel memory, and incompatible drivers must be updated.
- An unchecked IOCTL buffer is a classic flaw that lets an unprivileged process overwrite kernel memory.
- A driver that leaks memory or references may run for days before exhausting kernel pools and failing.
- Third-party kernel code that loads early can prevent a machine from booting if it faults, so staged rollout and recovery paths are essential.
Linux takes a different approach, keeping most drivers in the mainline source tree where they are reviewed and updated with each kernel release. Out-of-tree and proprietary modules taint the kernel and must be rebuilt when internal interfaces change, because Linux guarantees no stable in-kernel driver API.
A non-technical view
A computer’s operating system is like the management office of a large building, and hardware devices are the machines in the basement. A kernel-mode driver is a technician who holds a master key to every room. Because the technician can go anywhere instantly, work gets done quickly.
The same master key is also the risk. If that technician makes a serious mistake, the whole building can lose power, not only one machine. That is why operating systems demand that such technicians be vetted and certified, and why they now hand out master keys only when no safer option exists.
A concrete example
A company building an industrial data acquisition card for PCI Express needs to capture sensor samples at 20 megabytes per second without losing a single block. Its engineers write a Windows kernel-mode driver with KMDF. The driver maps the card’s registers, sets up scatter-gather DMA into locked memory, and registers an interrupt routine that only reads a status register and queues a deferred procedure call.
During testing, Driver Verifier reveals that one path touched pageable memory at DISPATCH_LEVEL, a defect that would have caused rare crashes in the field. After the fix, the driver passes the hardware compatibility tests and is signed. The result is continuous capture with no dropped samples and an interrupt routine that completes in a few microseconds, while the configuration utility runs safely in user mode.