Date: Thu, 19 Apr 2001 18:24:01 -0700 (PDT) From: John Baldwin <jhb@FreeBSD.org> To: hackers@FreeBSD.org Cc: des@FreeBSD.org, yokota@FreeBSD.org Subject: Patch to change pfind() to lock the process it returns Message-ID: <XFMail.010419182401.jhb@FreeBSD.org>
next in thread | raw e-mail | index | archive | help
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 <jhb@FreeBSD.org> -- 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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?XFMail.010419182401.jhb>