YOB
YOB

Reputation: 11

Why am I getting "operation not permitted" when trying to install a Linux kernel module?

I'm having some trouble when trying to run a very simple piece of code and couldn't find out what the reason could be.

I am getting

operation not permitted

when trying to install a Linux kernel module from a .ko file (KO_NAME).

This is an excerpt of the code:

if (strcmp(argv[1], "-init")==0) {

    fd=open(KO_NAME, O_RDONLY|O_CLOEXEC);
    if (fd<0) {
      perror("Error");
      printf("Error number: %d\n", errno);
    } else {
      printf("fd: %d\n", fd);
    }
    uid=getuid();
    if (uid!=ROOT_UID) {
      printf("Error: not root\n");
      return -1;
    }
    if (access(KO_NAME, F_OK)==-1) {
      printf("Error: File \"%s\" doesn't exist\n", argv[2]);
      return -1;
    }
    rc=syscall(__NR_finit_module, fd, "", 0);
      close(fd);
      if (rc!=0) {
          perror("Error");
          printf("rc=%d\n", rc);
          printf("Error number: %d\n", errno);
      }

and this is the result when run:

fd: 3

rc=-1

Error number: 1

Why am I getting Error number 1?

operation not permitted

Upvotes: 1

Views: 4681

Answers (2)

Appyx
Appyx

Reputation: 1185

Kernel modules can only be accessed by the root user by default. So after insmod you have to open the device file with the root user.

So you have to use sudo for opening the file.

Upvotes: 0

Tron
Tron

Reputation: 21

I had "Operation not permitted" errors installing Linux kernels too. I am running Sophos Anti-Virus, which has a known bug. "30s delay of file create and "Operation not permitted" errors with fanotify and cifs – This is a kernel issue and Sophos is working with the Linux community to fix this issue"

To get around this problem I disable sophos-av before and enable it after each Linux kernel install. I have only experienced this problem during Linux kernel install and not during common updates.

sudo /opt/sophos-av/bin/savdctl disable

Run Update Manager and install Linux kernel.

sudo /opt/sophos-av/bin/savdctl enable

Upvotes: 2

Related Questions