Michael
Michael

Reputation: 6172

Does copy_from_user modify the user pointer?

Does the copy_from_user function, declared in uaccess.h, modify the (void __user *)from pointer? The pointer isn't declared as const in the function declaration, only the contents it points to.

The reason I ask is that I want to use copy_from_user twice, with the second copy_from_user copying from the place where the first one finished.

I was planning on doing something like this, is it guaranteed to work?

//buf is a user pointer that is already defined
copy_from_user(my_first_alloced_region, buf, some_size);
//do stuff
copy_from_user(my_second_alloced_region, buf + some_size, some_other_size);

Thanks in advance.

Upvotes: 2

Views: 420

Answers (1)

Jason
Jason

Reputation: 32538

The callee function can't modify the pointer itself since you're simply passing the pointer-value as an argument to the function. If the argument is declared as a pointer to a const type, then the callee can't modify what is being pointed to either (at least not without a cast that would cast away the const-ness of the pointer). The only way to modify the pointer value in the caller itself would be to pass the callee a pointer-to-pointer type.

Upvotes: 3

Related Questions