Error checking in ioctl(2)?
Xin LI
delphij at delphij.net
Fri Apr 23 00:51:19 UTC 2010
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On 2010/04/22 17:45, Garrett Cooper wrote:
> On Thu, Apr 22, 2010 at 4:36 PM, Matthew Fleming
> <matthew.fleming at isilon.com> wrote:
>>> Hi hackers,
>>> I realize that this isn't 100% userland code, so the checks should
>>> be minimalized, but when looking at the ioctl(2) syscall code (at
>>> least I think it is... there's another dupe hanging around in
>>> sys/dev/hptmv/ioctl.c), I had some questions related to the error
>>> handling not being done in the code:
>>>
>>> if (size > 0) {
>>> if (com & IOC_VOID) {
>>> /* Integer argument. */
>>> arg = (intptr_t)uap->data;
>>> data = (void *)&arg;
>>> size = 0;
>>> } else
>>> data = malloc((u_long)size, M_IOCTLOPS,
>>> M_WAITOK); /* XXX: can fail -- do we care? */
>>
>> malloc(9) with M_WAITOK cannot return NULL. So the rest of your XXX
>> comments are not at issue.
>>
>> Also, free(9) is documented to do the right thing when asked to
>> free(NULL).
>>
>> copyin/copyout are really just bcopy but unlike most kernel code they
>> are allowed to take a page fault. They deal with this by setting a
>> function pointer in PCB_ONFAULT, which is used in trap() to set a return
>> instruction pointer.
>
> Matt,
> Awesome. I can see I need to do a bit more reading in malloc(3) :)...
> Thanks for the info!
It's actually malloc(9)... I personally feels it pretty confusing at
the beginning when I learned about it.
Cheers,
- --
Xin LI <delphij at delphij.net> http://www.delphij.net/
FreeBSD - The Power to Serve! Live free or die
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.14 (FreeBSD)
iQEcBAEBAgAGBQJL0O76AAoJEATO+BI/yjfBOr4H/jTKZ4MSw4ukOsAGmSsRKz9Z
J2Jw/8DH7Kv1VZD8Dsvzma8/gF94YqbaBNsiz1/bKLF0zJrecpEucvglmEzbhthP
eep5SJHMK2mKnX+RgfIrGr/iQoK03kmXW74UcIYAeLhgibFZ7gqnqnnIay1pObic
+GUCHFAV7XW+mHs9sITCNg4d4DprBn2m7VtccPRtIaHfLsRHo9xjI6Zhendf/D4H
5r+ZO0ndU4snmk7BPrHpjiP+KDfyZM0gaC6IOf+t7gUfHqf0/uOrLiQavTUqBw4K
WqMLUok1orbLa1oV/wITeYbcdPbvbNCp4B+ZSU0PngERbmJYqg+DrYLZ0572Lxo=
=zYtp
-----END PGP SIGNATURE-----
More information about the freebsd-hackers
mailing list