Hi Vitaliy,
Thanks, the early exit in bridge_ioctl() is simpler. and it solves
another problem
that I had not gotten around to reporting yet it was tested against
my fuzzer ci scripts
and I manually tested it also both before and after again, and
the your diff works,
Thanks again,
Same machine, same repro as in the report (a loop re-adding the port
while the bridge is destroyed, an unrelated "ifconfig vether241 create"
from another process), 5 x 60 s + 1 x 300 s per kernel:
unpatched: 6/6 livelock -- destroy in "smrbar", the create in
"clonelk", both still waiting after 20 s; the destroy
finished 1 s after the re-adder was stopped
your diff: 6/6 ok -- every destroy returned within 2 s while the
re-adder kept running, 180 destroy cycles, ~9600 adds
refused with ENXIO; no panic, nothing in dmesg
The member variant (re-adding with "add" instead of "addspan") was fine
with your diff as well (1 x 60 s, 20 cycles).
Normal use with your diff, all as expected: add/delete/re-add of
members and span ports, re-adding an existing member or span is a
no-op, member promiscuous mode on and off, STP on members, bridge up
and running, destroying a member removes it, destroying a bridge with
members, a span port and STP (1 s), and reusing the former member and
span port in a new bridge. dmesg clean.
another effectthat is nice because every bridge ioctl now fails once
sc_dying is set, a concurrent "ifconfig bridgeN up" during the destroy
can no longer call bridge_init() after bridge_stop() has run. I have a
separate, not yet sent report for that race (destroy vs. SIOCSIFFLAGS
re-arming sc_brtimeout on a softc that is then freed; softclock faults
on the freed bridge). Its repro panicked the unpatched kernel 6 out of
6 times; with your diff it ran clean 3 out of 3 (3 x 60 s, ~107 cycles
each). I can send that report separately if useful.
Thanks again
Tom
On Sat, 7 Nov 2026 at 16:54, Tom Smyth <[email protected]> wrote:
>
> Hi Vitaliy, im running your patch through the tests there and Ill
> report back as soon as it is done , Thanks again,
>
> if there is anything else i can do to assist let me know ..
>
> On Sat, 7 Nov 2026 at 15:05, Vitaliy Makkoveev <[email protected]> wrote:
> >
> > On Sat, Nov 07, 2026 at 12:55:45AM +0000, [email protected]
> > wrote:
> > > >Synopsis: bridge_clone_destroy() empties the span list one port at a
> > > time and sleeps in smr_barrier() for each; a concurrent
> > > SIOCBRDGADDS puts the port back during that sleep, so the
> > > loop
> > > does not end while someone keeps adding, and if_cloners_lock
> > > is held the whole time
> > > >Category: kernel
> > > >Severity: non-critical
> > > >Class: sw-bug
> > > >Release: OpenBSD 8.0-current (src as of 2026-11-03)
> > > >Environment:
> > > System : OpenBSD 8.0-current, GENERIC.MP as shipped
> > > (DIAGNOSTIC,
> > > POOL_DEBUG)
> > > Architecture: OpenBSD.amd64
> > > Machine : amd64 (QEMU/KVM guest), 2 CPUs
> > > Source : sys/net/if_bridge.c rev 1.382, if_bridge.h rev 1.78,
> > > sys/net/if.c as of 2026-11-03 (line numbers below
> > > are from these)
> > >
> > > >Description:
> > >
> > > if_clone_destroy() takes if_cloners_lock for writing (if.c:1445) and
> > > calls bridge_clone_destroy() (if_bridge.c:221), which empties the
> > > member and span lists like this:
> > >
> > > while ((bif = SMR_SLIST_FIRST_LOCKED(&sc->sc_iflist)) != NULL)
> > > bridge_ifremove(bif); /* :235 */
> > > while ((bif = SMR_SLIST_FIRST_LOCKED(&sc->sc_spanlist)) != NULL)
> > > bridge_spanremove(bif); /* :237 */
> > >
> > > bridge_spanremove() unlinks the port and then sleeps in
> > > smr_barrier() (:585), which releases the KERNEL_LOCK. The bridge
> > > is still on the interface list, so ioctls still reach
> > > bridge_ioctl(), which drops the NET_LOCK on entry (:270).
> > > SIOCBRDGADDS (:364) then checks only that the port is an Ethernet
> > > interface, that its if_bridgeidx is 0 (a span port never sets it)
> > > and that it is not already in sc_spanlist (:385; it was just
> > > unlinked), and inserts it again (:412). Nothing in SIOCBRDGADDS
> > > knows that the bridge is being destroyed.
> > >
> > > When smr_barrier() returns, the loop reads the head of sc_spanlist
> > > again, finds the re-added port, removes it and sleeps again. In
> > > testing, each sleep was long enough for another "ifconfig bridgeN
> > > addspan ifX" to get in, so as long as a process kept re-adding the
> > > port the loop did not end. The destroying process sits in
> > > "smrbar", and since it holds if_cloners_lock, every other interface
> > > create or destroy on the system (any driver) blocks in "clonelk"
> > > behind it:
> > >
> > > PID STAT WCHAN ELAPSED COMMAND
> > > 2888 DU smrbar 00:20 ifconfig bridge240 destroy
> > > 78813 DU clonelk 00:18 ifconfig vether241 create
> > >
> > > Destroy completes about a second after the adding process is
> > > stopped. The member loop has the same shape (bridge_ifremove()
> > > sleeps in smr_barrier() at :555 and in NET_LOCK() at :563, and
> > > if_bridgeidx is cleared at :562 before the second sleep), but a
> > > member loop that does not end was not seen in testing: during the
> > > smr_barrier() sleep the member's if_bridgeidx still refuses the
> > > add with EEXIST.
> > >
> > > Both SIOCIFDESTROY and SIOCBRDGADDS need root; no hardware is
> > > involved.
> > >
> > > >How-To-Repeat:
> > >
> > > As root, in one ksh session (bridge9, vether8 and vether9 must not
> > > exist yet):
> > >
> > > 1. ifconfig vether9 create up
> > > 2. ifconfig bridge9 create
> > > 3. ifconfig bridge9 addspan vether9
> > > 4. while :; do ifconfig bridge9 addspan vether9 2>/dev/null; done &
> > > 5. A=$!; sleep 1; ifconfig bridge9 destroy & D=$!
> > > 6. sleep 2; ifconfig vether8 create & C=$!
> > > 7. sleep 30; ps -o pid,stat,wchan,etime,command -p $D
> > > 8. ps -o pid,stat,wchan,etime,command -p $C
> > > 9. kill $A; wait $D $C
> > > 10. ifconfig bridge9 destroy; ifconfig vether9 destroy
> > > 11. ifconfig vether8 destroy
> > >
> > > Step 4 keeps adding vether9 as a span port of bridge9, step 5
> > > destroys bridge9 and step 6 creates an unrelated interface from
> > > another process. On the unpatched kernel, step 7 still shows the
> > > destroy in state D, wchan "smrbar", and step 8 shows the create in
> > > state D, wchan "clonelk", both still waiting after 30 s. The
> > > destroy and the create return as soon as step 9 stops the loop, and
> > > the "ifconfig bridge9 destroy" in step 10 then fails because bridge9
> > > is gone. On the patched kernel both have returned before step 7;
> > > the loop, which keeps running until step 9, may create bridge9
> > > again (ifconfig creates a missing cloned interface), and step 10
> > > removes it.
> > >
> > > >Fix:
> > >
> > > Mark the bridge as dying at the start of bridge_clone_destroy() and
> > > refuse SIOCBRDGADD and SIOCBRDGADDS on a dying bridge. Both the
> > > flag and the check run under the KERNEL_LOCK, like the list
> > > updates. Once the flag is set, only an add that was already past
> > > the check can still insert a port, and each such ioctl can insert
> > > at most one, so the removal loops end.
> > >
> >
> > I prefer to exit early, at the beginning of bridge_ioctl().
> >
> > Index: sys/net/if_bridge.c
> > ===================================================================
> > RCS file: /cvs/src/sys/net/if_bridge.c,v
> > retrieving revision 1.382
> > diff -u -p -r1.382 if_bridge.c
> > --- sys/net/if_bridge.c 2 Dec 2025 03:24:19 -0000 1.382
> > +++ sys/net/if_bridge.c 7 Nov 2026 15:02:01 -0000
> > @@ -223,6 +223,8 @@ bridge_clone_destroy(struct ifnet *ifp)
> > struct bridge_softc *sc = ifp->if_softc;
> > struct bridge_iflist *bif;
> >
> > + sc->sc_dying = 1;
> > +
> > /*
> > * bridge(4) detach hook doesn't need the NET_LOCK(), worst the
> > * use of smr_barrier() while holding the lock might lead to a
> > @@ -256,6 +258,9 @@ bridge_ioctl(struct ifnet *ifp, u_long c
> > struct bstp_port *bp;
> > struct bstp_state *bs = sc->sc_stp;
> > int error = 0;
> > +
> > + if (sc->sc_dying)
> > + return (ENXIO);
> >
> > /*
> > * bridge(4) data structure aren't protected by the NET_LOCK().
> > Index: sys/net/if_bridge.h
> > ===================================================================
> > RCS file: /cvs/src/sys/net/if_bridge.h,v
> > retrieving revision 1.78
> > diff -u -p -r1.78 if_bridge.h
> > --- sys/net/if_bridge.h 9 Oct 2026 16:36:24 -0000 1.78
> > +++ sys/net/if_bridge.h 7 Nov 2026 15:02:01 -0000
> > @@ -518,6 +518,7 @@ struct bridge_rtnode {
> > */
> > struct bridge_softc {
> > struct ifnet sc_if; /* the interface */
> > + int sc_dying; /* [k] */
> > uint32_t sc_brtmax; /* [m] max #
> > addresses */
> > uint32_t sc_brtcnt; /* [m] current #
> > addrs */
> > int sc_brttimeout; /* timeout ticks */
>
>
>
> --
> Kindest regards,
> Tom Smyth.
--
Kindest regards,
Tom Smyth.