Jeegar Patel
Jeegar Patel

Reputation: 27210

How to allocate user space buffer in kernel driver?

In some mess up i need to call one kernel function who is not suppose to call from kernel space because in argument it takes buffer from user space allocated.

const char __user *buf

But i need to call that so how can i allocate user space buffer and pass it with that function arguments.

if possible then i need to do it without any user space interaction. Is it really possible?

My goal is to call kernel routine from kernel driver who takes arguments const char __user *buf

Upvotes: 4

Views: 2630

Answers (2)

Anthony
Anthony

Reputation: 12397

There might be another way, depending on what system call you're actually trying to invoke.

Here is an article which explains a little bit about system call mechanics. There is a section which explains how to invoke system calls from kernel space, using kernel memory and avoid the validation.

  mm_segment_t fs;

  fs = get_fs();     /* save previous value */
  set_fs (get_ds()); /* use kernel limit */

  /* system calls can be invoked */

  set_fs(fs); /* restore before returning to user space */

Upvotes: 6

Arlie Stephens
Arlie Stephens

Reputation: 1176

AFAIK, the usual way to do this is to break the kernel routine in two - an outer routine that deals with system call mechanics, handles the copyin()/coyout() etc., and then calls the inner routine, which does the actual work.

Of course that won't work if you need to have your code self-contained within a module, and don't control the rest of the kernel it's used with.

And in answer to your specific question - I don't know if there's any such API, but I rather doubt it.

Upvotes: 5

Related Questions