{"id":2672,"date":"2016-12-03T15:31:58","date_gmt":"2016-12-03T22:31:58","guid":{"rendered":"http:\/\/mattfife.com\/?p=2672"},"modified":"2018-05-31T00:09:25","modified_gmt":"2018-05-31T07:09:25","slug":"module-to-cause-linux-kernel-panic","status":"publish","type":"post","link":"https:\/\/mattfife.com\/?p=2672","title":{"rendered":"Module to cause linux kernel panic"},"content":{"rendered":"<p>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.<\/p>\n<pre><code class=\"language-\" data-lang=\"\">panic.c:\r\n#define __NO_VERSION__\r\n#include &lt;linux\/version.h&gt;\r\n#include \r\n#include \r\n\r\nint init_module(void)\r\n{\r\n    panic(\" insert lame excuse here\");\r\n    return 0;\r\n}\r\n<\/code><\/pre>\n<p>Build with:<\/p>\n<pre> gcc -I\/usr\/src\/linux\/include -D__KERNEL__ -DMODULE -o panic.o -c panic.c<\/pre>\n<p>Here&#8217;s a good link about <a href=\"https:\/\/www.cyberciti.biz\/tips\/build-linux-kernel-module-against-installed-kernel-source-tree.html\" target=\"_blank\" rel=\"noopener\">building kernel modules without full kernel source<\/a>.<\/p>\n<p>Now, run the following insmod, and your system will kernel panic.<\/p>\n<pre> insmod panic.o \r\n<\/pre>\n<p>Credit to <a href=\"https:\/\/journal.paul.querna.org\/articles\/2005\/04\/09\/forcing-a-kernel-panic\/\" target=\"_blank\" rel=\"noopener\">Paul&#8217;s Journal<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 &lt;linux\/version.h&gt; #include #include int init_module(void) { panic(&#8221; insert lame excuse here&#8221;); return 0; } Build with: gcc -I\/usr\/src\/linux\/include -D__KERNEL__ -DMODULE&#8230;<\/p>\n<p class=\"read-more\"><a class=\"btn btn-default\" href=\"https:\/\/mattfife.com\/?p=2672\"> Read More<span class=\"screen-reader-text\">  Read More<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":true,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"Module to cause kernel panic","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[7,5],"tags":[],"class_list":["post-2672","post","type-post","status-publish","format-standard","hentry","category-technicalprogramming","category-technical"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p4WECr-H6","jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/mattfife.com\/index.php?rest_route=\/wp\/v2\/posts\/2672","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mattfife.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mattfife.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mattfife.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/mattfife.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2672"}],"version-history":[{"count":4,"href":"https:\/\/mattfife.com\/index.php?rest_route=\/wp\/v2\/posts\/2672\/revisions"}],"predecessor-version":[{"id":3594,"href":"https:\/\/mattfife.com\/index.php?rest_route=\/wp\/v2\/posts\/2672\/revisions\/3594"}],"wp:attachment":[{"href":"https:\/\/mattfife.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2672"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mattfife.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2672"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mattfife.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2672"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}