I'm reading LDD3. In chapter 8, I could not understand this paragraph:
An example of a function in the kernel that uses
vmallocis thecreate_modulesystem call, which usesvmallocto get space for the module being created. Code and data of the module are later copied to the allocated space usingcopy_from_user. In this way, the module appears to be loaded into contiguous memory.
Why is copy_from_user used? Aren't we in kernel space only?
Recall that kernel modules are loaded by the
insmod(ormodprobe) command, which runs in user space. These commands load the kernel module from disk into memory, then pass it to the kernel, which must usecopy_from_user()to copy that to kernel memory.