Linux kernel module skill for writing and debugging loadable kernel modules. Use when writing LKMs with Kbuild, adding module parameters, creating /proc and sysfs entries, implementing character devices, debugging with KGDB or ftrace, or handling module signing for Secure Boot. Activates on queries about Linux kernel modules, loadable modules, Kbuild, module parameters, /proc filesystem, sysfs, character devices, KGDB, or module signing.
Install with Codex or Claude Copy this prompt, paste it into Codex, Claude, or another assistant, and let it review the skill page and install it for you.
A direct command skips the review prompt. Inspect the source before running it.
Linux kernel module skill for writing and debugging loadable kernel modules. Use when writing LKMs with Kbuild, adding module parameters, creating /proc and sysfs entries, implementing character devices, debugging with KGDB or ftrace, or handling module signing for Secure Boot. Activates on queries about Linux kernel modules, loadable modules, Kbuild, module parameters, /proc filesystem, sysfs, character devices, KGDB, or module signing.
Linux Kernel Modules
Purpose
Guide agents through writing loadable Linux kernel modules (LKMs): the Kbuild build system, module parameters, /proc and sysfs interfaces, character device implementation, kernel debugging with KGDB and ftrace, and module signing for Secure Boot.
# KGDB — kernel GDB via serial/network# Boot with: kgdboc=ttyS0,115200 kgdbwait# Or over network: kgdboe=@192.168.1.10/,@192.168.1.11/# On debug host:
gdb vmlinux
(gdb) target remote /dev/ttyS0
(gdb) set architecture i386:x86-64:intel
(gdb) info registers
# ftrace — kernel function tracerechofunction > /sys/kernel/debug/tracing/current_tracer
echo mymod_write > /sys/kernel/debug/tracing/set_ftrace_filter
echo 1 > /sys/kernel/debug/tracing/tracing_on
cat /sys/kernel/debug/tracing/trace
# Dynamic debug — enable pr_debug() outputecho"module hello +p" > /sys/kernel/debug/dynamic_debug/control
7. EXPORT_SYMBOL vs EXPORT_SYMBOL_GPL
// EXPORT_SYMBOL — any module can link (including proprietary)
EXPORT_SYMBOL(my_helper);
// EXPORT_SYMBOL_GPL — only GPL-compatible modules can link
EXPORT_SYMBOL_GPL(gpl_only_fn);
Use EXPORT_SYMBOL_GPL for symbols that touch GPL-only kernel internals. Loading a non-GPL module that imports GPL symbols fails with a taint warning. Check with modinfo and dmesg after insmod.
# In-tree KUnit run (kernel tree with CONFIG_KUNIT=y)
./tools/testing/kunit/kunit.py run --filter mymod
# Out-of-tree: enable CONFIG_KUNIT in test kernel or use kunit module target
See skills/kernel/kernel-testing for full KUnit, kselftest, and syzkaller workflows.
# Build from kernel tree with Rust support enabled
make LLVM=1 rustavailable # verify Rust toolchain
make M=drivers/rust_example modules
sudo insmod drivers/rust_example/rust_example.ko
10. Module signing (Secure Boot, kernel 6.x)
Kernel 6.x enforces module signature verification when CONFIG_MODULE_SIG is enabled (default on most distro kernels with Secure Boot).
With lockdown integrity or confidentiality, unsigned modules are rejected. Distro kernels may also require keys enrolled in the kernel's built-in trusted keyring (CONFIG_SYSTEM_TRUSTED_KEYS).