Will there be direct access to user space instead of copy_to_user?

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) , . , - ​​ ?

. , , . - , . - .

.

+4
1

. , , , . . , X , , . , . , .

, . mmu ( ). x86 1:1 ( ). .

+1

Source: https://habr.com/ru/post/1652552/


All Articles