Wrap by netlock the whole foreach loop which calls switch_port_detach() in
authormvs <mvs@openbsd.org>
Tue, 23 Feb 2021 15:13:58 +0000 (15:13 +0000)
committermvs <mvs@openbsd.org>
Tue, 23 Feb 2021 15:13:58 +0000 (15:13 +0000)
switch_clone_destroy(). This fixes netlock assertion within underlay
ifpromisc(). The problem was reported by hrvoje@ [1].

"why not" by deraadt@

1. https://marc.info/?l=openbsd-bugs&m=161338077403538&w=2

sys/net/if_switch.c

index 15c6e77..447e164 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: if_switch.c,v 1.40 2021/01/19 19:39:14 mvs Exp $      */
+/*     $OpenBSD: if_switch.c,v 1.41 2021/02/23 15:13:58 mvs Exp $      */
 
 /*
  * Copyright (c) 2016 Kazuya GODA <goda@openbsd.org>
@@ -196,6 +196,7 @@ switch_clone_destroy(struct ifnet *ifp)
        struct switch_port      *swpo, *tp;
        struct ifnet            *ifs;
 
+       NET_LOCK();
        TAILQ_FOREACH_SAFE(swpo, &sc->sc_swpo_list, swpo_list_next, tp) {
                if ((ifs = if_get(swpo->swpo_ifindex)) != NULL) {
                        switch_port_detach(ifs);
@@ -204,6 +205,7 @@ switch_clone_destroy(struct ifnet *ifp)
                        log(LOG_ERR, "failed to cleanup on ifindex(%d)\n",
                            swpo->swpo_ifindex);
        }
+       NET_UNLOCK();
        LIST_REMOVE(sc, sc_switch_next);
        bstp_destroy(sc->sc_stp);
        swofp_destroy(sc);