From c849fda850525305140c6a073ddd2e5a109aa3fb Mon Sep 17 00:00:00 2001 From: "Simon J. Gerraty" Date: Fri, 19 Jun 2015 17:19:20 +0000 Subject: [PATCH] filemon_pid_check needs to hold proctree_lock Reviewed by: kib MFC after: few days --- sys/dev/filemon/filemon_wrapper.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/sys/dev/filemon/filemon_wrapper.c b/sys/dev/filemon/filemon_wrapper.c index f92dbe98b50e..ba819d582715 100644 --- a/sys/dev/filemon/filemon_wrapper.c +++ b/sys/dev/filemon/filemon_wrapper.c @@ -28,6 +28,8 @@ #include __FBSDID("$FreeBSD$"); +#include + #include "opt_compat.h" #if __FreeBSD_version > 800032 @@ -84,13 +86,17 @@ filemon_pid_check(struct proc *p) { struct filemon *filemon; - while (p->p_pptr) { + sx_slock(&proctree_lock); + while (p != initproc) { TAILQ_FOREACH(filemon, &filemons_inuse, link) { - if (p->p_pid == filemon->pid) + if (p->p_pid == filemon->pid) { + sx_xunlock(&proctree_lock); return (filemon); + } } - p = p->p_pptr; + p = proc_realparent(p); } + sx_xunlock(&proctree_lock); return (NULL); }