oops in a kernel module
Kevin Wilson
wkevils at gmail.com
Sat Apr 27 12:34:00 EDT 2013
Hello,
I have written a short kernel module which should zero a network SNMP
mib. I have OOPs.
My idea was to take an existing macro that adds an integer to a network SNMP
mib and to change it so that it would zero that counter.
So I tool the TCP_ADD_STATS() macro - see in the comments of the module below.
I tried both with xor and with subtracting the value of the SNMP mib
from itself.
In both cases it fails with the same OOPS.
I will appreciate if someone could advice/suggest alternative methods.
Following is my module and the OOPs i get:
#include <linux/module.h>
#include <linux/slab.h>
#include <linux/types.h>
#include <linux/string.h>
#include <linux/errno.h>
#include <linux/skbuff.h>
#include <linux/cgroup.h>
#include <linux/rcupdate.h>
#include <linux/atomic.h>
#include <net/rtnetlink.h>
#include <net/pkt_cls.h>
#include <net/sock.h>
#include <net/snmp.h>
#include <net/net_namespace.h>
static int __init init_zeromib(void)
{
int ret = 0;
printk("in %s\n",__func__);
//#define SNMP_ADD_STATS(mib, field, addend)
this_cpu_add(mib[0]->mibs[field], addend)
//#define TCP_ADD_STATS(net, field, val)
SNMP_ADD_STATS((net)->mib.tcp_statistics, field, val)
// TCP_ADD_STATS(sock_net(sk), TCP_MIB_OUTSEGS,
// tcp_skb_pcount(skb));
#define SNMP_ZERO_STATS(mib, field) this_cpu_add(mib[0]->mibs[field],
-(mib[0]->mibs[field]))
#define TCP_ZERO_STATS(net, field)
SNMP_ZERO_STATS((net)->mib.tcp_statistics, field)
TCP_ZERO_STATS(&init_net, ICMP_MIB_OUTMSGS);
return ret;
}
static void __exit exit_zeromib(void)
{
printk("in %s\n",__func__);
}
module_init(init_zeromib);
module_exit(exit_zeromib);
MODULE_LICENSE("GPL v2");
The oops when insmoding the moudle is:
Apr 27 19:27:36 amd kernel: [ 2683.611903] in init_zeromib
Apr 27 19:27:36 amd kernel: [ 2683.611929] BUG: unable to handle
kernel paging request at 0000000000017fe0
Apr 27 19:27:36 amd kernel: [ 2683.612017] IP: [<ffffffffa0005020>]
init_zeromib+0x20/0x1000 [zeromib]
Apr 27 19:27:36 amd kernel: [ 2683.612017] PGD 3b9eb067 PUD 3c514067 PMD 0
Apr 27 19:27:36 amd kernel: [ 2683.612017] Oops: 0000 [#1] SMP
Apr 27 19:27:36 amd kernel: [ 2683.612017] Modules linked in:
zeromib(+) edac_core edac_mce_amd k8temp nv_tco i2c_nforce2 i2c_core
8139too r8169 8139cp mii ata_generic sata_nv pata_acpi pata_amd
Apr 27 19:27:36 amd kernel: [ 2683.612017] CPU 1
Apr 27 19:27:36 amd kernel: [ 2683.612017] Pid: 5620, comm: insmod Not
tainted 3.9.0-rc1+ #56 /KN9(NF-MCP55 series)
Apr 27 19:27:36 amd kernel: [ 2683.612017] RIP:
0010:[<ffffffffa0005020>] [<ffffffffa0005020>]
init_zeromib+0x20/0x1000 [zeromib]
Apr 27 19:27:36 amd kernel: [ 2683.612017] RSP: 0018:ffff88003c4e1d48
EFLAGS: 00010292
Apr 27 19:27:36 amd kernel: [ 2683.612017] RAX: 0000000000017f70 RBX:
ffff88003c4e1ee8 RCX: ffff88003fd0fa68
Apr 27 19:27:36 amd kernel: [ 2683.612017] RDX: 0000000000000000 RSI:
ffff88003fd0ded8 RDI: 0000000000000246
Apr 27 19:27:36 amd kernel: [ 2683.612017] RBP: ffff88003c4e1d48 R08:
000000000000000a R09: 00000000000016f6
Apr 27 19:27:36 amd kernel: [ 2683.612017] R10: 0000000000000000 R11:
00000000000016f5 R12: ffffffffa0005000
Apr 27 19:27:36 amd kernel: [ 2683.612017] R13: 0000000000000000 R14:
ffffffffa004b000 R15: ffff88003c5ec8a0
Apr 27 19:27:36 amd kernel: [ 2683.612017] FS: 00007f0990404700(0000)
GS:ffff88003fd00000(0000) knlGS:0000000000000000
Apr 27 19:27:36 amd kernel: [ 2683.612017] CS: 0010 DS: 0000 ES: 0000
CR0: 0000000080050033
Apr 27 19:27:36 amd kernel: [ 2683.612017] CR2: 0000000000017fe0 CR3:
000000003bab6000 CR4: 00000000000007e0
Apr 27 19:27:36 amd kernel: [ 2683.612017] DR0: 0000000000000000 DR1:
0000000000000000 DR2: 0000000000000000
Apr 27 19:27:36 amd kernel: [ 2683.612017] DR3: 0000000000000000 DR6:
00000000ffff0ff0 DR7: 0000000000000400
Apr 27 19:27:36 amd kernel: [ 2683.612017] Process insmod (pid: 5620,
threadinfo ffff88003c4e0000, task ffff88003be5ae80)
Apr 27 19:27:36 amd kernel: [ 2683.612017] Stack:
Apr 27 19:27:36 amd kernel: [ 2683.612017] ffff88003c4e1d78
ffffffff8100215a ffff88003c4e1ee8 ffffffffa004b018
Apr 27 19:27:36 amd kernel: [ 2683.612017] ffffffffa004b050
ffffffffa004b000 ffff88003c4e1ed8 ffffffff810c2276
Apr 27 19:27:36 amd kernel: [ 2683.612017] ffffffff81328240
ffffffff81a0cc98 ffff88003c4e1ef8 ffff880000000000
Apr 27 19:27:36 amd kernel: [ 2683.612017] Call Trace:
Apr 27 19:27:36 amd kernel: [ 2683.612017] [<ffffffff8100215a>]
do_one_initcall+0x12a/0x180
Apr 27 19:27:36 amd kernel: [ 2683.612017] [<ffffffff810c2276>]
load_module+0x1c16/0x27a0
Apr 27 19:27:36 amd kernel: [ 2683.612017] [<ffffffff81328240>] ?
ddebug_proc_open+0xc0/0xc0
Apr 27 19:27:36 amd kernel: [ 2683.612017] [<ffffffff8115c162>] ?
insert_vmalloc_vmlist+0x22/0x80
Apr 27 19:27:36 amd kernel: [ 2683.612017] [<ffffffff810c2eae>]
sys_init_module+0xae/0x110
Apr 27 19:27:36 amd kernel: [ 2683.612017] [<ffffffff8159c659>]
system_call_fastpath+0x16/0x1b
Apr 27 19:27:36 amd kernel: [ 2683.612017] Code: <48> 8b 50 70 48 f7
da 65 48 01 50 70 31 c0 5d c3 00 00 00 00 00 00
Apr 27 19:27:36 amd kernel: [ 2683.612017] RIP [<ffffffffa0005020>]
init_zeromib+0x20/0x1000 [zeromib]
Apr 27 19:27:36 amd kernel: [ 2683.612017] RSP <ffff88003c4e1d48>
Apr 27 19:27:36 amd kernel: [ 2683.612017] CR2: 0000000000017fe0
Apr 27 19:27:36 amd kernel: [ 2683.638099] ---[ end trace 95e77c0f2eeae8bc ]--
rgs,
Kevin
More information about the Kernelnewbies
mailing list