From owner-freebsd-smp Thu Apr 19 18:26: 7 2001 Delivered-To: freebsd-smp@freebsd.org Received: from pike.osd.bsdi.com (pike.osd.bsdi.com [204.216.28.222]) by hub.freebsd.org (Postfix) with ESMTP id 0989E37B423; Thu, 19 Apr 2001 18:26:02 -0700 (PDT) (envelope-from jhb@foo.osd.bsdi.com) Received: from foo.osd.bsdi.com (root@foo.osd.bsdi.com [204.216.28.137]) by pike.osd.bsdi.com (8.11.1/8.9.3) with ESMTP id f3K1PuK19503; Thu, 19 Apr 2001 18:25:56 -0700 (PDT) (envelope-from jhb@foo.osd.bsdi.com) Received: (from jhb@localhost) by foo.osd.bsdi.com (8.11.1/8.11.1) id f3K1O2331600; Thu, 19 Apr 2001 18:24:02 -0700 (PDT) (envelope-from jhb) Message-ID: X-Mailer: XFMail 1.4.0 on FreeBSD X-Priority: 3 (Normal) Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 8bit MIME-Version: 1.0 Date: Thu, 19 Apr 2001 18:24:01 -0700 (PDT) Organization: BSD, Inc. From: John Baldwin To: hackers@FreeBSD.org Subject: Patch to change pfind() to lock the process it returns Cc: des@FreeBSD.org, yokota@FreeBSD.org Sender: owner-freebsd-smp@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org The pfind() and zpfind() functions obtain a shared lock while accessing the PID hash table and zombie process lists so that they will have a consistent list to work with while searching for a process. However, since these functions release the lock before returning, there is a race condition whereby a process may be modified in between the time that pfind() locates it and releases its lock and the time that the process that called pfind() gets a pointer to said process. One solution is to require all callers of pfind() and zpfind() to acquire the shared allproc lock before calling the function and then to release it after taking appropriate measures with the returned process. However, this is somewhat painful for users of pfind(). Thus, I've chosen instead to change pfind() and zpfind() use the PROC_LOCK() macro to lock the process that they find before they release the allproc lock and return. Note that if pfind() and zpfind() return NULL, there is no process to lock. This patch changes pfind() and zpfind() to follow this behavior and attempts to adjust all callers of pfind() and zpfind() appropriately. I've attempted to cc appropriate maintainers as well as the list as this change does touch a few areas. Some cases of pfind() in the system can probably be eliminated or changed to use a simpler algorithm, but I'd prefer that that discussion happen later. For now, please review the patch below for correctness, etc.: http://www.FreeBSD.org/~jhb/patches/pfind.patch Thanks. -- John Baldwin -- http://www.FreeBSD.org/~jhb/ PGP Key: http://www.Baldwin.cx/~john/pgpkey.asc "Power Users Use the Power to Serve!" - http://www.FreeBSD.org/ To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-smp" in the body of the message