copy_from_user() for userspace data containing pointers

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

 



Hi,

I have two structures that i share between kernel/userspace as follows:

struct foo {
  int num;
  struct bar *bartable;
};

struct bar {
  u32 ipaddr;
  unsigned char mac_addr[6];
};

Now from the userspace, I calloc() (num * sizeof(struct bar)) bytes to
bartable, initialize it and call an ioctl. So essentially I have 'num'
records of format 'struct bar' pointed to by 'bartable'. The ioctl
handling routine in the kernel is as follows:
-- 
struct foo fookern;
struct foo *userinfo = (struct foo *)ifr->ifr_data; 
struct bar *entry;

copy_from_user(&fookern, userinfo, sizeof(struct foo));

for(i=0, entry = fookern.bartable; i < fookern.num; i++, entry++) {
   print(entry->ipaddr, entry->mac_addr)  // pseudo code
}
--

The complete table calloc'ed to 'bartable' and initialized in the
userspace is not reflected in the kernel. Printing entry->ipaddr and
entry->mac_addr 'fookern.num' times prints all entry->ipaddr entries but
entry->mac_addr entries are zero.

So, how can be correctly copy pointer variables from userspace to
kernelspace? Or should there be a change in the sizeof parameter in the
copy_from_user() call?

TIA.
Regards,
Amit

-- 
I'm an angel!!! Honest!
The horns are just there to hold the halo up straight.
^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^
                  Amit Kucheria
          EECS Grad. Research Assistant
         University of Kansas @ Lawrence
   (R)+1-(785)-830 8521 ||| (O)+1-(785)-864 7774
____________________________________________________

--
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