也许在内核中,标志CONFIG_DEBUG_INFO没有打开或syslogd没有运行。在我的 ubuntu 系统中工作正常
1 #include <linux/kernel.h>
2 #include <linux/module.h>
3 #include <linux/init.h>
4
5 static void create_oops() {
6 *(int *)0 = 0;
7 }
8
9 static int __init my_oops_init(void) {
10 printk("oops from the module\n");
11 create_oops();
12 return (0);
13 }
14 static void __exit my_oops_exit(void) {
15 printk("Goodbye world\n");
16 }
17
18 module_init(my_oops_init);
19 module_exit(my_oops_exit);
~
生成文件
1 obj-m := oops.o
2 KDIR := /lib/modules/$(shell uname -r)/build
3 PWD := $(shell pwd)
4 SYM=$(PWD)
5 KBUILD_CFLAGS += -Wno-error=strict-prototypes
6 all:
7 $(MAKE) -k -C $(KDIR) SUBDIRS=$(PWD) modules
⋊> uname -a
Linux zjp 4.18.0-25-generic #26-Ubuntu SMP Mon Jun 24 09:32:08 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
4402 Aug 13 19:56:01 zjp kernel: [117908.066176] oops: loading out-of-tree module taints kernel.
4403 Aug 13 19:56:01 zjp kernel: [117908.066180] oops: module license 'unspecified' taints kernel.
4404 Aug 13 19:56:01 zjp kernel: [117908.066181] Disabling lock debugging due to kernel taint
4405 Aug 13 19:56:01 zjp kernel: [117908.066242] oops: module verification failed: signature and/or required key missing - tainting kernel
4406 Aug 13 19:56:01 zjp kernel: [117908.066491] oops from the module
4407 Aug 13 19:56:01 zjp kernel: [117908.066498] BUG: unable to handle kernel NULL pointer dereference at 0000000000000000
4408 Aug 13 19:56:01 zjp kernel: [117908.066503] PGD 0 P4D 0