This is not so, because copy_from_user()
copies from the current user process (which should be obvious, since there is no way to tell which user process to copy from).
In syscall called by your user space process, this is normal because the current process is your user space process. However, in the kernel thread, the current process can be any other process in the system - therefore you copy random processes from the memory, therefore you get garbage.
If you want to exchange memory between the kernel and the process in user space, the correct way to do this is to allocate the kernel and then allow the user space process to map it to the address space using mmap()
. Different pointers will be used in the kernel thread and user space process to refer to the memory area - the kernel thread will use the pointer to the memory allocated in the kernel address space, and the user space process will use the pointer to the memory area returned by mmap()
.
source share