4

I am just starting with modular programming.

Above are my two files:

hello.c

#include <linux/init.h>
#include <linux/module.h>

static int hello_init(void)
{
    printk(KERN_ALERT "TEST: Hello world\n");
    return 0;
}

static void hello_exit(void)
{
    printk(KERN_ALERT "TEST: Good Bye");
}

module_init(hello_init);
module_exit(hello_exit);

Makefile

obj-m += hello.o

KDIR = /usr/src/linux-headers-3.13.0-46-generic

all:
    $(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules

clean:
    rm -rf *.o *.ko *.mod.* *.symvers *.order

And here's my terminal output showing error in insmod command, kindly help.

anubhav@anubhav-Inspiron-3421:~/Desktop/os$ make
make -C /usr/src/linux-headers-3.13.0-46-generic  SUBDIRS=/home/anubhav/Desktop/os modules
make[1]: Entering directory `/usr/src/linux-headers-3.13.0-46-generic'
Building modules, stage 2.
MODPOST 1 modules
make[1]: Leaving directory `/usr/src/linux-headers-3.13.0-46-generic'
anubhav@anubhav-Inspiron-3421:~/Desktop/os$ insmod hello.ko
insmod: ERROR: could not insert module hello.ko: Operation not permitted
5
  • 3
    Only the root user typically has permissions to insert/remove kernel modules. Either su to root, or use sudo (if applicable) to run the command as root. Commented Mar 13, 2015 at 16:12
  • @lsowen I tried "su" and "su -". But after providing password, i get the msg "su: Authentication failure". Any other way to move ahead Commented Mar 13, 2015 at 16:17
  • This message means you put in the wrong password (or are not a member of a user group allowed to become root). The password you need to use at su is the root password, not your user password. Commented Mar 13, 2015 at 16:19
  • 1
    @lsowen ubuntu website says that user can prepend any command that needs to be executed as root with sudo command. My insmod command worked and i got the message using dmesg. Thanks. Commented Mar 13, 2015 at 16:25
  • 1
    And you dont see printk(KERN_ALERT "TEST: Good Bye"); because you have not done rmmod hello have you? Commented Mar 13, 2015 at 17:00

3 Answers 3

3

If you have secure boot enabled, the newer kernels won't allow inserting arbitrary kernel modules. So, either you can disable secure boot in your BIOS or you need to sign the kernel modules you want to install.

Steps to securely sign your kernel modules:

  1. Create a X509 certificate that can be imported in firmware
  2. Enrolling the public key just created
  3. Sign the module you want to install
  4. Install the module

You need to be root to do steps 2 & 4. The detailed process is described in a nice Ubuntu blog.

Sign up to request clarification or add additional context in comments.

Comments

1

As isowen mentioned only root can load or unload the module.

You see the print in hello_init() when you do insmod hello and you see the print in hello_exit() when you do rmmod hello.

Comments

0

execute cat /proc/sys/kernel/modules_disabled and if you see the result 1 then execute echo 'kernel.modules_disabled=1' >> /etc/sysctl.d/99-custom.conf then reboot and try again. ;) BR nu11secur1ty

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.