What are the implications of the linux __user macro?

前端 未结 3 2033
[愿得一人]
[愿得一人] 2020-11-29 20:29

I was hoping someone could explain the nuances of the __user macro used in the linux kernel source.

First of all, the macro:

# define __user                  


        
3条回答
  •  迷失自我
    2020-11-29 20:44

    I think __user marks user space pointers and tells the developer/system not to trust it. If user gives you "invalid" pointer, then kernel tries to reference it (note that kernel can reference everywhere) and it can corrupt it's own space.

    For example in "read"(in you usbdevice_fs.h) should provide you a (__user) buffer to write the result to. So you have to use copy_to_user, but not memcopy, strcpy or anything like this.

    Note: This is not formal definition/description, but the only part I'm aware of.

提交回复
热议问题