large copy_to_user fills only one page?
Hi,
I'm working with linux-2.4.18, and writing some
trivial code to get from kernel a grabbed image working this way:
#define IMSIZE 350000
user mode runs:
u_p=malloc(IMSIZE);ioctl(grabberfd,DOGRAB,u_p);
write *u_p to diskfree(u_p);
kernelmode runs:
case DOGRAB:
char *u_p,*k_p;
copy_from_user(u_p,arg,sizeof(char *));
k_p=vmalloc(IMSIZE);
kernelgrabs(k_p);
copy_to_user(u_p,k_p,IMSIZE);
vfree(k_p);
break;What I get actually is only 4K filled in userland, but copy_to_user returns IMSIZE!
If I memset the memory area *u_p to any value, the grab happens properly.
I guess memset'ing faults the good pages in, I'm quite surprised this does not happen smoothly by itself ;-(
Any clue?
Sincerely yours,
Signature · 4 lines
Emmanuel Michon Chef de projet REALmagic France SAS Mobile: 0614372733 GPGkeyID: D2997E42
Quoted 3 lines · Emmanuel Michon
case DOGRAB:
char *u_p,*k_p; copy_from_user(u_p,arg,sizeof(char *));
^^^
You copy into random stack garbage here. After that it goes downwards.
-Andi
Hi Emmanuel,
Quoted 4 lines · Emmanuel Michon
I'm working with linux-2.4.18, and writing some
trivial code to get from kernel a grabbed image working this way:
What I get actually is only 4K filled in userland, butcopy_to_userreturns IMSIZE!
copy_to_user() returns the number of bytes NOT copied. same for copy_from_user().
This is a common mistake and your code using this functions should look like this:
if (copy_from_user(to,uptr,size)) {
return -EFAULT;
}
/* Do some processing */
if (copy_to_user(uptr,from,size)) {
return -EFAULT;
}
PS: CC'ed linux-kernel, that you will not get 1000 answers ;-)
Regards
Ingo Oeser
Signature · 1 line
Science is what we can tell a computer. Art is everything else. --- D.E.Knuth