How To Cause An Oops

Chris Van Hoof vanhoof at canonical.com
Wed Jan 18 20:25:02 UTC 2012


On 01/17/2012 12:23 PM, Joseph Salisbury wrote:
> Hello,
> 
> Is there a way to generate or simulate an oops on purpose?  This would
> be helpful to perform testing while the kerneloops.org site is down.
> 
> Thanks,
> 
> Joe

Heya Joe -- I've had this laying around for a while; as long as
/proc/sys/kernel/panic_on_oops is set to 0 it should give you what
you're after.

--chris

vanhoof at hanzo:~/oops$ cat oops.c
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/init.h>

static void generate_oops(void) {
    *(int*)0 = 1;
}

static int __init my_oops_init(void) {
    printk("hi");
    generate_oops();
    return 0;
}
static void __exit my_oops_exit(void) {
    printk("bai");
}

module_init(my_oops_init);
module_exit(my_oops_exit);

vanhoof at hanzo:~/oops$ cat Makefile
obj-m := oops.o
KDIR := /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
SYM=$(PWD)

all:
	$(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules


vanhoof at hanzo:~/oops$ make
make -C /lib/modules/3.0.0-15-generic/build SUBDIRS=/home/vanhoof/oops
modules
make[1]: Entering directory `/usr/src/linux-headers-3.0.0-15-generic'
  CC [M]  /home/vanhoof/oops/oops.o
  Building modules, stage 2.
  MODPOST 1 modules
  CC      /home/vanhoof/oops/oops.mod.o
  LD [M]  /home/vanhoof/oops/oops.ko
make[1]: Leaving directory `/usr/src/linux-headers-3.0.0-15-generic'

vanhoof at hanzo:~/oops$ sudo insmod ./oops.ko
vanhoof at hanzo:~/oops$ dmesg
[...]
[  293.004578] oops: module license 'unspecified' taints kernel.
[  293.004584] Disabling lock debugging due to kernel taint
[  293.004832] hi
[  293.004851] BUG: unable to handle kernel NULL pointer dereference at
          (null)
[  293.004925] IP: [<ffffffffa003c012>] my_oops_init+0x12/0x1000 [oops]
[  293.004979] PGD 1572e1067 PUD 1559a7067 PMD 0
[  293.005024] Oops: 0002 [#1] SMP
[  293.005058] CPU 0
[  293.005081] Modules linked in: oops(P+) parport_pc autofs4 ppdev
snd_hda_codec_hdmi rfcomm bnep bluetooth binfmt_misc snd_hda_intel
snd_hda_codec snd_hwdep snd_pcm i915 snd_seq_midi snd_rawmidi nouveau
snd_seq_midi_event snd_seq snd_timer snd_seq_device ttm snd
drm_kms_helper drm mei(C) soundcore mxm_wmi snd_page_alloc i2c_algo_bit
wmi video lp parport ahci xhci_hcd libahci e1000e
[  293.005438]
[  293.005448] Pid: 2810, comm: insmod Tainted: P         C
3.0.0-15-generic #24-Ubuntu Intel Corporation 2012 Client
Platform/Emerald Lake
[  293.005513] RIP: 0010:[<ffffffffa003c012>]  [<ffffffffa003c012>]
my_oops_init+0x12/0x1000 [oops]
[  293.005558] RSP: 0018:ffff880155ab5f18  EFLAGS: 00010292
[  293.005584] RAX: 0000000000000014 RBX: ffffffffa009f000 RCX:
000000000003ffff
[  293.005630] RDX: 0000000000000000 RSI: 0000000000000082 RDI:
0000000000000246
[  293.005681] RBP: ffff880155ab5f18 R08: 000000000000000a R09:
0000000000000000
[  293.005732] R10: 0000000000000000 R11: 0000000000000000 R12:
0000000000000000
[  293.005784] R13: ffffffffa003c000 R14: 00000000015a8010 R15:
0000000000000003
[  293.005836] FS:  00007f19cfc29720(0000) GS:ffff88015e200000(0000)
knlGS:0000000000000000
[  293.005895] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[  293.005937] CR2: 0000000000000000 CR3: 000000015357f000 CR4:
00000000001406f0
[  293.005988] DR0: 0000000000000000 DR1: 0000000000000000 DR2:
0000000000000000
[  293.006039] DR3: 0000000000000000 DR6: 00000000ffff0ff0 DR7:
0000000000000400
[  293.006091] Process insmod (pid: 2810, threadinfo ffff880155ab4000,
task ffff88013a442e40)
[  293.006149] Stack:
[  293.006166]  ffff880155ab5f48 ffffffff81002042 ffffffffa009f000
ffffffffffffffff
[  293.006230]  0000000000000d4e 00000000015a8010 ffff880155ab5f78
ffffffff8109fede
[  293.006293]  00007fff3bc46992 00000000015a8010 0000000000000d4e
0000000000004000
[  293.006357] Call Trace:
[  293.006383]  [<ffffffff81002042>] do_one_initcall+0x42/0x180
[  293.006428]  [<ffffffff8109fede>] sys_init_module+0xbe/0x230
[  293.006473]  [<ffffffff815fa3c2>] system_call_fastpath+0x16/0x1b
[  293.006517] Code: <c7> 04 25 00 00 00 00 01 00 00 00 31 c0 5d c3 00
00 00 00 00 00 00
[  293.006651] RIP  [<ffffffffa003c012>] my_oops_init+0x12/0x1000 [oops]
[  293.006704]  RSP <ffff880155ab5f18>
[  293.006730] CR2: 0000000000000000
[  293.066044] ---[ end trace 4e561320e5a93aba ]---






More information about the kernel-team mailing list