0

I'm working on a linux project. I need to pass a linked list to the kernel from a userspace program. I have used the kernel way of implementing linked lists in userspace. I have defined a structure as follows:

struct time{ int val; struct list_head* list; };

The variable for this strucure would be:

struct time mylist;

I have given the input data and used list_add function found in linux/include/list.h to link the structures. This mylist is a part of another structure:

struct params{
int data1;
struct time* mylist;
};

Suppose I get all the data and store it in,

struct params param;

Now if I pass &param to a system call, and use copy_from_user() function there, will I be able to access the list ? I read that I cannot dereference a pointer in kernel space (which points to a data in userspace) and that I'll have to use copy_from_user function again in Linux Kernel: copy_from_user - struct with pointers. Could anyone suggest me a possible way of passing this list to the kernel space ?

Community
  • 1
  • 1
ch2301
  • 3
  • 1
  • 2
    For each node, create a new node in kernel space, copy the user-space node in via `copy_from_user()`, and update the pointer to the newly created kernel space node. Repeat. This is messy. Consider a different API for talking to the kernel. – Peter Jun 25 '14 at 12:48
  • @Peter I read that mmap() could be used to share memory between userspace and kernel space. But I'm not working on kernel modules. Will mmap() work in my case ? – ch2301 Jul 02 '14 at 04:39
  • 1
    I don't know what you mean that "you are not working on kernel modules". Module vs. main kernel doesn't matter. No, `mmap()` will not help with the linked list, because kernel-space and user-space still have different virtual addresses for the same memory, which means the "next" pointer of the list needs to be different for each. Really, a linked list is not an appropriate structure for communicating with the kernel. – Peter Jul 02 '14 at 13:27

0 Answers0