VKM

Table of Contents

Initial setup for debugging

  1. Install the VKM project for our vurnable kernel module.
git clone https://github.com/ft-mugurel/VKM.git
cd VKM
  • Now we need an kernel with debugging enabled.
  1. Install the linux kernel.
wget https://cdn.kernel.org/pub/linux/kernel/v6.x/linux-6.8.tar.xz
tar xvf linux-6.8.tar.xz
mv linux-6.8 linux
cd linux
  1. Create the default configuration file.
make defconfig
make kvm_guest.config
  1. Enable the following options by adding them to the .config file:
# Coverage collection.
CONFIG_KCOV=y

# Debug info for symbolization.
CONFIG_DEBUG_INFO_DWARF4=y

# Memory bug detector
CONFIG_KASAN=y
CONFIG_KASAN_INLINE=y

# Required for Debian Stretch and later
CONFIG_CONFIGFS_FS=y
CONFIG_SECURITYFS=y

Or just run the following command:

echo -e "\nCONFIG_KCOV=y\nCONFIG_DEBUG_INFO_DWARF4=y\nCONFIG_KASAN=y\nCONFIG_KASAN_INLINE=y\nCONFIG_CONFIGFS_FS=y\nCONFIG_SECURITYFS=y" >> .config

After that you need to run this command to update the configuration:

make olddefconfig
  1. Compile the kernel.
make CC="gcc -std=gnu11" -j16
  1. Create and debootstrap. First you need to install debootstrap for your distribution. Then run:
cd ..
mkdir image
cd image
wget https://raw.githubusercontent.com/google/syzkaller/master/tools/create-image.sh -O create-image.sh
chmod +x create-image.sh
./create-image.sh
cd ..

Building the kernel module and runnning inside of the qemu:

  1. Build the kernel module.
make build
  1. Run the kernel module inside of the qemu.
make loadmodule

This will upload the module in to qemu and load it into the kernel.

  1. To unload the module, run:
make unloadmodule

What is kernel module?

  • A kernel module is a piece of code that can be loaded into the kernel at runtime, allowing for dynamic extension of the kernel’s functionality.