Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to communicate with a Linux kernel module from user space without littering /dev with new nodes?

What are the ways to communicate with a kernel module from user space? By communication i mean sending information and commands between the kernel module and a user space process.

I currently know of two way:

  1. open/close/read/write/ioctl on published device node.
  2. read/write on exported and hooked /proc file.

More specifically, can someone advice the best way to communicate with a kernel module that does not actually drives any hardware and therefore should not be littering /dev with stub nodes that exists solely for ioctl calls? I mostly need to check its various status variables and send it a block of data with a request type tag and see if the request succeeded.

like image 995
Inso Reiges Avatar asked May 25 '10 09:05

Inso Reiges


People also ask

How Linux kernel module can communicate to the user space?

Communicate with user spaceThe user space must open a file specified by path name using the open() API. This file will be used by both, the user application and the kernel module to interact with each other.

Can we link user space applications to kernel space directly?

User space programs cannot access system resources directly so access is handled on the program's behalf by the operating system kernel. The user space programs typically make such requests of the operating system through system calls. Kernel threads, processes, stack do not mean the same thing.

Why do you need to keep the kernel space separate from the user space?

A modern computer operating system usually segregates virtual memory into user space and kernel space. Primarily, this separation serves to provide memory protection and hardware protection from malicious or errant software behaviour.


1 Answers

Netlink sockets are designed for that kind of requirements, too...

Also see

  • man 7 netlink
  • libnl - Netlink library
  • The libnl Archives
like image 110
filofel Avatar answered Nov 15 '22 18:11

filofel