How Tech - Systems Programming

How Tech - Systems Programming

Building Kernel Modules that Safely Interact with User-Space through IOCTLs

Jul 05, 2026
∙ Paid

Part I — Article

Building Kernel Modules that Safely Interact with User-Space through IOCTLs

The Linux kernel maintains a hard boundary between kernel and user address spaces. A userspace pointer — 0x7fff... something — is completely meaningless in kernel context. The page tables are different. The virtual address mappings don’t exist on the kernel side. And since Broadwell (2014), SMAP — Supervisor Mode Access Prevention — is a hardware-enforced CPU feature that causes an immediate fault if kernel code dereferences a userspace pointer directly. Before SMAP, drivers silently got away with this. On modern kernels, the crash is instant.

IOCTLs are how drivers expose device-specific operations that don’t fit read()/write() semantics. A single ioctl(fd, cmd, arg) syscall fans out into hundreds of device-specific handlers depending on cmd. The kernel VFS layer takes the file descriptor, resolves it to a struct file, and calls file->f_op->unlocked_ioctl. Your driver provides that function pointer.

→ Subscribe now to access source code repository - 200 + coding lessons

User's avatar

Continue reading this post for free, courtesy of Systems.

Or purchase a paid subscription.
© 2026 Sumedh S · Privacy ∙ Terms ∙ Collection notice
Start your SubstackGet the app
Substack is the home for great culture