abhinav007 |
03-08-2018 12:06 AM |
Details
@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:
module1.c
Code:
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/fs.h>
#include <linux/cdev.h>
#include <linux/semaphore.h>
#include <asm/uaccess.h>
#include <linux/init.h>
static int __init driver_entry(void)
{
printk(KERN_ALERT "module1: module entered");
return 0;
}
static void __exit driver_exit(void)
{
printk(KERN_ALERT "module1: module exit");
}
module_init(driver_entry);
module_exit(driver_exit);
MODULE_AUTHOR("Abhi");
MODULE_DESCRIPTION("Simple driver");
MODULE_LICENSE("GPL");
Makefile:
Code:
CONFIG_MODULE_SIG=n
obj-m := module1.o
KERNEL_DIR = /lib/modules/$(shell uname -r)/build
all:
$(MAKE) -C $(KERNEL_DIR) M=$(PWD) modules
clean:
$(MAKE) -C $(KERNEL_DIR) M=$(PWD) clean
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:
Code:
abhinav@abhinav-VirtualBox:~/tuts/ch1$ ls
Makefile module1.c
abhinav@abhinav-VirtualBox:~/tuts/ch1$ dmesg
abhinav@abhinav-VirtualBox:~/tuts/ch1$ make
make -C /lib/modules/4.13.0-36-generic/build M=/home/abhinav/tuts/ch1 modules
make[1]: Entering directory '/usr/src/linux-headers-4.13.0-36-generic'
CC [M] /home/abhinav/tuts/ch1/module1.o
Building modules, stage 2.
MODPOST 1 modules
CC /home/abhinav/tuts/ch1/module1.mod.o
LD [M] /home/abhinav/tuts/ch1/module1.ko
make[1]: Leaving directory '/usr/src/linux-headers-4.13.0-36-generic'
abhinav@abhinav-VirtualBox:~/tuts/ch1$ sudo insmod module1.ko
abhinav@abhinav-VirtualBox:~/tuts/ch1$ dmesg
[ 1420.222942] module1: module exit
abhinav@abhinav-VirtualBox:~/tuts/ch1$ lsmod
Module Size Used by
module1 16384 0
snd_intel8x0 40960 2
snd_ac97_codec 131072 1 snd_intel8x0
intel_powerclamp 16384 0
ac97_bus 16384 1 snd_ac97_codec
snd_pcm 98304 2 snd_ac97_codec,snd_intel8x0
crct10dif_pclmul 16384 0
crc32_pclmul 16384 0
ghash_clmulni_intel 16384 0
cryptd 24576 1 ghash_clmulni_intel
joydev 20480 0
intel_rapl_perf 16384 0
snd_seq_midi 16384 0
input_leds 16384 0
snd_seq_midi_event 16384 1 snd_seq_midi
snd_rawmidi 32768 1 snd_seq_midi
snd_seq 65536 2 snd_seq_midi_event,snd_seq_midi
serio_raw 16384 0
snd_seq_device 16384 3 snd_seq,snd_rawmidi,snd_seq_midi
vboxvideo 53248 2
ttm 94208 1 vboxvideo
drm_kms_helper 167936 1 vboxvideo
snd_timer 32768 2 snd_seq,snd_pcm
drm 360448 5 vboxvideo,ttm,drm_kms_helper
fb_sys_fops 16384 1 drm_kms_helper
syscopyarea 16384 2 vboxvideo,drm_kms_helper
snd 81920 11 snd_seq,snd_ac97_codec,snd_timer,snd_rawmidi,snd_intel8x0,snd_seq_device,snd_pcm
vboxguest 294912 1 vboxvideo
mac_hid 16384 0
sysfillrect 16384 2 vboxvideo,drm_kms_helper
i2c_piix4 24576 0
sysimgblt 16384 2 vboxvideo,drm_kms_helper
soundcore 16384 1 snd
parport_pc 32768 0
ppdev 20480 0
lp 20480 0
parport 49152 3 lp,parport_pc,ppdev
autofs4 40960 2
hid_generic 16384 0
usbhid 49152 0
hid 118784 2 hid_generic,usbhid
ahci 36864 2
e1000 143360 0
psmouse 147456 0
libahci 32768 1 ahci
pata_acpi 16384 0
video 40960 0
abhinav@abhinav-VirtualBox:~/tuts/ch1$ sudo rmmod module1.ko
abhinav@abhinav-VirtualBox:~/tuts/ch1$ dmesg
[ 1420.222942] module1: module exit
[ 2283.046381] module1: module entered
abhinav@abhinav-VirtualBox:~/tuts/ch1$ lsmod
Module Size Used by
snd_intel8x0 40960 2
snd_ac97_codec 131072 1 snd_intel8x0
intel_powerclamp 16384 0
ac97_bus 16384 1 snd_ac97_codec
snd_pcm 98304 2 snd_ac97_codec,snd_intel8x0
crct10dif_pclmul 16384 0
crc32_pclmul 16384 0
ghash_clmulni_intel 16384 0
cryptd 24576 1 ghash_clmulni_intel
joydev 20480 0
intel_rapl_perf 16384 0
snd_seq_midi 16384 0
input_leds 16384 0
snd_seq_midi_event 16384 1 snd_seq_midi
snd_rawmidi 32768 1 snd_seq_midi
snd_seq 65536 2 snd_seq_midi_event,snd_seq_midi
serio_raw 16384 0
snd_seq_device 16384 3 snd_seq,snd_rawmidi,snd_seq_midi
vboxvideo 53248 2
ttm 94208 1 vboxvideo
drm_kms_helper 167936 1 vboxvideo
snd_timer 32768 2 snd_seq,snd_pcm
drm 360448 5 vboxvideo,ttm,drm_kms_helper
fb_sys_fops 16384 1 drm_kms_helper
syscopyarea 16384 2 vboxvideo,drm_kms_helper
snd 81920 11 snd_seq,snd_ac97_codec,snd_timer,snd_rawmidi,snd_intel8x0,snd_seq_device,snd_pcm
vboxguest 294912 1 vboxvideo
mac_hid 16384 0
sysfillrect 16384 2 vboxvideo,drm_kms_helper
i2c_piix4 24576 0
sysimgblt 16384 2 vboxvideo,drm_kms_helper
soundcore 16384 1 snd
parport_pc 32768 0
ppdev 20480 0
lp 20480 0
parport 49152 3 lp,parport_pc,ppdev
autofs4 40960 2
hid_generic 16384 0
usbhid 49152 0
hid 118784 2 hid_generic,usbhid
ahci 36864 2
e1000 143360 0
psmouse 147456 0
libahci 32768 1 ahci
pata_acpi 16384 0
video 40960 0
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?
|