Pack a binary into a self-contained, self-executing Linux kernel module using the usermode driver infrastructure. https://code.ivysaur.me/mkkmod
c
Go to file
2024-07-13 10:56:47 +12:00
.gitignore initial commit 2024-07-13 10:56:47 +12:00
build-module.sh initial commit 2024-07-13 10:56:47 +12:00
build-sample.sh initial commit 2024-07-13 10:56:47 +12:00
eprog_kern.c initial commit 2024-07-13 10:56:47 +12:00
Makefile initial commit 2024-07-13 10:56:47 +12:00
modules.order initial commit 2024-07-13 10:56:47 +12:00
README.md initial commit 2024-07-13 10:56:47 +12:00
sample.c initial commit 2024-07-13 10:56:47 +12:00

mkkmod

Pack a binary into a self-contained, self-executing Linux kernel module using the usermode driver infrastructure.

Adapted from an example by Richard Weinberger.

License: GPL-2.0-only

Usage

  • Build sample binary to embed: ./build-sample.sh
  • Build kernel module: ./build-module.sh ./sample
    • To build for the non-running kernel: KERN_VER=6.9.8-200.fc40.x86_64 ./build-module.sh ./sample
  • Run: insmod ./eprog.ko

Requirements

  • The generated module must have a GPL-compatible license to use EXPORT_SYMBOL_GPL functions.
  • Requires kernel 5.9 or later.
  • Kernel version needs to export the umd functionality.

If you get errors of the form modpost: "fork_usermode_driver" [...] undefined! check if your kernel exposes the functions in /usr/src/linux-headers-$(uname -r)/Module.symvers and/or that the functions are present in /proc/kallsyms.

Compatibility tests:

Distro Kernel version Notes
Debian 12 6.1.0-22 Missing symbols
Fedora 40 6.9.8-200 Features are present

Reference