Forcing a Kernel Panic

Ever Wondered how to panic a Linux Kernel? It is really easy. Here is your source code:

Quote from panic.c:
#define __NO_VERSION__
#include <linux/version.h>
#include <linux/kernel.h>
#include <linux/module.h>

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

Then compile it with gcc -I/usr/src/linux/include -D__KERNEL__ -DMODULE -o panic.o -c panic.c.
Now just run insmod panic.o.

Okay, So I was a little bored tonight.

2 Responses to “Forcing a Kernel Panic”

  1. benito says:

    This code does not compile on 2.6.23 and 2.6.24.

  2. augu and gaspa says:

    Tried this in 2.6.23, and it works:

    freeze.c:

    #include

    int freeze_init_module(void) {
    panic(“BOOM!”);
    return 0;
    }

    module_init(freeze_init_module);

    Makefile:

    KERNELDIR=”/usr/src/linux”

    obj-m += freeze.o

    all:
    $(MAKE) -C $(KERNELDIR) M=$(PWD) modules

Leave a Reply