FILEMON_SET_FD: Disallow changing the fd.

MFC after:	1 week
Suggested by:	mjg
Sponsored by:	EMC / Isilon Storage Division
This commit is contained in:
Bryan Drewery 2016-03-09 19:50:35 +00:00
parent c3d1c73fa9
commit 044fd54366
2 changed files with 18 additions and 3 deletions

View File

@ -31,7 +31,7 @@
.\"
.\" $FreeBSD$
.\"
.Dd January 28, 2016
.Dd March 9, 2016
.Dt FILEMON 4
.Os
.Sh NAME
@ -125,6 +125,19 @@ function returns the value 0 if successful;
otherwise the value \-1 is returned and the global variable
.Va errno
is set to indicate the error.
.Sh ERRORS
The
.Fn ioctl
system call
with
.Dv FILEMON_SET_FD
will fail if:
.Bl -tag -width Er
.It Bq Er EEXIST
The
.Nm
handle is already associated with a file descriptor.
.El
.Sh FILES
.Bl -tag -width ".Pa /dev/filemon"
.It Pa /dev/filemon

View File

@ -163,8 +163,10 @@ filemon_ioctl(struct cdev *dev, u_long cmd, caddr_t data, int flag __unused,
switch (cmd) {
/* Set the output file descriptor. */
case FILEMON_SET_FD:
if (filemon->fp != NULL)
fdrop(filemon->fp, td);
if (filemon->fp != NULL) {
error = EEXIST;
break;
}
error = fget_write(td, *(int *)data,
cap_rights_init(&rights, CAP_PWRITE),