Segmentation error when rmmod or modprobe -r

Try the simplest kernel module from LDD3 without any changes to the purpose-built kernel v4.1.0-rc6 for the Beagle Bone board with BusyBox v1.23.0. The code for the module is as follows:

#include <linux/init.h> #include <linux/module.h> MODULE_LICENSE("Dual BSD/GPL"); static int hello_init(void) { printk(KERN_ALERT "Hello, world\n"); return 0; } static void hello_exit(void) { printk(KERN_ALERT "Goodbye, cruel world\n"); } module_init(hello_init); module_exit(hello_exit); 

Makefile:

 ARCH := arm CROSS_COMPILE := arm-cortex_a8-linux-gnueabi- obj-m := hello.o all: make ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) -C /path/to/linux/source/tree M=$(PWD) modules clean: make ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) -C /path/to/linux/source/tree M=$(PWD) clean 

The module compiles and installs on rootfs just fine. it also loads:

 $ insmod hello.ko [ 30.692404] Hello, world 

But when I try to remove it, I get:

 $ rmmod hello.ko Segmentation fault $modprobe -r hello.ko Segmentation fault $ lsmod hello 813 0 - Live 0xbf000000 (O) 

The kernel is compiled with the ability to unload the module (both regular and forced).

What is the possible cause of this problem? What is the way to approach his research?

Update:

As suggested in the comments I tried, including linux/kernel.h , defining the characters MODULE , LINUX and __KERNEL__ . Added __init and __exit to functions. Removed static modifiers. Removed printk lines. The result is the same. dmesg shows only the initial greeting. It is surprisingly surprising that loading and unloading kernel modules such as gpio_keys or crypto/ccm gpio_keys Therefore, the only thing left to suspect is a way to compile the module.

Update 2
Updating the kernel to the most recent snapshot did not help. A compiled module with various optimization settings did not help. The next step, I think, I'm going to modify BusyBox rmmod to have some indication of the location of the problem.

+5
source share
2 answers

I managed to get around this problem. Using strace , I found that segfault happens somewhere when read contains the BusyBox specificiv modules.dep.bb file. This file is used by BusyBox when it is compiled with the option "Simplified modutils" ( CONFIG_MODPROBE_SMALL ). Having disabled the option, choosing utilities for installing and restoring BusybBox, I have work on unloading the module. I believe the problem is that the test module is compiled and stored outside the /lib/..../modules directory, so busybox with simplified modutils is just confused.

0
source

Take a look at these guides:

http://www.tldp.org/HOWTO/Module-HOWTO/x839.html http://www.tldp.org/LDP/lkmpg/2.4/html/x281.htm

Try adding:

 #define MODULE #define LINUX #define __KERNEL__ #include <linux/kernel.h> /* Needed for KERN_ALERT */ 
0
source

All Articles