From owner-freebsd-hackers@FreeBSD.ORG Fri Apr 23 00:45:39 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 E7A321065670 for ; Fri, 23 Apr 2010 00:45:39 +0000 (UTC) (envelope-from yanefbsd@gmail.com) Received: from mail-qy0-f181.google.com (mail-qy0-f181.google.com [209.85.221.181]) by mx1.freebsd.org (Postfix) with ESMTP id 9FA748FC08 for ; Fri, 23 Apr 2010 00:45:39 +0000 (UTC) Received: by qyk11 with SMTP id 11so10656425qyk.13 for ; Thu, 22 Apr 2010 17:45:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:received:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=Of0ECCvjwcv5AZY/Hg7WLDbU0iWj5SF8B5Pbg76aogA=; b=m/X7ANmNxAX/7IIAf/FYvWvNnrsVXmRYiLBziYBBqrHmA5Y9pSbAUgCr5ImP1cub1Z yfdbclvdvnaED9i4mFo8p4qrGSXDuE7px7f1a+p+KGlNqnT/r211y6/1nC+zAj/mDHRr /2H1F7vFT9S1Yufu+dng04CnUM0lBVVfIHc9s= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; b=D3YcmYCUDRTZCSM4ZCcVUjScM9f+WQ1utM5CLNLKWN/DLwCd/Lf+4dB2LBMeiDF/MS xah7hMWUOAL2y8VwnlYU4ZVkqT+UMYZU0/n7V6ElXkaKzL9f/5+MhzRLUl520xu7NK5r I5arsBSmhqhn7rHge6ePy83ZxzHiGggTIX8KI= MIME-Version: 1.0 Received: by 10.229.233.11 with HTTP; Thu, 22 Apr 2010 17:45:38 -0700 (PDT) In-Reply-To: <06D5F9F6F655AD4C92E28B662F7F853E039E33A7@seaxch09.desktop.isilon.com> References: <06D5F9F6F655AD4C92E28B662F7F853E039E33A7@seaxch09.desktop.isilon.com> Date: Thu, 22 Apr 2010 17:45:38 -0700 Received: by 10.229.91.11 with SMTP id k11mr30978qcm.50.1271983538876; Thu, 22 Apr 2010 17:45:38 -0700 (PDT) Message-ID: From: Garrett Cooper To: Matthew Fleming Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Cc: FreeBSD-Hackers Subject: Re: Error checking in ioctl(2)? X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list 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:45:40 -0000 On Thu, Apr 22, 2010 at 4:36 PM, Matthew Fleming wrote: >> Hi hackers, >> =A0 =A0 I realize that this isn't 100% userland code, so the checks shou= ld >> 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: >> >> =A0 =A0 =A0 =A0 if (size > 0) { >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (com & IOC_VOID) { >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 /* Integer argument. */ >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 arg =3D (intptr_t)uap->d= ata; >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 data =3D (void *)&arg; >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 size =3D 0; >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 } else >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 data =3D malloc((u_long)= size, M_IOCTLOPS, >> M_WAITOK); /* XXX: can fail -- do we care? */ > > malloc(9) with M_WAITOK cannot return NULL. =A0So 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. =A0They 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! -Garrett