filemon_ioctl: Lock the associated filemon handle before writing to it.

Reported by:	mjg
MFC after:	2 weeks
Sponsored by:	EMC / Isilon Storage Division
This commit is contained in:
Bryan Drewery 2016-01-27 21:14:09 +00:00
parent e8c87a09dc
commit 64c368a488
2 changed files with 3 additions and 7 deletions

View File

@ -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);
}

View File

@ -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