Home Loadable Kernel Modules

Loadable Kernel Modules


Whether you are fuzzing or looking into certain Linux subsystems, you might need to set up a loadable kernel module if you selected m option on kernel config. An example would be something like Netfilter which would load that module when you use them dynamically. If you do an lsmod you should be able to see some of loadable kernel modules like nfnetlink (Netfilter component). These aren’t automatically there when you follow this syzkaller guide. In this blog, we will compile kernel and setup Qemu image so that it can load these modules.



Compiling Kernel and Image

Just follow this syzkaller guide. By default, Debian image created by create-image.sh will be 2G. Sometimes, this is not big enough especially if you compile the kernel with something like Ubuntu config. You can actually expand this image by doing qemu-img resize stretch.img +20G (This will increase the image size by 20G but you can change the number).

Then you should also increase the size insize linux guest. with tools like parted and resize2fs

parted /dev/sda resizepart 1 100%
resize2fs /dev/sda

Compiling Kernel Modules

You need to compile Linux kernel module by doing

make modules

Then Save it by doing the command below. You can replace INSTALL_MOD_PATH with the path you want.

INSTALL_MOD_PATH=./linux_modules make modules_install

Then move the linux_modules folder to Qemu host using scp. In guest Linux, move the /lib folder under linux_modules to system /lib. It should look something like below. Note that the folder path needs to match uname -r

Once that is done do and restart.

depmod -a

If you do lsmod, it should have bunch of loadable modules if your kernel is expecting loadable kernel modules.

This post is licensed under CC BY 4.0 by the author.

Visualizing KCOV with syz-cover

srsRan 4G Setup