11

If I could write a user program that would crash my OS (not my application), how would I do it?

I was thinking somehow switch my usermode program to kernel mode and cause a memory corruption. Is it possible?

Note: I am not creating a virus. Just curiosity.

Cœur
  • 37,241
  • 25
  • 195
  • 267
SysAdmin
  • 5,455
  • 8
  • 33
  • 34

10 Answers10

8

KeBugCheck on Windows is the documented way to get a BSOD.

You can also try deleting the root registry key (\REGISTRY) in Windows XP, using the native NT API.

user541686
  • 205,094
  • 128
  • 528
  • 886
7

Write and load a kernel module that calls panic() or implement equivalent thereof.

Or simply exec the shutdown or halt command or the syscall that implements it.

Chris Stratton
  • 39,853
  • 6
  • 84
  • 117
6

If the OS happens to be windows, create a fake driver that dereferences a NULL pointer. Crash!

Tony The Lion
  • 61,704
  • 67
  • 242
  • 415
4

The whole idea of an operating system is that a user program can't crash it under normal conditions. Of course you could still do something like exhaust the disk space on a partition that is used for a swap file and that would impair many operating systems or you could find a known vulnerability but there's no very easy way to reliably crash it.

sharptooth
  • 167,383
  • 100
  • 513
  • 979
3

In Linux, Alt-SysRq-C will crash/restart your kernel.

In Windows, see: https://web.archive.org/web/20110513143420/http://www.dailygyan.com/2008/09/some-methods-to-crash-your-windows.html [Ed: March 8, 2021 - Switch to Archive.org link due to site going down.]

entropo
  • 2,481
  • 15
  • 15
2

For Windows one possibility is to write a kernel mode driver which locks some memory pages owned by a process and then terminate that process. Will result in a BSOD "Process has locked pages".

ur.
  • 2,890
  • 1
  • 18
  • 21
1

Linux: Even though not strictly crashing the OS, you can quite easily make it unusable by allocating lots of memory (and read/writing it for the allocation to actually become effective and make the OS swap a lot) and by forking lots of processes. "Fork bomb" is the keyword and can even be done in shell script.

Tilman Vogel
  • 9,337
  • 4
  • 33
  • 32
1

I think the reason why you want to crash the OS is relevant here. Are you trying to simulate a condition for testing, or are you just plain curious?

Here are two options if you wish to recreate, and automate, crashing, for the purpose of fault tolerance.

  • Run insider a virtual machine (vmware, VirtualBox) and simply kill the VM process. Alternately you can give it very low priority, drop devices, or otherwise simulate bad things.
  • Use servers that have a management console. This will have an API that can simply turn off the device.

The other numerous suggestions are good if you wish to crash from within the OS itself. These software crashes can help reproduce a miscreant process. A similar set of hardware related crashes could also work (such as reducing speed on a programmable fan and overheating the CPU).

The reason behind your request is actually quite important since all the different faults will yield a slightly different result.

edA-qa mort-ora-y
  • 30,295
  • 39
  • 137
  • 267
0

Try allocating chunks of memory until you have no free memory:

int alloced = 0;
for(;;)
{
    char *alloc = malloc(10*1024*1024); // alloc 10 MB
    if(alloc != NULL)
    {
        alloced += 10;
        // edit: you have to memset the memory otherwise the system will give it back to you next time
        memset(alloc, 0xab, 10*1024*1024);
        printf(" alloced %d MB\n", alloced);
    }
}

edit: I actually tried just right now on a 64 bits linux with 2GB of ram and 3.3GB of swap: the screen has frozen, I could allocate 4950MB of ram, but then the process was killed by the system, and linux fell back on its feet gracefully, so, no, this doesnt work :=)

Gui13
  • 12,993
  • 17
  • 57
  • 104
  • 3
    Virtual memory and paging means you're going to be there a while. And at least in Windows, you'll crash your application's own process *long* before you crash the OS. – Cody Gray - on strike Apr 29 '11 at 07:40
  • The trick is to allocate and access enough for the system to become terribly slow but not as much that the OOM killer gets after you. Then, "working" on that memory will make the system basically unusable. In my view, Linux is not very robust against that situation. – Tilman Vogel Apr 29 '11 at 16:18
  • You could launch a thread constantly writing thing on each memory chunk? :D – Gui13 Apr 29 '11 at 16:27
0

Crash an OS using pure user-mode application means the kernel is vulnerable. If the OS is well tested, then this should not occur.

You can try BSoD Windows by attacking bugous 3rd-party drivers via sending garbage IO-CONTROLs to them.

DeviceIoControl Function (Windows) http://msdn.microsoft.com/en-us/library/aa363216(VS.85).aspx

Peter
  • 1,048
  • 10
  • 23