Results 1 to 6 of 6

Thread: How to make kernel panic

  1. #1
    Join Date
    Nov 2008
    Location
    Melbourne Fl
    Beans
    66

    How to make kernel panic

    Hi,

    I know that this is a strange request; but, I am looking to write some C code that causes kernel panic. I have been looking at some of the panic() man pages and I have derived two non-working solutions both similar to:

    Code:
    #include <stdio.h>
    #include <sys/types.h>
    #include <unistd.h>
    #include <tcl.h>
    int main(){
    	panic("Test");
    	return 0;
    }
    The other is using the panic() function in sys/systm.h. The issue I am having in both cases is that tcl.h or sys/systm.h cannot be found.

    Code:
    joseph@joseph-touch:~$ gcc KernelPanic.c
    KernelPanic.c:4:17: error: tcl.h: No such file or directory
    Does anyone have any advise on how I could get this working?

    Thanks
    Joseph

  2. #2
    Join Date
    Apr 2006
    Location
    Atlanta, USA
    Beans
    427

    Re: How to make kernel panic

    Hi,

    Not just any program running on the system can cause the kernel to panic. In fact, I'm pretty sure a panic can only come from inside the kernel itself. So you would need to build a kernel module or patch the actual kernel source in order to trigger a panic.

    Building a kernel module will for sure be easier. Find an example for this (I'm sure there are a few on this forum or on google -- this one looks promising), and then simply call panic from your module initialization function.

    You can then case the panic by loading your kernel module with "insmod <yourmod.ko>" or "modprobe <yourmod.ko>" as root.

    Hope this helps.
    Here we are, trapped in the amber of the moment. There is no why.

  3. #3
    Join Date
    Apr 2007
    Location
    (X,Y,Z) = (0,0,0)
    Beans
    3,715

    Re: How to make kernel panic

    Wait, why do you need tcl.h? IIRC and from what I've googled, That's a header related to the Tcl programming environment's API... Maybe you were looking for linux/sysctl.h?

    Second, I'm not quite sure whether panic() is designed for user-land usage... All I find is that it's designed as something internal to the kernel, maybe accessable for kernel modules, biut not for applications for sure. You know, having an application being able to stop the kernel anytime is not what I'd call a sane design...

  4. #4
    Join Date
    Feb 2010
    Location
    Paraguay
    Beans
    169
    Distro
    Ubuntu

    Re: How to make kernel panic

    Onward and upwards,
    Kenny Meyer
    Personal Blog | DuckDuckGo | LoCo Paraguay
    Vimacs - META X term <ENTER> vim <ENTER>

  5. #5
    Join Date
    Jul 2007
    Beans
    305
    Distro
    Ubuntu 9.04 Jaunty Jackalope

    Re: How to make kernel panic

    You could mess around with /sys and /dev directories.

    dd if=/dev/zero of=/dev/mem bs=1M count=16
    should have some interesting effects.
    iplist

    "Specialization is for Insects", R. Heinlein

  6. #6
    Join Date
    Nov 2008
    Location
    Melbourne Fl
    Beans
    66

    Re: How to make kernel panic

    Quote Originally Posted by johnl View Post
    this one looks promising
    I used this tutorial and called panic() from the init function. It worked fine.

    Thanks

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •