I'm learning how to create a kernel module in userspace. Does anyone know of any easy kernel modules that can be controlled from userspace?

I've went through /lib/modules but most of the drivers require either root access and go into esoteric functionalities, I don't really want to go through all the source code. (e.g. eepoe).

Does anyone know of any userspace kernel device driver?

enter image description here

closed as off-topic by Basile Starynkevitch, Rui F Ribeiro, Anthon, Stephen Rauch, GAD3R Aug 13 '17 at 15:03

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Requests for learning materials (tutorials, how-tos etc.) are off topic. The only exception is questions about where to find official documentation (e.g. POSIX specifications). See the Help Center and our Community Meta for more information." – Basile Starynkevitch, Rui F Ribeiro, Anthon, Stephen Rauch, GAD3R
If this question can be reworded to fit the rules in the help center, please edit the question.


The description "userspace kernel module" is a contradiction in terms: Either something runs in userspace, or it runs in the kernel, but it can't run in either, and you can't run kernel modules in userspace.

That said, it's possible to write device drivers in userspace, by making use of quite general kernel APIs (which run in kernel space, no matter if they are modules or not), and implementing the actual device driver functionality in userspace. Device drivers using libusb, spidev or i2cdev are such examples: they use a library to access well-known kernel APIs, or access the APIs directly, but the device driver logic runs in userspace.

Another, similar example is fuse: using fixed kernel APIs, you can implement your own filesystem in userspace.

So if you want examples, google for device drivers using those APIs. But they will still be example of "user space device drivers", not "userspace kernel device drivers", so I'm not sure if this is what you want.

If you want to write something that runs in kernel space, you need to learn how to write a kernel module.

  • would "kernel modules that can be load/unloaded at userspace" be an accurate analogy? – laycat Aug 13 '17 at 11:06
  • That makes no sense, either: All kernel modules can be loaded/unloaded with commands from userspace (insmod, rmmod, modprobe). No kernel modules can be loaded "into" userspace, if that's what you mean by "at". A kernel module runs in kernel space, always. – dirkt Aug 13 '17 at 13:13
  • the former is correct. insmod and rmmod however requires sudo access. I am looking to create a hello driver that interacts with system calls without having to give users sudo access. – laycat Aug 13 '17 at 14:29
  • I'm sorry, but I get the impression your understanding of the Linux architecture is a bit confused. "System calls" are something that userspace programs do, and processes running as any user can do that. Root just has rights to execute a few additional system calls. If you are looking for ways to run an application program that needs root rights and should be started as a non-root user, look into the setuid bit. That has nothing to do with kernel modules, or kernel space as opposed to userspace. – dirkt Aug 13 '17 at 17:12
  • no problem, thank you for your feedback. I'm genuinely new at this, I should have taken the more conventional route of creating a new kernel. If its ok, please add me as a friend on gtalk or facebook, I would be happy to have a friend to discuss this with. – laycat Aug 14 '17 at 0:51

There's an answer about creating files in sysfs on stackoverflow. They are simple to handle and should be accessible w/o root permissions by default.

Not the answer you're looking for? Browse other questions tagged or ask your own question.