Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/filemon Clean up the error paths in filemon_ioctl(), ...



details:   https://anonhg.NetBSD.org/src/rev/52e89f92b192
branches:  trunk
changeset: 811948:52e89f92b192
user:      pgoyette <pgoyette%NetBSD.org@localhost>
date:      Mon Nov 23 22:20:57 2015 +0000

description:
Clean up the error paths in filemon_ioctl(), making sure to release the
rw_lock before returning.  Avoids a "locking against myself" error
reported by Brad Harder.

diffstat:

 sys/dev/filemon/filemon.c |  14 +++++++++-----
 1 files changed, 9 insertions(+), 5 deletions(-)

diffs (45 lines):

diff -r 97527dff9fb9 -r 52e89f92b192 sys/dev/filemon/filemon.c
--- a/sys/dev/filemon/filemon.c Mon Nov 23 21:40:14 2015 +0000
+++ b/sys/dev/filemon/filemon.c Mon Nov 23 22:20:57 2015 +0000
@@ -24,7 +24,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: filemon.c,v 1.17 2015/11/21 07:45:30 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: filemon.c,v 1.18 2015/11/23 22:20:57 pgoyette Exp $");
 
 #include <sys/param.h>
 #include <sys/kernel.h>
@@ -291,6 +291,8 @@
        if (!filemon)
                return EBADF;
 
+       /* filemon_fp_data() has locked the entry - make sure to unlock! */
+
        switch (cmd) {
        case FILEMON_SET_FD:
                /* Set the output file descriptor. */
@@ -302,8 +304,8 @@
                /* Now set up the new one */
                filemon->fm_fd = *((int *) data);
                if ((filemon->fm_fp = fd_getfile(filemon->fm_fd)) == NULL) {
-                       rw_exit(&filemon->fm_mtx);
-                       return EBADF;
+                       error = EBADF;
+                       break;
                }
                /* Write the file header. */
                filemon_comment(filemon);
@@ -336,8 +338,10 @@
                        p = p->p_pptr;
                        rw_exit(&lp->p_reflock);
                }
-               if (p == NULL)
-                       return EPERM;
+               if (p == NULL) {
+                       error = EPERM;
+                       break;
+               }
 
                error = kauth_authorize_process(curproc->p_cred,
                    KAUTH_PROCESS_CANSEE, tp,



Home | Main Index | Thread Index | Old Index