How to validate the variable size memory block in ioctl handler?
Yuri
yuri at rawbw.com
Sun Jan 20 23:02:05 UTC 2013
I am implementing an ioctl that reads/writes variable size structure.
Allocated size is supplied by the caller in the structure itself.
struct my_struct {
int len; // allocated size
other_struct s[1];
};
ioctl request id is defined as _IOWR('X', <number>, my_struct)
How to validate from the ioctl function handler (for some device) that
the whole (variable size) block of bytes is RW accessible in the process
memory space?
Should I call copyout/copyin for this, or there is some shorter way?
EFAULT should be returned in case of validation failure.
As I understand, macros like _IOR, _IOWR do validation based on the size
of structure supplied to them. So that the handler procedures don't have
to do that.
I was expecting to find among them some macro that would work for such
variable size structure, but it isn't there. (Not sure if this is
possible language-wise).
Yuri
More information about the freebsd-hackers
mailing list