Rust-for-Linux rootkit detection kernel module

A Rust kernel module that caught the symbol-hiding LKM rootkit Diamorphine by checking where syscall table entries point.

Field
Security · 2025
Period
Dec 18, 2025 – Jan 15, 2026
Team
Layer7 end-of-term project, team of three
Role
PM, dev environment, detection module
Setup
Arch Linux, kernel 6.18.0, Rust nightly
Tags
RustLinux KernelRootkit

Overview

rust_rkscan is a Linux kernel module written with Rust-for-Linux that detects LKM rootkits hiding themselves by hooking system calls. In a C kernel module, one memory mistake in the detection code can panic the kernel, so we chose Rust, whose ownership and borrowing rules reject that class of bug at compile time.

It was a three-person end-of-term project for Layer7, a security club. As PM I shaped the idea with the team, built the development environment and wrote the detection module.

Environment

We started on Ubuntu Server 24.04 under QEMU/KVM, but Rust-for-Linux builds kept failing on bindgen version conflicts, mismatched cargo and apt packages, and an old LLVM. I rebuilt the environment on an Arch Linux VM, which ships the latest kernel and Rust nightly right away.

CheckVerify the toolchain with make LLVM=1 rustavailable
ConfigEnable Rust support in menuconfig
BuildBuild an x86_64 kernel from the Rust-for-Linux tree, update GRUB
VerifyBoot the 6.18.0-rust kernel, load the rust_minimal sample
  • OS: Arch Linux, kernel 6.18.0, Rust 1.94.0-nightly, LLVM/Clang
  • Target rootkit: Diamorphine, a public LKM rootkit

Detection design

Diamorphine removes itself from lsmod, filters its own symbols out of /proc/kallsyms, and hooks the getdents, getdents64 and kill system calls. The module therefore checks in two stages.

rust_rkscan architecture

  1. Signature check: look up known symbols such as diamorphine_init and hacked_getdents with kallsyms_lookup_name.
  2. Behavior check: read the current address of key system calls from sys_call_table, and flag a hook when an address falls outside the kernel .text range, in module memory.

With KASLR on, addresses changed on every boot and the .text range check became unreliable. For the experiment we turned KASLR off and built the function pointers from fixed addresses read in /proc/kallsyms.

Results

On a clean system both checks pass and the module prints System Clear.

Scan log on a clean system

After loading Diamorphine with insmod and scanning again, the signature check still finds nothing because Diamorphine filters kallsyms. The behavior check finds that getdents (78), getdents64 (217) and kill (62) now point outside the .text range (0xffffffff81000000 to 0xffffffff8231f750), into module memory at 0xffffffffc000xxxx, and prints Rootkit Detected!.

Scan log after loading Diamorphine

3/3Hooked syscalls detected
0/3Symbols found by signature

Against a rootkit that hides its symbols, the signature check failed and the behavior check, which looks at the real addresses in the syscall table, caught it. It showed in practice that a kernel module written in Rust can do the same kernel-level inspection as a C module.

Limits and next steps

NoteThese results come from a test setup with KASLR off, against one rootkit (Diamorphine).
  • The module only detects. It does not restore hooked system calls or block malicious modules from loading.
  • Next steps:
    • Compare detection rates and limits against other rootkits such as Reptile and Suterusu
    • Write our own rootkit that fixes Diamorphine's weak spots and evades this module, then harden the detector against it
    • Build a C module with the same features and compare performance and safety
  • The .text range should also be computed at runtime so the check works with KASLR on.

Ask more

guest@lambda: ~ — zsh — 80×24zsh>_ Ask Lambda~/
Type ai to ask about this project. Type help for commands.
Welcome to Lambda.

lists every command.

list files
go to projects
ask the AI