Building Kernel Modules that Safely Interact with User-Space through IOCTLs
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 singleioctl(fd, cmd, arg)syscall fans out into hundreds of device-specific handlers depending oncmd. The kernel VFS layer takes the file descriptor, resolves it to astruct file, and callsfile->f_op->unlocked_ioctl. Your driver provides that function pointer.
→ Subscribe now to access source code repository - 200 + coding lessons


