zirias@
Developer
When porting a driver from Linux to FreeBSD, I came across this code:
where
Now, AFAIK, this won't work on all architectures? Is it ever safe to directly access userspace memory? Is there some means to check whether such an access is ok, or should you always use a buffer in kernel space and the copy(9) functions?
edit: just to be sure, I changed the driver code to consistently use
C:
/* verify if it's ok to write into the buffer */
if (access_ok(VERIFY_WRITE, kernel_val.buffer, 0x2000) == 0)
return -EFAULT;
kernel_val.buffer
is a pointer to userspace. The code then continues writing directly there. As I couldn't find an equivalent to access_ok()
in FreeBSD, I just removed the whole check for testing and it worked.Now, AFAIK, this won't work on all architectures? Is it ever safe to directly access userspace memory? Is there some means to check whether such an access is ok, or should you always use a buffer in kernel space and the copy(9) functions?
edit: just to be sure, I changed the driver code to consistently use
copyin()
/ copyout()
on all data, this works fine, but I'm still curious