Module to cause linux kernel panic

Module to cause linux kernel panic

In doing some robustness testing, I needed to crash my Linux VM intentionally to see if the rest of the system survived. I was thinking of writing a kernel module that just did something silly like dereference null or divide by zero, but turns out you can do it much easier than that. Just call panic.

panic.c:
#define __NO_VERSION__
#include <linux/version.h>
#include 
#include 

int init_module(void)
{
    panic(" insert lame excuse here");
    return 0;
}

Build with:

 gcc -I/usr/src/linux/include -D__KERNEL__ -DMODULE -o panic.o -c panic.c

Here’s a good link about building kernel modules without full kernel source.

Now, run the following insmod, and your system will kernel panic.

 insmod panic.o 

Credit to Paul’s Journal

One thought on “Module to cause linux kernel panic

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.