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 <[EMAIL PROTECTED]> -- 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 [EMAIL PROTECTED]
with "unsubscribe freebsd-hackers" in the body of the message

Reply via email to