Re: copy_to/from_use query?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



  Hello.

Let me hitchhike on this thread.
I was using memmove().

struct file_operations foo_operations = {
    write:          foo_write,
    read:           foo_read
};

ssize_t foo_write(struct file *file, const char *buf, size_t count, loff_t *ppos) {
    if (!access_ok(VERIFY_READ, buffer, buffer_len)) return -EFAULT;
    memmove( ... , buffer, count); // May cause a page fault and oops.
}

ssize_t foo_read(struct file *file, char *buf, size_t count, loff_t *ppos) {
    if (!access_ok(VERIFY_WRITE, buffer, buffer_len)) return -EFAULT;
    memmove(buffer, ... , count); // May cause a page fault and oops.
}

  But as I read this thread, I began to think that I have to use copy_to_user() and copy_from_user().

ssize_t foo_write(struct file *file, const char *buf, size_t count, loff_t *ppos) {
    if (!access_ok(VERIFY_READ, buffer, buffer_len)) return -EFAULT;
    copy_from_user( ... , buffer, count); // Is safe, but may sleep.
}

ssize_t foo_read(struct file *file, char *buf, size_t count, loff_t *ppos) {
    if (!access_ok(VERIFY_WRITE, buffer, buffer_len)) return -EFAULT;
    copy_to_user(buffer, ... , count); // Is safe, but may sleep.
}

  Am I right?

  Regards...

---
   Tetsuo Handa

--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux