Project 5: Linux Kernel Module — Character Device Driver

A character device driver (/dev/mydevice) that implements a simple ring buffer in kernel space, accessible from userspace via read/write/ioctl.

Quick Reference

Attribute Value
Primary Language See main guide
Alternative Languages N/A
Difficulty Level 4: Expert
Time Estimate 3-4 weeks
Knowledge Area Kernel Development / Drivers
Tooling Linux Kernel Headers
Prerequisites Strong C, completed at least one userspace project above, comfortable with system crashes

What You Will Build

A character device driver (/dev/mydevice) that implements a simple ring buffer in kernel space, accessible from userspace via read/write/ioctl.

Why It Matters

This project builds core skills that appear repeatedly in real-world systems and tooling.

Core Challenges

  • Setting up kernel module build environment (maps to kernel build system)
  • Implementing file_operations (open, read, write, release, ioctl) (maps to VFS layer)
  • Managing kernel memory with kmalloc/kfree (maps to kernel memory management)
  • Handling concurrent access with spinlocks/mutexes (maps to OS-level locks)
  • Copying data between user and kernel space (maps to kernel/user boundary)
  • Debugging without crashing your system (maps to kernel debugging)

Key Concepts

  • Kernel modules: “Linux Device Drivers” Ch. 2 - Corbet et al.
  • Character devices: “Linux Device Drivers” Ch. 3 - Corbet et al.
  • Kernel memory allocation: “Linux Kernel Development” Ch. 12 - Robert Love
  • Kernel synchronization: “Linux Kernel Development” Ch. 10 - Robert Love
  • copy_to_user/copy_from_user: “Linux Device Drivers” Ch. 3 - Corbet et al.

Real-World Outcome

Deliver a working demo with observable output that proves the feature is correct.


Implementation Guide

  1. Reproduce the simplest happy-path scenario.
  2. Build the smallest working version of the core feature.
  3. Add input validation and error handling.
  4. Add instrumentation/logging to confirm behavior.
  5. Refactor into clean modules with tests.

Milestones

  • Milestone 1: Minimal working program that runs end-to-end.
  • Milestone 2: Correct outputs for typical inputs.
  • Milestone 3: Robust handling of edge cases.
  • Milestone 4: Clean structure and documented usage.

Validation Checklist

  • Output matches the real-world outcome example
  • Handles invalid inputs safely
  • Provides clear errors and exit codes
  • Repeatable results across runs

References

  • Main guide: TRACK_A_OS_KERNEL_PROJECTS.md
  • “Linux Device Drivers” by Corbet, Rubini, Kroah-Hartman