0

Does anyone know how to send data from a kernel module to a userspace app, via signals? Actually, I have a kernel module that uses the function send_sig_info() to notify a userspace app (registered through ioctl) about some events happening in the kernel space. I would like to include some data that describe those events in the siginfo data structure (particularly, via the si_ptr field, if I'm not mistaken). Is there any sample code that does that? Besides, what about memory freeing? Normally, it should be done by the userspace app, right ?! So, how can the userspace app frees memory that was allocated by the kernel? Any hint related to this problem is most welcomed. Thank you.

P.S.: This post is focused on using signals and not other IPC techniques, such as Netlink or shared memory.

  • "I would like to include some data that describe those events in the `siginfo` data structure" - Yes, this probably should work. Fields of that structure are described in the [header](https://elixir.bootlin.com/linux/v5.19.8/source/include/uapi/asm-generic/siginfo.h#L37). All fields except the first 3 ones- `si_signo`, `si_errno`, `si_code` - are signal-specific, so you may use them as you want. "Besides, what about memory freeing?" - The content of `siginfo` structure will be **copied** to user space, so there is no worry about freeing it. – Tsyvarev Sep 13 '22 at 21:12
  • Actually, I'm looking for a way to pass a pointer on a buffer, populated by the kernel module, through the si_ptr field of the siginfo data struct. For instance, the buffer can contain a string that must be read by the userspace app. If it was the other way around, one can use copy_from_user/simple_read_from_buffer kernel functions. I think memory handling is required in this context. – Adel Belkhiri Sep 14 '22 at 00:25
  • Via signals you could pass a pointer to a buffer with the data. But for passing the non-small amount of data you need to use other mechanisms: signals cannot do that. – Tsyvarev Sep 14 '22 at 20:25

1 Answers1

0

I don't think it is possible to send data from kernel to userspace application through signals.

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Sep 27 '22 at 21:36