Getting netlink socket creation returns NULL in the kernel

Irfan Ullah (울라 이르판) irfan at dke.khu.ac.kr
Thu Oct 17 02:23:56 EDT 2019


My actual goal is to develop kernel space and user space programs to
establish communication in which kernel should initiate the communication.
The kernel will send information (e.g., guest physical address from
handle_ept_violation() in vmx.c, finding the corresponding page of that
address, owner process (or if possible the application, i.e., VLC, open
office) of the page, process/application releasing the page) at run time to
the user space application.
I have written code  consists of three file i.e., netlink_kernel_module.c,
netlink_kernel_space.h, netlink_user_module.c.  "netlink_kernel_module.c"
contains just kernel loading/ unloading module functions i.e., __init
hello_init(), and _exit hello_exit().  "netlink_kernel_space.h" contains
all the rest of the kernel space code for sending/ receiving data while
 "netlink_user_module.c" contains the user space application code for
sending/receiving data.

*During development and testing* I use  "netlink_kernel_module.c" to load
and unload kernel module, in which the "__init hello_init()" just call the
"create_socket(int data)" defined in  "netlink_kernel_space.h" with the
data which I want to pass to the user space program. And my code works
perfectly in this way.

*But, To get the required data from the kernel in real time*, I include  "
netlink_kernel_space.h " in kernel file i.e., vmx.c and call the
"create_socket(int data)"  from the handle_ept_voilation() defined in vmx.c
<https://elixir.bootlin.com/linux/latest/source/arch/x86/kvm/vmx/vmx.c#L5079>
after
line#5098. I compile, and install the kernel, and reboot the system (and
thus I don't need  "netlink_kernel_module.c"  because I don't load/unload
the kernel module but include  "netlink_kernel_space.h"  in the vmx.c by
using #include "netlink_kernel_space.h").  But, I am getting “NULL” while
creating socket (nl_sk = NULL in nl_sk = netlink_kernel_create(&init_net,
NETLINK_USER, &cfg);). Here code also shows weird behaviour. If I put 1-3
seconds sleep just before the socket creating statement, then it works just
during booting of the virtual machine, after successful boot I get the same
socket NULL error. Please find the code in the attachment..
Thank you very much.

On Wed, Oct 16, 2019 at 11:29 PM Valdis Klētnieks <valdis.kletnieks at vt.edu>
wrote:

> On Wed, 16 Oct 2019 13:54:08 +0900, Irfan Ullah said:
>
> > developed kernel space, and user space programs.  Kernel and user space
> > programs working perfectly when I load and run these modules from the
> > terminal using “sudo insmod kernelmodule.ko”, and “./userspaceApp”
> > respectively.  But, when I try to use kernel program  (directly as a
> header
> > file #include "kernelmodule.h") with the kernel original file that is
> > “vmx.c” then it returns “NULL” while creating socket (nl_sk = NULL in
> nl_sk
>
> You're going to have to explain in more detail what you're doing, and
> possibly
> share your code.  "when I try to use kernel program directly" doesn't make
> sense....
>
>

-- 
*Best Regards,*


*Mr. Irfan Ullah*
PhD Candidate
Data and Knowledge Engineering(DKE) Lab
Department of Computer Science and Engineering
Kyung Hee University, South Korea.
 +82-010-591-51651 <+82%2010-3877-8867>
  sahibzada.iu at gmail.com
 sahibzada_irfanullah
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20191017/d3dfbb1c/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Kernel_User_comm.zip
Type: application/zip
Size: 7514 bytes
Desc: not available
URL: <http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20191017/d3dfbb1c/attachment-0001.zip>


More information about the Kernelnewbies mailing list