kernel_thread() causes segfault

Shashank Khasare sskkernelnewbie at gmail.com
Mon Mar 21 02:16:57 EDT 2016


Hi,

I want to write a new syscall in which caller process would create kernel
thread which shares the process address space, file descriptor table,
parent pid etc.
The new kernel thread would be clone of current thread but it would never
execute any userspace code.

The kernel_thread() function with following arguments would be ideal to
achieve this task:
kernel_thread(some_function, some_args, CLONE_FS | CLONE_FILES |
CLONE_PARENT)

In latest kernels (v3.1x), this function causes segmentation fault in the
user process.
However same code works perfectly in older kernels (v2.6).

According to this link
<https://groups.google.com/forum/#%21searchin/linux.kernel/kernel_thread%28%29/linux.kernel/LPWuY2DMMuA/L2hv1x23YqQJ>,
and this code
<http://lxr.free-electrons.com/source/arch/x86/kernel/process_64.c?v=3.16#L177>
(call chain: kernel_thread -> do_fork -> copy_process -> copy_thread), it
looks like only the kernel thread can spawn another kernel thread. (I tried
to set PF_KTHREAD flag in current->flags before calling kernel_thread
function, but the system crashed.)

Is there any clean way of creating kernel thread that shares process
address space, file descriptor table, parent pid etc?


Thanks,
Shashank Khasare
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20160321/9a074fde/attachment.html 


More information about the Kernelnewbies mailing list