From owner-freebsd-hackers@FreeBSD.ORG Fri Dec 16 16:13:51 2005 Return-Path: X-Original-To: freebsd-hackers@freebsd.org Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 48B5F16A41F; Fri, 16 Dec 2005 16:13:51 +0000 (GMT) (envelope-from jhb@freebsd.org) Received: from speedfactory.net (mail6.speedfactory.net [66.23.216.219]) by mx1.FreeBSD.org (Postfix) with ESMTP id 50B5043D45; Fri, 16 Dec 2005 16:13:50 +0000 (GMT) (envelope-from jhb@freebsd.org) Received: from server.baldwin.cx (unverified [66.23.211.162]) by speedfactory.net (SurgeMail 3.5b3) with ESMTP id 3945960 for multiple; Fri, 16 Dec 2005 11:11:51 -0500 Received: from localhost (john@localhost [127.0.0.1]) by server.baldwin.cx (8.13.1/8.13.1) with ESMTP id jBGGDibV080636; Fri, 16 Dec 2005 11:13:44 -0500 (EST) (envelope-from jhb@freebsd.org) From: John Baldwin To: freebsd-hackers@freebsd.org Date: Fri, 16 Dec 2005 11:14:12 -0500 User-Agent: KMail/1.8.2 References: <20051215223745.GA37768@FreeBSD.czest.pl> <20051216091057.GQ77268@cirb503493.alcatel.com.au> In-Reply-To: <20051216091057.GQ77268@cirb503493.alcatel.com.au> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200512161114.14398.jhb@freebsd.org> X-Virus-Scanned: ClamAV 0.87.1/1210/Thu Dec 15 10:23:22 2005 on server.baldwin.cx X-Virus-Status: Clean X-Spam-Status: No, score=-2.8 required=4.2 tests=ALL_TRUSTED autolearn=failed version=3.0.2 X-Spam-Checker-Version: SpamAssassin 3.0.2 (2004-11-16) on server.baldwin.cx X-Server: High Performance Mail Server - http://surgemail.com r=1653887525 Cc: Peter Jeremy , "Wojciech A. Koszek" , phk@freebsd.org Subject: Re: [CALL FOR TESTERS] New system call: abort2() 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, 16 Dec 2005 16:13:51 -0000 On Friday 16 December 2005 04:10 am, Peter Jeremy wrote: > On Thu, 2005-Dec-15 22:37:45 +0000, Wojciech A. Koszek wrote: > > abort2(const char *why, int nargs, void **args); > > > >"why" is reason of program abort, "nargs" is number of arguments > >passed in "args". Both "why" and "args" (with "%p" format) will be > >printed via log(9). Sample output: > >[..] > >pid <3004> abort2: ABORT2 > >pid <3019> abort2: invalid argument > >[..] > > I don't believe the following code is correct. uap->args is a > userspace pointer so uap->args[i] is dereferencing a userspace > argument in kernelspace. > + arg = uargs[i] = (void *) fuword(uap->args[i]); > I think it should be fuword(uap->args + i); > > I don't see the point of the following test. "arg" is printed using > %p and never de-referenced so there's no reason it can't be NULL. I > would see that a legitimate use of abort2() is when the application > detects that a pointer is unexpectedly NULL. Aborting on -1 is less > clear - if fuword() fails, it will return -1 but, equally, a faulty > user application may have left -1 in a pointer. (Note that mmap(2) > returns -1 on error so it's not inconceivable that a pointer could > contain -1). > > + /* Prevent from faults in user-space */ > + if (arg == NULL || arg == (void *)-1) { > + error = EINVAL; > + break; > + } > > Taking the above into account, I believe the code should be: > + if (uap->args == NULL) > + break; > + error = copyin(uap->args, uargs, uap->nargs * sizeof (void > *)); + if (error != 0) > + break; Agreed. Also, copyinstr() can provide a better interface for copying the why string in. Also, the PROC LOCK isn't needed for reading the static p_pid and p_comm fields of struct proc. Also, I second the other comments of do { } while(0) vs goto. Many existing syscalls use 'goto out;' for error handling, and I think that is one of the very few cases when goto is useful and not harmful. -- John Baldwin <>< http://www.FreeBSD.org/~jhb/ "Power Users Use the Power to Serve" = http://www.FreeBSD.org