I am attempting to copy a custom struct from kernel space to user space. inside user space errno returns 'bad address'. What is the usual cause of a bad address error?
if(copy_to_user(info, &kernel_info, sizeof(struct prinfo)))
I am attempting to copy a custom struct from kernel space to user space. inside user space errno returns 'bad address'. What is the usual cause of a bad address error?
if(copy_to_user(info, &kernel_info, sizeof(struct prinfo)))
Bad Address error means that the address location that you have given is invalid. With the case you have above I would guess it is because you are passing in a copy of info
instead of a pointer to info
's memory location.
Looking at the docs, copy_to_user
is defined as
copy_to_user(void __user * to, const void * from, unsigned long n);
So unless your info
parameter is a pointer I would update your code to be:
if(copy_to_user(&info, &kernel_info, sizeof(struct prinfo)) ) {
//some stuff here i guess
}
Assuming that info is a pointer type and that info is pointing to a valid location it is still possible that info is pointing to an address that is not in user space which is required by the function.