0

insmod/rmmod doesn't recognize the arguments. Even insmod without any argument also gets executed. It looks like only command is recognized by the system.

Through insmod command kernel module can be inserted dynamically but when I do insmod testStub.ko, nothing is happening. Neither do I see my module in lsmod result nor any printk messages that I have written in my testStub.c, in dmesg.

lsmod/modprobe -l also don't show any output.

lsmod command is supposed to show all running modules .in my system it gives no output.

This is testStub.c:

#include <linux/module.h> /* Needed by all modules */
#include <linux/kernel.h> /* Needed for KERN_INFO */

int init_module(void)
{
    printk(KERN_EMERG "Module Attached");
    return 0;
}

void cleanup_module(void)
{
    printk(KERN_INFO "Module Detached!\n");
}

This is Makefile:

obj-m += testStub.o

all:
        make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules

clean:
        make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
Sam Protsenko
  • 14,045
  • 4
  • 59
  • 75
  • 1
    It is not clear what you are asking or experiencing. Try giving example command and responses. That should help overcome your English limitations. – nategoose Jun 11 '15 at 15:48
  • @nategoose .I have added the details.now does description make you understand the problem ? – Shailendra Saxena Jun 11 '15 at 18:19
  • 1
    No. People reading your question should be able to attempt to repeat the output. What does `cat /proc/modules` print? – nategoose Jun 11 '15 at 19:14
  • 1
    What value is returned by `insmod sample.ko`? (Can be viewed by executing `echo $?` after it in the same terminal). Also, name and version of your distro would be helpfull, same for kernel version you load. – Tsyvarev Jun 11 '15 at 21:08
  • @Tsyvarev insmod sample.ko returns 0. System- Linux(Ubuntu 14.04 ), Release-3.13.0-45-generic, Machine- x86_64 – Shailendra Saxena Jun 12 '15 at 05:26
  • @nategoose cat /proc/modules prints all running modules. But my sample module is not there. – Shailendra Saxena Jun 12 '15 at 05:36
  • Try to add this in your code:`module_init(init_module);` – shuofei Jun 12 '15 at 06:00
  • @shuofoi Not required. go through the following link. http://www.tldp.org/LDP/lkmpg/2.4/html/c147.htm – Shailendra Saxena Jun 12 '15 at 06:19
  • As `insmod` works even without arguments... What output of `insmod --version` is? And where `insmod` is placed in the filesystem (output of `which insmod`)? BTW, your question tells about `sample.ko` module and `sample.c` source, but according to your code, these should be `testStub.ko` and `testStub.c` correspondingly. – Tsyvarev Jun 12 '15 at 10:12
  • insmod --version = no output, find / -name insmod = /usr/share/bash-completion/completions/insmod, /usr/lib/klibc/bin/insmod, /sbin/insmod. Sorry. i have updated proper file names in the question. – Shailendra Saxena Jun 12 '15 at 10:50
  • Probably, you have another program, named `insmod`. One, which loads kernel modules, is `/sbin/insmod`. Try to use it explicitely: `/sbin/insmod testStub.ko`. – Tsyvarev Jun 12 '15 at 17:53
  • 1
    Calling functions `init_module`/`cleanup_module` is not enough for Linux >2.6, you need to use `module_init`/`module_exit` macro like here: http://stackoverflow.com/questions/3218320/module-init-and-init-module-of-linux – myaut Jun 13 '15 at 13:35
  • @myaut: Question (and answers to it) you refer to just say, that both variants are correct. I have checked `init_module` and `cleanup_module` with 3.18 kernel - they work as expected. – Tsyvarev Jun 13 '15 at 19:58
  • @ShailendraSaxena What does `which insmod` output? Also, run the `file` and `ls -l` on what is returned. If `insmod` is a symbolic link then follow the link so that we can find out what's really being run. If you find a shell script, then look at and possibly share the text of it. – nategoose Jun 16 '15 at 13:44
  • @nategoose which insmod -/sbin/insmod; insmod is a symbolic link and linked to /bin/kmod. ls -l /sbin/insmod; lrwxrwxrwx 1 root root 9 Sep 11 2014 /sbin/insmod -> /bin/kmod. – Shailendra Saxena Jun 17 '15 at 06:00
  • file /sbin/insmod -/sbin/insmod: symbolic link to `/bin/kmod' – Shailendra Saxena Jun 17 '15 at 06:10
  • @nategoose vi /bin/kmod; this file is empty. who deleted the content of this file ? that's why insmod is not taking any action. how to recover this file ? – Shailendra Saxena Jun 17 '15 at 06:14
  • @ShailendraSaxena Why would you choose to use `vi` to check the contents of that file? It's likely a binary file of some type, and at best you should expect jibberish. Run `file` and `ls -l` on it. – nategoose Jun 17 '15 at 14:38
  • @ShailendraSaxena Is the computer that you're using your computer? Is it possible that you're running in a `chroot`ed login? – nategoose Jun 17 '15 at 14:40
  • @nategoose yes i have root access. I can directly login as a root into the machine. Yes i was expecting jibberish in the file /bin/kmod like /bin/grep has. it should have binary content that gets executed on calling insmod. – Shailendra Saxena Jun 18 '15 at 06:05
  • @ShailendraSaxena I wouldn't expect running an empty file to fail so silently. From your home directory try `touch empty_file ; chmod +x empty_file ; ./empty_file`. Your shell program should give you some type of error message. – nategoose Jun 18 '15 at 15:27

1 Answers1

0

Your source file is missing module license this taints the kernel when you try to insert the module. add below line to your source code to make it work.

MODULE_LICENSE("GPL");

Vikram N
  • 41
  • 3