>Synopsis:
SIOCSIFRDOMAIN and if_clone_destroy() acquire the global
if_cloners_lock in opposite order with respect to an interface's
if_refcnt, a classic ABBA lock-order inversion. When a
"ifconfig <if> rdomain <N>" (into a not-yet-existing rdomain) races the
"ifconfig <if> destroy" of the same interface, the destroy sleeps
forever in refcnt_finalize() on wchan "ifrm" while HOLDING
if_cloners_lock, and the rdomain ioctl sleeps forever on wchan
"clonelk" while holding the ifnet reference the destroy is waiting for.
Both threads are unkillable (state DU) and every subsequent clone
operation anywhere on the system (create/destroy of ANY interface)
piles up on "clonelk". The machine stays otherwise alive but all
interface (de)configuration is dead; only a reset recovers it.
This is a pure lock-order deadlock between two legitimate operations
-- no leaked reference and no use-after-free.
>Category: kernel
>Environment:
System : OpenBSD 8.0-current
Details : OpenBSD 8.0-current (GENERIC.MP), WITNESS + DIAGNOSTIC
Architecture: OpenBSD.amd64
Machine : amd64 (QEMU/KVM guest, 2 vcpu)
Source : sys/net/if.c rev 1.767, openbsd/src as of 2026-11-03, git
d5b06e73
>Description:
ifioctl() (sys/net/if.c) takes a reference on the target ifnet with
if_unit() and holds it across the whole ioctl, releasing it with
if_put() only at the very end:
ifp = if_unit(ifr->ifr_name); /* if_ref: if_refcnt++ */
...
case SIOCSIFRDOMAIN:
error = if_createrdomain(ifr->ifr_rdomainid, ifp);
if (!error || error == EEXIST) {
NET_LOCK();
error = if_setrdomain(ifp, ifr->ifr_rdomainid);
NET_UNLOCK();
}
break;
...
if_put(ifp); /* ref released HERE, at the
end */
For a destination rdomain that has no routing table yet,
if_createrdomain() creates the rdomain's loopback by calling the
cloner directly:
if_createrdomain(int rdomain, struct ifnet *ifp)
rtable_add(rdomain);
...
error = if_clone_create(loifname, 0); /* -> clonelk */
if_clone_create() does rw_enter_write(&if_cloners_lock). So the
rdomain ioctl is: HOLD if_refcnt(ifp), then BLOCK on if_cloners_lock.
Meanwhile if_clone_destroy() (sys/net/if.c) takes if_cloners_lock
FIRST and holds it across the entire teardown, which ends in
refcnt_finalize() waiting for every outstanding ifnet reference to be
released:
if_clone_destroy(const char *name)
rw_enter_write(&if_cloners_lock); /* clonelk held */
...
ret = (*ifc->ifc_destroy)(ifp); /* -> if_detach -> */
/* if_remove -> */
/*
refcnt_finalize(ifrm) */
rw_exit_write(&if_cloners_lock);
if_remove(struct ifnet *ifp)
...
refcnt_finalize(&ifp->if_refcnt, "ifrm");
So the destroy is: HOLD if_cloners_lock, then BLOCK (ifrm) on
if_refcnt(ifp) dropping to zero.
Deadlock (ABBA):
destroy holds clonelk, waits (ifrm) for ifp's if_refcnt
rdomain holds if_refcnt, waits (clonelk) for if_cloners_lock
Neither can make progress. refcnt_finalize()/rw_enter_write() are
uninterruptible, so both ifconfig processes are stuck in state DU and
cannot be killed. Because if_clone_create() and if_clone_destroy()
for EVERY cloner serialize on the single global if_cloners_lock, every
later "ifconfig ... create/destroy" (and any other SIOCSIFRDOMAIN into
a fresh rdomain) also blocks on clonelk indefinitely. The system is
otherwise responsive but interface management is permanently dead.
Found by a layer-2 loop topology fuzzer whose teardown destroyed
interfaces while "rdomain" was still being issued on them.
>How-To-Repeat:
As root, for 60 seconds (errors of the loops discarded; rdomains
150-152 have no routing table yet, so the first SIOCSIFRDOMAIN into
each creates its loopback via if_clone_create()):
T=60; end=$(( $(date +%s) + T ))
for u in 170 171 172 173; do
( while [ $(date +%s) -lt $end ]; do
ifconfig vether$u create; ifconfig vether$u destroy; done ) &
for r in 150 151 152; do
( while [ $(date +%s) -lt $end ]; do
ifconfig vether$u rdomain $r; done ) &
done
done
then, 10 seconds after the loops stop:
ps axww -O wchan | awk '$4 ~ /D/'
36260 ifrm ?? DU ifconfig vether172 destroy
62046 clonelk ?? DU ifconfig vether172 rdomain 151
98572 clonelk ?? DU ifconfig vether173 rdomain 152
23603 clonelk ?? DU ifconfig vether171 create
...
The threads sleep uninterruptibly (DU); only a reset recovers.
>Fix:
Do not hold the ifnet reference across if_createrdomain().
SIOCSIFRDOMAIN remembers the interface index, drops its reference,
creates the rdomain (and its loopback, which takes if_cloners_lock),
then looks the interface up again by index. If it was destroyed in
the meantime (or the index now names a different interface), the
ioctl returns ENXIO. if_createrdomain() takes the index instead of
the ifnet pointer; it only used the pointer to recognise "the
loopback being created is the interface itself" (EEXIST), which the
index comparison does equally.
With no reference held, the destroy's refcnt_finalize() completes,
if_clone_destroy() releases if_cloners_lock, and the rdomain ioctl
proceeds (and then fails with ENXIO).
A more general alternative would be for if_clone_destroy() not to
hold if_cloners_lock across the refcnt_finalize() wait at all, so no
reference held by any concurrent operation can stall every clone
operation on the system. That is a larger change to the cloner
locking and is not attempted here.
Index: sys/net/if.c
===================================================================
RCS file: /cvs/src/sys/net/if.c,v
retrieving revision 1.767
diff -u -p -r1.767 if.c
--- sys/net/if.c 24 Oct 2026 15:47:07 -0000 1.767
+++ sys/net/if.c 5 Nov 2026 07:09:31 -0000
@@ -128,7 +128,7 @@
void if_attachsetup(struct ifnet *);
void if_attach_common(struct ifnet *);
void if_remove(struct ifnet *);
-int if_createrdomain(int, struct ifnet *);
+int if_createrdomain(int, unsigned int);
int if_setrdomain(struct ifnet *, int);
void if_slowtimo(void *);
@@ -2021,7 +2021,7 @@ if_setlladdr(struct ifnet *ifp, const ui
}
int
-if_createrdomain(int rdomain, struct ifnet *ifp)
+if_createrdomain(int rdomain, unsigned int ifidx)
{
int error;
struct ifnet *loifp;
@@ -2038,7 +2038,7 @@ if_createrdomain(int rdomain, struct ifn
error = if_clone_create(loifname, 0);
if ((loifp = if_unit(loifname)) == NULL)
return (ENXIO);
- if (error && (ifp != loifp || error != EEXIST)) {
+ if (error && (ifidx != loifp->if_index || error != EEXIST)) {
if_put(loifp);
return (error);
}
@@ -2374,16 +2374,38 @@ forceup:
ifp->if_priority = ifr->ifr_metric;
break;
- case SIOCSIFRDOMAIN:
+ case SIOCSIFRDOMAIN: {
+ unsigned int ifidx = ifp->if_index;
+
if ((error = suser(p)) != 0)
break;
- error = if_createrdomain(ifr->ifr_rdomainid, ifp);
+ /*
+ * Creating the rdomain may create its loopback interface,
+ * which takes if_cloners_lock. Do not hold a reference to
+ * ifp across that: if_clone_destroy() holds if_cloners_lock
+ * while it waits in if_remove() for the last reference to
+ * the interface ("ifrm"), so the two would deadlock and
+ * wedge all interface cloning for good.
+ */
+ if_put(ifp);
+ error = if_createrdomain(ifr->ifr_rdomainid, ifidx);
+ ifp = if_get(ifidx);
+ if (ifp == NULL ||
+ strcmp(ifp->if_xname, ifr->ifr_name) != 0) {
+ /* destroyed while we were not holding it */
+ if_put(ifp);
+ KERNEL_UNLOCK();
+ return (ENXIO);
+ }
+ oif_flags = ifp->if_flags;
+ oif_xflags = ifp->if_xflags;
if (!error || error == EEXIST) {
NET_LOCK();
error = if_setrdomain(ifp, ifr->ifr_rdomainid);
NET_UNLOCK();
}
break;
+ }
case SIOCAIFGROUP:
if ((error = suser(p)))
>Verification:
Diff applied as shown with patch -p0 to sys/net/if.c r1.767
(openbsd/src as of 2026-11-03), no fuzz or offset; kernel
GENERIC.MP + WITNESS + DIAGNOSTIC, amd64, 2 vcpu, built without
warnings. Unpatched = the same tree without the diff, same config.
How-To-Repeat run for 60 s five times and for 300 s once on each
kernel, each run after a fresh boot or a reset:
unpatched: 6/6 permanent wedge (destroy in "ifrm", rdomain ioctls
and later clone operations in "clonelk"); reset needed.
patched: 0/6; no thread left in D state 10 s after the loops
stopped, no WITNESS or DIAGNOSTIC output.
A normal-use run on the patched kernel, which moves interfaces into
new rdomains (80, 83) and pings across tpmr/veb/bridge between them,
gave the same results as on the unpatched kernel.
Current -current: commit 37be935f0 (the rtables rework) changed
sys/net/if.c after this report's base, so the diff above no longer
applies to the tip. The same fix rebased onto origin/master
afb08c4d5 is appended below; the deadlock still reproduces there
and the rebased fix clears it (GENERIC.MP, 0 warnings, fresh reboot
per run, VM with 4 vcpu):
unpatched master WEDGE 3/3 (ifconfig ...rdomain stuck DU on
clonelk 10 s+ after the race)
patched master SURVIVED 3/3
The rebased diff changes if_createrdomain() the same way (it has a
single caller and is not in any header, so the parameter-type change
is fully contained; no data structure is altered):
----------------------------------------------------------------------
Rebased for -current after commit 37be935f0 (origin/master afb08c4d5,
sys/net/if.c). Apply this instead of the diff above on a tree that
includes the rtables rework.
Index: sys/net/if.c
===================================================================
--- sys/net/if.c
+++ sys/net/if.c
@@ -128,7 +128,7 @@
void if_attachsetup(struct ifnet *);
void if_attach_common(struct ifnet *);
void if_remove(struct ifnet *);
-int if_createrdomain(struct ifnet *, unsigned int);
+int if_createrdomain(unsigned int, unsigned int);
int if_setrdomain(struct ifnet *, unsigned int);
void if_slowtimo(void *);
@@ -2021,7 +2021,7 @@ if_setlladdr(struct ifnet *ifp, const ui
}
int
-if_createrdomain(struct ifnet *ifp, unsigned int rdomain)
+if_createrdomain(unsigned int ifidx, unsigned int rdomain)
{
int error;
struct ifnet *loifp;
@@ -2038,7 +2038,7 @@ if_createrdomain(struct ifnet *ifp, unsi
error = if_clone_create(loifname, 0);
if ((loifp = if_unit(loifname)) == NULL)
return (ENXIO);
- if (error && (ifp != loifp || error != EEXIST)) {
+ if (error && (ifidx != loifp->if_index || error != EEXIST)) {
if_put(loifp);
return (error);
}
@@ -2371,20 +2371,42 @@ forceup:
ifp->if_priority = ifr->ifr_metric;
break;
- case SIOCSIFRDOMAIN:
+ case SIOCSIFRDOMAIN: {
+ unsigned int ifidx = ifp->if_index;
+
if ((error = suser(p)) != 0)
break;
if (ifr->ifr_rdomainid < 0) {
error = EINVAL;
break;
}
- error = if_createrdomain(ifp, ifr->ifr_rdomainid);
+ /*
+ * Creating the rdomain may create its loopback interface,
+ * which takes if_cloners_lock. Do not hold a reference to
+ * ifp across that: if_clone_destroy() holds if_cloners_lock
+ * while it waits in if_remove() for the last reference to
+ * the interface ("ifrm"), so the two would deadlock and
+ * wedge all interface cloning for good.
+ */
+ if_put(ifp);
+ error = if_createrdomain(ifidx, ifr->ifr_rdomainid);
+ ifp = if_get(ifidx);
+ if (ifp == NULL ||
+ strcmp(ifp->if_xname, ifr->ifr_name) != 0) {
+ /* destroyed while we were not holding it */
+ if_put(ifp);
+ KERNEL_UNLOCK();
+ return (ENXIO);
+ }
+ oif_flags = ifp->if_flags;
+ oif_xflags = ifp->if_xflags;
if (!error || error == EEXIST) {
NET_LOCK();
error = if_setrdomain(ifp, ifr->ifr_rdomainid);
NET_UNLOCK();
}
break;
+ }
case SIOCAIFGROUP:
if ((error = suser(p)))