On Mon, Dec 17, 2012 at 10:32 AM, Yann Droneaud <span dir="ltr"><<a href="mailto:ydroneaud@opteya.com" target="_blank">ydroneaud@opteya.com</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Le lundi 17 décembre 2012 à 10:11 -0500, Terry Hsu a écrit :<br>
<div>> Hello everyone,<br>
><br>
><br>
> I am looking for some mechanism for userspace tasks to pass certain<br>
> functions to kernel and let the kernel execute these functions on<br>
> behalf of userspace tasks. I know that sysfs can be used with kobject<br>
> embedded into internal kernel structure to access kernel variables.<br>
> But is there anyway for userspace tasks to pass a function to kernel<br>
> to execute through sysfs?<br>
><br>
<br>
</div>From a security point of view: what a crazy idea !<br>
<br>
And difficult to implement as you described it:<br>
A pointer to userspace is of no interest for the kernel.<br>
A pointer to userspace memory is tied the process that "generate" it.<br>
So without any reference to the process, a pointer has no meaning for<br>
the kernel.<br>
Then, this pointer must point to something, eg. what's going to happen<br>
when your process exit while the kernel is going to execute code on its<br>
behalf ...<br>
<div><br></div></blockquote><div><br></div><div>Before a userspace tasks can delegate the job to kernel, it has to have the privilege to do so. Therefore if a task asks the kernel to run something that is not permitted, the kernel will block the request and return error value to the userspace caller.</div>
<div><br></div><div>Thanks for pointing out the difficulties here when passing the function pointers to kernel. I am relatively new to kernel hacking, so after reading your comments, I went back and read about high memory in Linux kernel. I learned that the kernel can use kmap/kunmap to establish/destory persistant kernel mappings. Will it be feasible if the kernel use kmap to map those userspace memory regions? In this way the kernel can access the function pointer and execute the function on behalf of the userspace task. </div>
<div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div>
><br>
> PS: adding syscall in the kernel can certainly satisfy my needs but it<br>
> is less favorable because the new kernel service I want to add is not<br>
> that general to be added as a new syscall.<br>
><br>
<br>
</div>You might want to describe the problem you're trying to fix or at least<br>
a use case.<br></blockquote><div><br></div><div>For example, when a userspace task creates a thread to execute a function, the kernel will copy the task_struct and mm_struct from its parent process. I am trying assign different memory access privileges for different tasks within the same process so that they do not always have the same privilege to access all the pages of their parent process. To do so, I intend to let the kernel maintain separate page tables for different tasks, and bookkeep the access privilege.</div>
<div><br></div><div>Thanks! </div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Regards.<br>
<span><font color="#888888"><br>
--<br>
Yann Droneaud<br>
OPTEYA<br>
<br>
<br>
<br>
</font></span></blockquote></div><br>