title: Linux Kernel: copy_from_user - struct with pointers
body: <p>I've implemented some kind of character device and I need help with copy_ from_user function.</p>
  
  <p>I've a structure:</p>
  
  <pre><code>struct  my_struct{
  
  int a;
  
  int *b;
  };
  </code></pre>
  
  <p>I initialize it in user space and pass pointer to my_struct to my char device using 'write' function. In Kernel's Space character device 'write' function I cast it from a *char to this kind of structure. I alloc some memory for a struct using kmalloc and do <code>copy_from_user</code>  into it.  </p>
  
  <p>It's fine for simple 'int a', but it copies only pointer (address) of b value, not value pointed by b, so I'm now in Kernel Space and I'm working with a pointer that points to a user space memory. Is this incorrect and I shouldn't access to user space pointer directly and I have to  <code>copy_from_user</code> every single pointer in my struct and then copy back  every pointer in "read" function using  <code>copy_to_user</code> function?</p>