From 64c368a48832917430d2b38c051c99e2e83f102c Mon Sep 17 00:00:00 2001 From: Bryan Drewery Date: Wed, 27 Jan 2016 21:14:09 +0000 Subject: [PATCH] filemon_ioctl: Lock the associated filemon handle before writing to it. Reported by: mjg MFC after: 2 weeks Sponsored by: EMC / Isilon Storage Division --- sys/dev/filemon/filemon.c | 3 +++ sys/dev/filemon/filemon_wrapper.c | 7 ------- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/sys/dev/filemon/filemon.c b/sys/dev/filemon/filemon.c index e16ad08ab836..90cf586e4515 100644 --- a/sys/dev/filemon/filemon.c +++ b/sys/dev/filemon/filemon.c @@ -146,6 +146,8 @@ filemon_ioctl(struct cdev *dev, u_long cmd, caddr_t data, int flag __unused, if ((error = devfs_get_cdevpriv((void **) &filemon)) != 0) return (error); + filemon_filemon_lock(filemon); + switch (cmd) { /* Set the output file descriptor. */ case FILEMON_SET_FD: @@ -177,6 +179,7 @@ filemon_ioctl(struct cdev *dev, u_long cmd, caddr_t data, int flag __unused, break; } + filemon_filemon_unlock(filemon); return (error); } diff --git a/sys/dev/filemon/filemon_wrapper.c b/sys/dev/filemon/filemon_wrapper.c index d107a40892f6..7ba843dcf1ea 100644 --- a/sys/dev/filemon/filemon_wrapper.c +++ b/sys/dev/filemon/filemon_wrapper.c @@ -115,21 +115,14 @@ filemon_comment(struct filemon *filemon) int len; struct timeval now; - /* Load timestamp before locking. Less accurate but less contention. */ getmicrotime(&now); - /* Lock the found filemon structure. */ - filemon_filemon_lock(filemon); - len = snprintf(filemon->msgbufr, sizeof(filemon->msgbufr), "# filemon version %d\n# Target pid %d\n# Start %ju.%06ju\nV %d\n", FILEMON_VERSION, curproc->p_pid, (uintmax_t)now.tv_sec, (uintmax_t)now.tv_usec, FILEMON_VERSION); filemon_output(filemon, filemon->msgbufr, len); - - /* Unlock the found filemon structure. */ - filemon_filemon_unlock(filemon); } static int