Date: Sun, 20 Jan 2013 15:01:59 -0800 From: Yuri <yuri@rawbw.com> To: hackers@freebsd.org Subject: How to validate the variable size memory block in ioctl handler? Message-ID: <50FC7767.4050207@rawbw.com>
next in thread | raw e-mail | index | archive | help
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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?50FC7767.4050207>
