Grab the non-exclusive net lock to read-only traverse the interface list
authorkn <kn@openbsd.org>
Fri, 21 Oct 2022 14:20:03 +0000 (14:20 +0000)
committerkn <kn@openbsd.org>
Fri, 21 Oct 2022 14:20:03 +0000 (14:20 +0000)
Destroying lo(4) interfaces checks for other interfaces in the same
rdomain(4) first which does not modify anything, so allow other readers.

All interface ioctl(2)s currently run with the kernel lock held, so this
should not make a real difference...

OK mvs

sys/net/if_loop.c

index a158204..4077198 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: if_loop.c,v 1.92 2022/09/08 10:22:06 kn Exp $ */
+/*     $OpenBSD: if_loop.c,v 1.93 2022/10/21 14:20:03 kn Exp $ */
 /*     $NetBSD: if_loop.c,v 1.15 1996/05/07 02:40:33 thorpej Exp $     */
 
 /*
@@ -204,16 +204,16 @@ loop_clone_destroy(struct ifnet *ifp)
                        return (EPERM);
 
                /* if there is any other interface in this rdomain, deny */
-               NET_LOCK();
+               NET_LOCK_SHARED();
                TAILQ_FOREACH(p, &ifnetlist, if_list) {
                        if (p->if_rdomain != ifp->if_rdomain)
                                continue;
                        if (p->if_index == ifp->if_index)
                                continue;
-                       NET_UNLOCK();
+                       NET_UNLOCK_SHARED();
                        return (EBUSY);
                }
-               NET_UNLOCK();
+               NET_UNLOCK_SHARED();
 
                rdomain = ifp->if_rdomain;
        }