1

Is it possible to access a kernel module if a user is not sudoer?

I am trying to access a KVM, which is kernel module, as non-sudoer but I am getting an error:

Could not access KVM kernel module: Permission denied.

Is there any way to make this module accessible to all users (non-sudoers as well) ?

user298350
  • 11
  • 1
  • 2
  • 1
    What are you using to access the kernel module? You could make it so when you run that command with sudo, it does not ask for the password for that command - see here. – Wilf Jun 27 '14 at 13:29

2 Answers2

2

A general recipe to set permissions on kernel modules access is to add a file to /etc/udev/rules.d. For example, you can create a file /etc/udev/rules.d/99-kvm.rules with the following text:

KERNEL=="kvm", GROUP="kvm-users"
facetus
  • 121
1

Ubuntu 18.04 upgrade

For /dev/kvm specifically, add the user to the kvm group with:

sudo usermod -a -G kvm $USER

and reboot the computer and the problem is solved.

I was getting that error message when passing the -enable-kvm to qemu-system-x86_64.

How I found it out: if we do:

ls -al /dev/kvm

it gives:

crw-rw---- 1 root kvm 10, 232 May 12 07:53 /dev/kvm

and:

id -a

gives:

uid=1000(ciro) gid=1000(ciro) groups=1000(ciro),4(adm),20(dialout),24(cdrom),27(sudo),30(dip),46(plugdev),118(lpadmin),128(sambashare)

did not contain the kvm group.

Maybe access was previously granted through udev rules, but then they moved to the group mechanism? https://bugzilla.redhat.com/show_bug.cgi?id=1479558#c3

yes we dropped the kvm udev rules in the rawhide package, since rawhide systemd now provides them. However it looks like you are using the virt-preview repo on f26, so now there isn't anything setting /dev/kvm permissions to 666 and group=kvm

It does seem possible to add users to the kvm group during upgrade: How to run a script only during first install of a package and during upgrades? but maybe it was not done because of security concerns?