[SOLVED] Kernel module unexpected exit when using insmod
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
The module compiles without error.I previously received a module verification error due to signature while insmod hence added the CONFIG_MODULE_SIG=n.
I am using the virtualbox environment running Ubuntu 16.04. However, when I insert the module using insmod, the "module exited" message appears highlighted with red background in dmesg log even before the "module entry" message. The function driver_exit gets executed automatically with the insmod call. Not able to understand this phenomenon?
@smallpond, I have checked with lsmod and the module was not loaded before insmod was used. I changed the Makefile to compile with /lib/modules/$(shell uname -r)/build instead of /usr/src/linux-headers-$(shell uname -r).I am posting the full code below:
The module throws compile error if I try to compile with "sudo make", but compiles successfully without the use of "sudo". I am attaching the log below:
Can clearly verify that module is loaded and unloaded by using lsmod, but not sure what is actually going behind the execution. It seems driver_exit function is triggered as soon as the module is instatiated by insmod. Could it be still the module verification error due to missing signature?
Is there some compelling reason you are using insmod instead of modprobe?
Seems there a lot of work needs to be done with modprobe. It demands the module to be present in /lib/usr/$(shell uname -r) directory. Also I tried modules_install but it throws error that
Code:
cp: cannot stat './modules.order':No such file or directory
Also I found many methods to compile and load LKM, it has become slightly confusing
Modprobe is more trouble, but it also makes more checks, and it doesn't mysteriously fail like insmod.
I used modprobe this time by making a symbolic link and depmod. No change in the output though.
It seems that the driver_entry and driver_exit are behaving exactly opposite than intended. driver_exit is executed when the module is instantiated and driver_entry is executed when rmmod is used. The message indicating module is out-of-tree build and module verification failure appears initially every time I restart the system and load the module for the first time (even though CONFIG_MODULE_SIG=n in makefile). I also checked that CONFIG_MODULE_SIG_FORCE is not enabled.
Could it be that dmesg log is lagging behind or something similar?
Last edited by abhinav007; 03-11-2018 at 10:45 PM.
Found the solution. It was the most stupid thing I could imagine, just added "\n" at the end of printk message. Guess the module was working properly but dmesg didn't show correct log until I added a newline at the end of the KERN_INFO & KERN_ALERT message.
But still wonder how this issue prompted "module exited" before "module entry" ?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.