Should I pass user-space buffer pointer to read() of struct file implemented by `filp_open()`?

Peter Teoh htmldeveloper at gmail.com
Thu Dec 5 03:37:03 EST 2013


On Wed, Nov 27, 2013 at 9:57 PM, 乃宏周 <naive231 at gmail.com> wrote:

> In module code:
>
> *unsigned char buf[20];*
>
> *struct file *device;*
>
> *device = filp_open(...);*
>
> *device->f_op->read(device,buf,20,&device->f_pos);*
>
> In signature(interface) of *read()* of *struct file*, *buf* should came
> from user-space. I fed my buffer, and I get correct data from that, Is that
> correct? Shouldn't I provide a user-space buffer to that ?
>

Some convention in kernel programming:

long do_sys_open(int dfd, const char __user *filename, int flags, umode_t
mode)
{

here __user is used for declaration - explicitly saying that the pointer is
pointing to userspace data.

without it, all pointer necessarily need to point to kernel allocated
memory, and u used copy_from_user() to copy data from userspace to kernel
pointer.



> _______________________________________________
> Kernelnewbies mailing list
> Kernelnewbies at kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>
>
>

-- 
Regards,
Peter Teoh
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20131205/af450bba/attachment.html 


More information about the Kernelnewbies mailing list