Below is a snippet of my simple driver code.
int vprobe_ioctl( struct file *filep, unsigned int cmd, void *UserInp)
{
case IOCTL_GET_MAX_PORTS:
*(int*)UserInp = TotalPorts;
#if ENABLED_DEBUG
printk("Available port :%u \n ", TotalPorts);
#endif
break;
}
I did not know about the function copy_to_userthat should be used when writing to user space in memory. The code directly accesses the user address. But still, I am not getting any kernel failure on my development system (x86_64 architecture). It works as expected.
But sometimes I could see a kernel crash when I paste the .ko file into some other x86_64 machines. So, I replaced direct access with copy_to_userand it works.
Can someone explain
i) How does direct access to a user address work?
ii) , . , - ?
. , , . - , . - .
.