From owner-freebsd-hackers@FreeBSD.ORG Fri Apr 23 00:51:19 2010 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 942A3106566B for ; Fri, 23 Apr 2010 00:51:19 +0000 (UTC) (envelope-from delphij@delphij.net) Received: from tarsier.geekcn.org (tarsier.geekcn.org [IPv6:2001:470:a803::1]) by mx1.freebsd.org (Postfix) with ESMTP id 259938FC18 for ; Fri, 23 Apr 2010 00:51:19 +0000 (UTC) Received: from mail.geekcn.org (tarsier.geekcn.org [211.166.10.233]) by tarsier.geekcn.org (Postfix) with ESMTP id 69628A58F7C; Fri, 23 Apr 2010 08:51:17 +0800 (CST) X-Virus-Scanned: amavisd-new at geekcn.org Received: from tarsier.geekcn.org ([211.166.10.233]) by mail.geekcn.org (mail.geekcn.org [211.166.10.233]) (amavisd-new, port 10024) with LMTP id 0XWFujjwCa+G; Fri, 23 Apr 2010 08:51:11 +0800 (CST) Received: from delta.delphij.net (drawbridge.ixsystems.com [206.40.55.65]) (using TLSv1 with cipher DHE-RSA-CAMELLIA256-SHA (256/256 bits)) (No client certificate requested) by tarsier.geekcn.org (Postfix) with ESMTPSA id 35921A56243; Fri, 23 Apr 2010 08:51:09 +0800 (CST) DomainKey-Signature: a=rsa-sha1; s=default; d=delphij.net; c=nofws; q=dns; h=message-id:date:from:reply-to:organization:user-agent: mime-version:to:cc:subject:references:in-reply-to: x-enigmail-version:openpgp:content-type:content-transfer-encoding; b=XC8JQfsz6GMZbsiVkQ1rEirCGAefz+eNJXFxDw1UrrfLDkdU7Ak7+WFcJBvaCnXCj RthWxinTQVvXV7e0tkayA== Message-ID: <4BD0EEFA.90907@delphij.net> Date: Thu, 22 Apr 2010 17:51:06 -0700 From: Xin LI Organization: The Geek China Organization User-Agent: Mozilla/5.0 (X11; U; FreeBSD amd64; en-US; rv:1.9.1.9) Gecko/20100408 Thunderbird/3.0.4 ThunderBrowse/3.2.8.1 MIME-Version: 1.0 To: Garrett Cooper References: <06D5F9F6F655AD4C92E28B662F7F853E039E33A7@seaxch09.desktop.isilon.com> In-Reply-To: X-Enigmail-Version: 1.0.1 OpenPGP: id=3FCA37C1; url=http://www.delphij.net/delphij.asc Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Cc: FreeBSD-Hackers , Matthew Fleming Subject: Re: Error checking in ioctl(2)? X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: d@delphij.net List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 23 Apr 2010 00:51:19 -0000 -----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 > 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 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-----