LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Syscall stat64() returning EFAULT (bad address)... (https://www.linuxquestions.org/questions/programming-9/syscall-stat64-returning-efault-bad-address-900050/)

alclub 08-29-2011 08:33 AM

Syscall stat64() returning EFAULT (bad address)...
 
Hi, I'm trying to call stat64() (from a kernel context) but it keeps returning errno EFAULT (bad address). I successfully vmalloc'ed some memory, but it doesn't accept it.

I'm not too experienced with kernel programming yet but I tried looking at the source and it seems when stat64() tries to use copy_to_user() and it fails, stat64 will return efault.

I'm guessing it want's user space memory. But I tried kmalloc(sizeof(my_statbuf),GFP_USER) as well and that fails. I also tried fstat64 which fails too.

Here's an example of what I'm trying to do:

Code:

...

extern struct stat64 __user *my_statbuf;

my_statbuf = vmalloc(sizeof(*my_statbuf)); /* I also tried kmalloc(sizeof(my_statbuf),GFP_USER) */
if(my_statbuf == NULL){printk(KERN_INFO "malloc failed"); return 1;}

unsigned long fd = open(filename, flags, mode); //Opening my file which works.

printk(KERN_INFO "fstat returned: %ld",real_fstat64(fd,my_statbuf)); // prints -14 (efault)

...

/* replacing fstat64 with stat64 (and the file descriptor with a filename) has the exact same result (efault). */


Thanks guys


All times are GMT -5. The time now is 04:09 PM.