Source-Changes-HG archive

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

[src/trunk]: src/sys/net tun: fix locking against myself



details:   https://anonhg.NetBSD.org/src/rev/37c2eb95bf66
branches:  trunk
changeset: 363630:37c2eb95bf66
user:      ozaki-r <ozaki-r%NetBSD.org@localhost>
date:      Fri Aug 03 09:54:40 2018 +0000

description:
tun: fix locking against myself

filt_tunread is called with tun_lock held from tun_output (via tun_output =>
selnotify => knote), so we must not take tun_lock in filt_tunread.  The bug
is triggered only if a tun is used through kqueue.

Found by k-goda@IIJ

diffstat:

 sys/net/if_tun.c |  13 +++++--------
 1 files changed, 5 insertions(+), 8 deletions(-)

diffs (40 lines):

diff -r 0cb43ff97139 -r 37c2eb95bf66 sys/net/if_tun.c
--- a/sys/net/if_tun.c  Fri Aug 03 07:44:31 2018 +0000
+++ b/sys/net/if_tun.c  Fri Aug 03 09:54:40 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_tun.c,v 1.144 2018/06/26 06:48:02 msaitoh Exp $     */
+/*     $NetBSD: if_tun.c,v 1.145 2018/08/03 09:54:40 ozaki-r Exp $     */
 
 /*
  * Copyright (c) 1988, Julian Onions <jpo%cs.nott.ac.uk@localhost>
@@ -19,7 +19,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_tun.c,v 1.144 2018/06/26 06:48:02 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_tun.c,v 1.145 2018/08/03 09:54:40 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -1058,18 +1058,15 @@
        struct ifnet *ifp = &tp->tun_if;
        struct mbuf *m;
 
-       mutex_enter(&tp->tun_lock);
+       KASSERT(mutex_owned(&tp->tun_lock));
+
        IF_POLL(&ifp->if_snd, m);
-       if (m == NULL) {
-               mutex_exit(&tp->tun_lock);
+       if (m == NULL)
                return 0;
-       }
 
        for (kn->kn_data = 0; m != NULL; m = m->m_next)
                kn->kn_data += m->m_len;
 
-       mutex_exit(&tp->tun_lock);
-
        return 1;
 }
 



Home | Main Index | Thread Index | Old Index