Driver Models Compared
Linux vs Windows Internals Compared · Operating Systems track
11 min read
In this module
How Operating Systems Talk to Hardware
Device drivers are the diplomats between the kernel and the hardware. They take generic OS requests — read this sector, send that packet, draw a frame — and translate them into the specific dance the chip on the other end is expecting. Linux and Windows wire this up in completely different ways, and the differences ripple straight through stability, security, and how miserable driver development feels.
Linux Device Model
Linux glues all its device handling together with three pieces: sysfs, udev, and loadable kernel modules.
Device Types
Linux files devices into three buckets:
Character Devices (/dev/ttyS0, /dev/random): - Accessed as a stream of bytes - Read/write operations transfer data sequentially - Examples: serial ports, terminals, input devices
Block Devices (/dev/sda, /dev/nvme0n1): - Accessed in fixed-size blocks (typically 512 bytes or 4 KB) - Support random access (seeking) - Buffered through the page cache - Examples: hard drives, SSDs, USB storage
Network Devices (eth0, wlan0): - Not represented in /dev - Accessed through socket API and netlink - Packet-oriented (not byte-stream or block) - Examples: Ethernet adapters, Wi-Fi adaptersKernel Module Structure
#include <linux/module.h>#include <linux/fs.h>#include <linux/cdev.h>
static int major_num;static struct cdev my_cdev;
static int my_open(struct inode *inode, struct file *file) { pr_info("Device opened\n"); return 0;}
static ssize_t my_read(struct file *file, char __user *buf, size_t count, loff_t *offset) { char data[] = "Hello from kernel!\n"; size_t len = strlen(data); size_t n; if (*offset >= len) return 0; n = len - *offset; if (n > count) n = count; if (copy_to_user(buf, data + *offset, n)) return -EFAULT; *offset += n; return n; // bytes copied, saved before *offset moved}
static struct file_operations my_fops = { .owner = THIS_MODULE, .open = my_open, .read = my_read,};
static int __init my_init(void) { dev_t dev; alloc_chrdev_region(&dev, 0, 1, "mydevice"); major_num = MAJOR(dev); cdev_init(&my_cdev, &my_fops); cdev_add(&my_cdev, dev, 1); pr_info("Device registered: major=%d\n", major_num); return 0;}
static void __exit my_exit(void) { cdev_del(&my_cdev); unregister_chrdev_region(MKDEV(major_num, 0), 1); pr_info("Device unregistered\n");}
module_init(my_init);module_exit(my_exit);MODULE_LICENSE("GPL");sysfs and udev
sysfs (mounted at /sys) is where the kernel publishes its device tree for user space to read and poke:
/sys/├── bus/│ ├── pci/devices/ ← PCI devices│ ├── usb/devices/ ← USB devices│ └── platform/devices/ ← Platform devices├── class/│ ├── net/ ← Network interfaces│ ├── block/ ← Block devices│ └── input/ ← Input devices└── devices/ └── (hierarchical device tree)udev is the user-space daemon that watches for hotplug events, creates the matching nodes under /dev, and runs your rules whenever a device shows up or disappears:
# /etc/udev/rules.d/99-mydevice.rules# When a USB device with specific vendor/product ID is inserted:SUBSYSTEM=="usb", ATTR{idVendor}=="1234", ATTR{idProduct}=="5678", \ SYMLINK+="mydevice", MODE="0666"Linux exposes hardware through the filesystem. Devices appear as files in /dev, kernel parameters appear as files in /proc and /sys, and even process information appears as files in /proc/[pid]/. This design means standard tools (cat, echo, dd) can interact with hardware, and programs that read/write files can operate on devices without special APIs.
Windows Driver Model
Windows has gone through three generations of driver framework:
WDM (Windows Driver Model)
WDM is the original kernel-mode framework, built around I/O Request Packets (IRPs):
#include <wdm.h>
NTSTATUS DriverEntry(PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath) { // Register dispatch routines DriverObject->MajorFunction[IRP_MJ_CREATE] = MyCreate; DriverObject->MajorFunction[IRP_MJ_READ] = MyRead; DriverObject->MajorFunction[IRP_MJ_WRITE] = MyWrite; DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = MyIoControl; DriverObject->MajorFunction[IRP_MJ_CLOSE] = MyClose; DriverObject->DriverUnload = MyUnload;
// Create a device object PDEVICE_OBJECT deviceObject; UNICODE_STRING devName = RTL_CONSTANT_STRING(L"\\Device\\MyDevice"); NTSTATUS status = IoCreateDevice(DriverObject, 0, &devName, FILE_DEVICE_UNKNOWN, 0, FALSE, &deviceObject); if (!NT_SUCCESS(status)) return status;
// Ask the I/O manager to copy read/write data through a kernel // buffer, so Irp->AssociatedIrp.SystemBuffer is valid in MyRead deviceObject->Flags |= DO_BUFFERED_IO;
// Create a symbolic link so user mode can access it // (\??\ is the modern spelling of the older \DosDevices\ prefix) UNICODE_STRING symLink = RTL_CONSTANT_STRING(L"\\??\\MyDevice"); IoCreateSymbolicLink(&symLink, &devName);
return STATUS_SUCCESS;}
NTSTATUS MyRead(PDEVICE_OBJECT DeviceObject, PIRP Irp) { PIO_STACK_LOCATION irpSp = IoGetCurrentIrpStackLocation(Irp); ULONG length = irpSp->Parameters.Read.Length;
// Fill the buffer with data PVOID buffer = Irp->AssociatedIrp.SystemBuffer; if (length < 18) { Irp->IoStatus.Status = STATUS_BUFFER_TOO_SMALL; Irp->IoStatus.Information = 0; IoCompleteRequest(Irp, IO_NO_INCREMENT); return STATUS_BUFFER_TOO_SMALL; } RtlCopyMemory(buffer, "Hello from driver!", 18);
Irp->IoStatus.Status = STATUS_SUCCESS; Irp->IoStatus.Information = 18; IoCompleteRequest(Irp, IO_NO_INCREMENT); return STATUS_SUCCESS;}WDF: KMDF and UMDF
WDF is Microsoft's attempt to make driver development less of an exercise in suffering:
┌───────────────────────────────────────────────┐│ KMDF (Kernel-Mode Driver Framework) ││ - Simpler than raw WDM ││ - Automatic PnP and power management ││ - Still runs in kernel space (ring 0) ││ - For drivers needing kernel performance │├───────────────────────────────────────────────┤│ UMDF (User-Mode Driver Framework) ││ - Runs in user space (ring 3) ││ - If driver crashes, system survives ││ - Communicates with kernel via reflector ││ - For USB, sensors, HID devices ││ - UMDF 2 can handle some interrupts │└───────────────────────────────────────────────┘Plug and Play (PnP) Manager
PnP is what handles automatic hardware detection and driver loading on Windows:
1. Hardware enumeration (PCI bus scan, USB enumeration)2. PnP Manager reads device IDs3. Searches for matching INF file (driver installation file)4. Loads the driver5. Sends PnP IRPs: IRP_MN_START_DEVICE, IRP_MN_QUERY_CAPABILITIES6. Driver initializes the hardwareINF Files and Driver Signing
Every Windows driver needs an accompanying INF (installation manifest) plus a valid digital signature:
; mydriver.inf[Version]Signature = "$WINDOWS NT$"Class = MyDeviceClassClassGuid = {12345678-1234-1234-1234-123456789ABC}Provider = %ManufacturerName%DriverVer = 01/01/2024,1.0.0.0CatalogFile = mydriver.cat ; Digital signature catalog
[Manufacturer]%ManufacturerName% = Standard, NTamd64
[Standard.NTamd64]%DeviceName% = MyDevice_Install, PCI\VEN_1234&DEV_5678
[MyDevice_Install]CopyFiles = MyDevice_CopyFiles
[MyDevice_CopyFiles]mydriver.sysSince Vista x64, kernel drivers without a valid signature simply won't load. Since Windows 10 1607, that signature has to come from Microsoft itself, via the Hardware Dev Center portal — third-party signing isn't enough any more.
Windows requires kernel-mode drivers to be digitally signed to protect against rootkits. Unsigned drivers cannot be loaded on 64-bit Windows (without disabling Secure Boot or enabling test signing). Linux historically allowed any module to be loaded, but many distributions now support Secure Boot module signing. Driver signing strictness has a direct bearing on the security model of each platform.
Bring Your Own Vulnerable Driver (BYOVD)
Mandatory signing has a blind spot: it checks who signed a driver, not whether the driver is any good. Plenty of legitimately signed drivers expose IOCTLs that read or write arbitrary kernel memory for user mode. An attacker who already has admin rights but wants the kernel simply installs one of those drivers and asks it nicely.
Real examples aren't hard to find. MSI's RTCore64.sys (CVE-2019-16098) let any caller read and write kernel memory, and ransomware crews have used it to blind EDR products. Capcom's capcom.sys went further and would happily call a function pointer supplied from user mode. The defences are Microsoft's vulnerable driver blocklist, which refuses to load known offenders, and HVCI, which stops the attacker turning a write primitive into new unsigned kernel code. HVCI doesn't stop data-only tricks like zeroing a callback array, so the blocklist matters as much as the hypervisor.
Comparison
The I/O model row is easiest to see as a picture. On Windows, a request becomes an IRP that travels down a stack of device objects and completes back up; on Linux, the VFS makes one indirect call into whichever driver owns the file.
Filters are why Windows antivirus and encryption products can see (and veto) I/O without patching anyone's code: they simply sit in the stack.
| Aspect | Linux | Windows |
|---|---|---|
| Framework | Kernel modules (simple init/exit) | WDM, KMDF, UMDF (structured) |
| Loading | insmod/modprobe | PnP Manager + INF files |
| Device nodes | /dev (filesystem) | Object namespace (\Device) |
| User-mode drivers | FUSE (filesystems), libusb | UMDF (general framework) |
| Hot-plugging | udev rules | PnP Manager |
| Signing | Optional (depends on distro) | Mandatory (64-bit) |
| I/O model | file_operations callbacks | IRP dispatch routines |
| Discovery | sysfs + udev | Device Manager + PnP |
The driver model has a direct line to system stability. On Linux, modules sit in ring 0 with no safety net — a single null deref in your driver takes the whole machine down. UMDF on Windows can punt some drivers out into user space where a crash is merely recoverable. The catch: most performance-sensitive Windows drivers still use KMDF in kernel mode, and a bug there is just as final.
If you're building anything close to the metal — kernel modules, embedded work, mapping an OS's attack surface — both models are required reading.