Deliberately vulnerable Linux kernel module (LKM) for kernel security training. A misc character device whose ioctl handlers contain an integer overflow, an integer underflow and a stack buffer overflow, with a userspace CLI, a QEMU and GDB debugging lab, and PDF walkthroughs.
After load it registers a misc character device /dev/vuln_lkm. Userspace talks to it only through ioctl.
Author: Damian Andres Ulanowicz
Intentional bugs (lab only, not an exploit kit):
- Integer overflow —
vuln_lkm_add:g_val = g_val + non au32with no saturation check. - Integer underflow —
vuln_lkm_sub:g_val = g_val - nwith no underflow check. - String buffer overflow —
vuln_lkm_str:memcpyinto a 32-byte stack buffer using a userlen(capped only at 256, not at 32).
If you insmod on the host (HOST=1 ./load.sh): yes, it can. GET/SET/ADD/SUB usually just wrap a number and stay up. str with more than 32 bytes can oops or panic this kernel and you reboot or restore a snapshot. Do not do that on a machine you care about.
Default ./load.sh / ./install.sh uses QEMU. The guest boots a copy of your host's vmlinuz plus a busybox initramfs. That is the same kernel version (so vuln_lkm.ko matches), but it is not the already-running Ubuntu. A guest panic dies in QEMU (-no-reboot). The host stays up. No snapshot required for the QEMU path.
QEMU is not attaching to the live host kernel. It is a separate VM.
chmod +x install.sh load.sh unload.sh scripts/*.sh
./install.sh # packages, build/, busybox initramfs, then QEMU
# in the guest:
/vuln_lkm_cli getArtifacts: build/vuln_lkm.ko, build/vuln_lkm_cli, build/initramfs.cpio.gz, build/bzImage.
make # .ko + CLI into build/ (CLI was missing if you only ran make module)
./load.sh # QEMU guest
HOST=1 ./load.sh # host insmod — can panic this Ubuntu
./scripts/debug_gdb.sh| file | pages | contents |
|---|---|---|
| Docs/vuln_lkm.pdf | 21 | How the LKM works |
| Docs/vuln_lkm_cli.pdf | 11 | How the CLI works |
| Docs/vuln_lkm_run_debug.pdf | 47 | Install, QEMU/GDB, busybox, ioctl/IRQL/overflows |
| file | role |
|---|---|
vuln_lkm.c / vuln_lkm.h |
LKM + shared ioctl ABI |
vuln_lkm_cli.c |
userspace tester (binary: build/vuln_lkm_cli) |
Makefile |
kbuild + gcc; outputs under build/ |
install.sh |
packages, build, initramfs, then load.sh |
load.sh |
QEMU by default; HOST=1 insmod on this kernel |
scripts/build_initramfs.sh |
busybox rootfs + copy of /boot/vmlinuz-$(uname -r) |
scripts/run_qemu.sh |
guest, GDB stub :1234 |
scripts/debug_gdb.sh |
attach GDB to the guest |
Docs/ |
markdown + PDFs |
./build/vuln_lkm_cli -h
./build/vuln_lkm_cli get
./build/vuln_lkm_cli set 10
./build/vuln_lkm_cli sub 11 # underflow → 4294967295
./build/vuln_lkm_cli set 0xfffffffe
./build/vuln_lkm_cli add 3 # overflow → 1
./build/vuln_lkm_cli str hello # fits in 32
In QEMU the binary is /vuln_lkm_cli. Long str belongs there, not on the host.
More: Docs/cli.md, Docs/install-and-run.md.
This project is licensed under the MIT License. Copyright (c) 2026 Damian Andres Ulanowicz.