Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Servers, nginx and Docker

insmod says Operation not permitted when loading a kernel module

Errorinsmod: ERROR: could not insert module HelloWorld.ko: Operation not permitted

Short answer

Operation not permitted is the kernel's EPERM reply to a module load. The kernel documents two reasons: the caller lacks the CAP_SYS_MODULE privilege (run it as root), or module loading has been turned off with the kernel.modules_disabled switch, which only a reboot clears.

  • Applies to Linux kernel 6.x, kmod, Ubuntu 24.04
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Ask the kernel log what it said about the failed load; insmod itself only prints a general message.

    sudo dmesg | tail -n 20
  2. 2Match what you see, then jump to its fix

    1. 1The command was typed without sudo, as a normal userinsmod ran without root privilegeFix
    2. 2It fails with Operation not permitted even with sudo, for every module, not only yoursModule loading is disabled on the running kernelFix

What does the error look like?

  • insmod: ERROR: could not insert module HelloWorld.ko: Operation not permitted

Cause 1 of 2

insmod ran without root privilege

1Check

Loading a module needs the CAP_SYS_MODULE capability. A normal account does not have it.

id -u

2Fix

Run the command as root. For a module in your build folder, give insmod the path to the .ko file.

sudo insmod ./HelloWorld.ko

3Verify

The module shows up in the loaded list.

lsmod | grep -i helloworld

Confirmed by man7.org

Did this fix it?

Cause 2 of 2

Module loading is disabled on the running kernel

1Check

The kernel.modules_disabled toggle stops all loading and unloading once it is set to 1, and it cannot be set back to 0 without a reboot.

cat /proc/sys/kernel/modules_disabled

2Fix

If the value is 1, reboot the machine. To find what sets it at boot, search your sysctl configuration for the setting.

grep -rn 'modules_disabled' /etc/sysctl.conf /etc/sysctl.d/ /usr/lib/sysctl.d/ 2>/dev/null

3Verify

After the reboot the value reads 0 and the load works.

cat /proc/sys/kernel/modules_disabled
sudo insmod ./HelloWorld.ko

Confirmed by kernel.org

Did this fix it?

How do I stop it coming back?

  • Use sudo for module operations, and prefer modprobe for modules that are installed, since the insmod manual recommends it for most users.
  • Only set kernel.modules_disabled after every needed module is loaded, and document it.
  • Read dmesg first: insmod reports only the most general messages.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Related fixes

Servers

dnf cannot install MySQL on Amazon Linux 2023

dnf cannot find a mysql-server package on Amazon Linux 2023

Amazon Linux 2023 documents MariaDB, not MySQL, as its database server, with packages named mariadb105 and mariadb105-server.

3 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.