In LDD3's example, access_ok()
is placed at the beginning of ioctl
method of a kernel module to check whether a pointer passed from userspace is valid. It is correct when userspace application calls ioctl()
system call, and passes it an address of a variable. In some cases, however, ioctl()
system call is invoked with a value instead of a pointer as third argument and finally the second argument of access_ok()
in kernel module.
I've tried to pass an integer as access_ok()
's second argument and it works fine. No error was reported. But I don't very sure that is this usage correct?
For example, if I invoke ioctl()
in userspace with it's third argument to be '3'. Then, in ioctl()
method of struct file_operations
, access_ok()
will receive 3
as it's second argument. Because the access_ok()
expects a pointer, so it translates 3
to be a userspace pointer. Obversely, it's wrong...