Is it possible to cause a kernel panic with a single command line?
What would be the most straightforward such command for a sudoing user and what would it be for a regular user, if any?
Scenarios that suggest downloading something as a part of the command do not count.
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
FreeBSD:
sysctl debug.kdb.panic=1
Linux (more info in the kernel documentation):
echo c > /proc/sysrq-trigger
Method 2
mkdir /tmp/kpanic && cd /tmp/kpanic && printf '#include <linux/kernel.h>n#include <linux/module.h>nMODULE_LICENSE("GPL");static int8_t* message = "buffer overrun at 0x4ba4c73e73acce54";int init_module(void){panic(message);return 0;}' > kpanic.c && printf 'obj-m += kpanic.onall:ntmake -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules' > Makefile && make && insmod kpanic.ko
Compiles a module that crashes the kernel by calling the panic function, needs root, requires make and gcc
Replace the “buffer overrun at 0x4ba4c73e73acce54” in the command with something interesting for more drama.
Method 3
The kernel is meant to keep running no matter what. So any way to cause a kernel panic by user interaction (other than deliberate vandalism by all-powerful root, like Bruce Ediger jokingly proposes, and most kernels today are built so most of those pranks won’t work in the first place) is an extremely serious bug, that would get fixed fast.
Method 4
The easiest thing is to hold down alt + print screen (sysrq) and press c while still holding them
It does the same as echo c > /proc/sysrq-trigger
A little explanation: the sysrq key is used to send low-level commands to the kernel itself, as a last resort to try to save the system. If you hold alt + print screen(sysrq) down and press another key next to them, it does the same as if you were to echo the key in that sysrq-trigger file. They call it trigger for a reason ;3
The ‘c’ tells the kernel to crash (cause a kernel panic)
However, you may want to see the content of ‘proc/sys/kernel/sysrq’. If it is 178 or anything else, you should change it to 1. 0 is all disabled, 1 is all enabled, and anything larger than 1 is a bitmap for the specific things the kernel allows to do with sysrq.
Method 5
Try this:
dd if=/dev/urandom of=/proc/sysrq-trigger
This did a very fast kernel panic for me, but I’m not sure how safe the process is because I did it on the live Ubuntu installation. But the kernel did spam error messages at me when I did it in the pure terminal environment.
Method 6
compile the following code into a module and insmod it, sure you should get a panic:
static int crash_module_init(void)
{
printf("crash module startingn");
int *p = 0;
printk("%dn", *p);
return 0;
}
static void crash_module_exit(void)
{
printf("crash module exitingn");
}
module_init(crash_module_init);
module_exit(crash_module_exit);
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0