>Synopsis: aggr_add_port() checks that the member's ac_trport is NULL,
but only claims the member (sets ac_trport) at the very end of
the add. In between it issues member ioctls that can release
NET_LOCK (vxlan(4) does), so a second aggr_add_port() for the
same member passes the check too. On a DIAGNOSTIC kernel the
second add then panics on KASSERT(ac_trport == NULL); without
DIAGNOSTIC the member is taken over by two aggrs.
>Category: kernel
>Severity: serious (local DoS by root)
>Priority: medium
>Class: sw-bug
>Release: OpenBSD 8.0-current (source as of 2026-11-03)
>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_aggr.c rev 1.53, openbsd/src as of
2026-11-03, git d5b06e73
>Description:
aggr_add_port() (SIOCSTRUNKPORT, called with NET_LOCK held) refuses
a member that already belongs to a trunk/aggr/bridge port:
if (SMR_PTR_GET_LOCKED(&ac0->ac_trport) != NULL) {
error = EBUSY;
goto put;
}
It then calls aggr_group() (SIOCADDMULTI), aggr_p_setlladdr()
(SIOCSIFLLADDR and ifnewlladdr()), aggr_p_set_mtu() (SIOCSIFMTU) and
possibly ifpromisc() on the member, and only at the end publishes
the port (if_aggr.c:1318-1324):
KASSERT(SMR_PTR_GET_LOCKED(&ac0->ac_trport) == NULL);
aggr_port_take(p); /* for the SMR ptr */
SMR_PTR_SET_LOCKED(&ac0->ac_trport, &p->p_ether_port);
The check is only valid as long as NET_LOCK is held, but some member
drivers release it in those ioctls. ifnewlladdr() takes the member
down and up with SIOCSIFFLAGS, and vxlan_ioctl() handles that with
vxlan_down()/vxlan_up(), which do NET_UNLOCK() to take vxlan_lock.
A second "ifconfig aggrN trunkport vxlanM" for the same member can
run in that window, pass the EBUSY check, and later reach the
commit with ac_trport already set by the first add:
panic: kernel diagnostic assertion
"SMR_PTR_GET_LOCKED(&ac0->ac_trport) == NULL" failed: file
"/usr/src/sys/net/if_aggr.c", line 1322
aggr_add_port(ffff800000e27000,ffff800044ce2ea0) at aggr_add_port+0x949
aggr_ioctl(ffff800000e27000,8048698d,ffff800044ce2ea0) at aggr_ioctl+0x7a5
ifioctl(ffff800012fd8c00,8048698d,ffff800044ce2ea0,ffff800044c1da00)
at ifioctl+0xa4f
sys_ioctl(ffff800044c1da00,ffff800044ce3060,ffff800044ce2fe0) at
sys_ioctl+0x30e
Without DIAGNOSTIC the second add overwrites ac_trport, and the
member's if_ioctl/if_output and detach/link state hooks are taken
over by both aggrs.
>How-To-Repeat:
As root, on a DIAGNOSTIC kernel:
ifconfig vxlan0 create
ifconfig vxlan0 tunnel 127.0.0.1 127.0.0.2 vnetid 100
ifconfig vxlan0 up
ifconfig aggr0 create up
ifconfig aggr1 create up
while :; do ifconfig aggr0 trunkport vxlan0; ifconfig aggr0 -trunkport
vxlan0; done >/dev/null 2>&1 &
while :; do ifconfig aggr1 trunkport vxlan0; ifconfig aggr1 -trunkport
vxlan0; done >/dev/null 2>&1 &
sleep 60; kill %1 %2
The kernel panics with the assertion above during last step
this was done manually see ouput below
obsd-ci-agent-148# ifconfig vxlan0 create
ifconfig vxlan0 tunnel 127.0.0.1 127.0.0.2 vnetid 100
ifconfig vxlan0 up
ifconfig aggr0 create up
ifconfig aggr1 create up
while :; do ifconfig aggr0 trunkport vxlan0; ifconfig aggr0 -trunkport
vxlan0; done >/dev/null 2>&1 &
while :; do ifconfig aggr1 trunkport vxlan0; ifconfig aggr1 -trunkport
vxlan0; done >/dev/null 2>&1 &
sleep 60; kill %1 %2
obsd-ci-agent-148# ifconfig vxlan0 tunnel 127.0.0.1 127.0.0.2 vnetid 100
obsd-ci-agent-148# ifconfig vxlan0 up
obsd-ci-agent-148# ifconfig aggr0 create up
obsd-ci-agent-148# ifconfig aggr1 create up
nkport vxlan0; ifconfig aggr0 -trunkport vxlan0; done >/dev/null 2>&1 & <
[1] 67837
nkport vxlan0; ifconfig aggr1 -trunkport vxlan0; done >/dev/null 2>&1 & <
[2] 18951
obsd-ci-agent-148# sleep 60; kill %1 %2
panic: kernel diagnostic assertion "SMWARNING: SPL NOT LOWERED ON
SYSCR_PTR_GET_LOCKED(&ac0->ac_trport) A==LL 111 20 EXIT 0 c
Stop
Nped at savectx+0xae: movl $0,%gs:0x688
TID PID UID PRFLAGS PFLAGS CPU COMMAND
502188 80376 0 0x3 0 0 ifconfig
*244512 67837 0 0x10100001 0 1 ksh
savectx() at savectx+0xae
end of kernel
end trace frame: 0x7b6c8e8618b0, count: 14
https://www.openbsd.org/ddb.html describes the minimum info required in bug
reports. Insufficient info makes it difficult to find and fix bugs.
ddb{1}> bt
savectx() at savectx+0xae
end of kernel
end trace frame: 0x7b6c8e8618b0, count: -1
ddb{1}>
>Fix:
The diff below claims the member before the first call that can
release NET_LOCK: all of the port setup that cannot sleep (rx task
and mbuf list, timeouts, state machine fields) is moved before the
member ioctls, and ac_trport is set right after it, with a
placeholder input handler (aggr_port_reserved_input(), which hands
the packet back to the member) until the port is set up. A
concurrent add of the same member then gets EBUSY. At the end of
the add only the input handler is switched to aggr_port_input().
If one of the member ioctls fails, the claim is released and the
input path is waited for as in aggr_p_dtor() before the port is
freed.
Index: sys/net/if_aggr.c
===================================================================
--- sys/net/if_aggr.c
+++ sys/net/if_aggr.c
@@ -863,7 +863,18 @@ drop:
return (NULL);
}
+/*
+ * input handler for a port that aggr_add_port() has claimed but not
+ * finished setting up yet: hand the packet back to the member.
+ */
static struct mbuf *
+aggr_port_reserved_input(struct ifnet *ifp0, struct mbuf *m, uint64_t dst,
+ void *port, struct netstack *ns)
+{
+ return (m);
+}
+
+static struct mbuf *
aggr_port_input(struct ifnet *ifp0, struct mbuf *m, uint64_t dst, void *port,
struct netstack *ns)
{
@@ -1184,6 +1195,7 @@ aggr_add_port(struct aggr_softc *sc, const struct trun
struct aggr_multiaddr *ma;
struct cpumem_iter cmi;
struct refcnt *r;
+ struct smr_entry smrdtor;
int past = ticks - (hz * LACP_TIMEOUT_FACTOR);
int i;
int error;
@@ -1245,7 +1257,7 @@ aggr_add_port(struct aggr_softc *sc, const struct trun
refcnt_init(r);
}
- p->p_ether_port.ep_input = aggr_port_input;
+ p->p_ether_port.ep_input = aggr_port_reserved_input;
p->p_ether_port.ep_port_take = aggr_cpu_take;
p->p_ether_port.ep_port_rele = aggr_cpu_rele;
p->p_ether_port.ep_port = p;
@@ -1255,9 +1267,37 @@ aggr_add_port(struct aggr_softc *sc, const struct trun
p->p_ioctl = ifp0->if_ioctl;
p->p_output = ifp0->if_output;
+ task_set(&p->p_rxm_task, aggr_rx, p);
+ ml_init(&p->p_rxm_ml);
+
+ timeout_set_proc(&p->p_ptm_tx, aggr_ptm_tx, p);
+ timeout_set_proc(&p->p_txm_ntt, aggr_transmit_machine, p);
+ timeout_set_proc(&p->p_current_while_timer,
+ aggr_current_while_timer, p);
+ timeout_set_proc(&p->p_wait_while_timer, aggr_wait_while_timer, p);
+
+ p->p_muxed = 0;
+ p->p_collecting = 0;
+ p->p_distributing = 0;
+ p->p_selected = AGGR_PORT_UNSELECTED;
+ p->p_actor_state = LACP_STATE_AGGREGATION;
+
+ /*
+ * claim the member now. the member ioctls below can release
+ * NET_LOCK (eg, vxlan(4) does in its SIOCSIFFLAGS handler, which
+ * ifnewlladdr() calls), and without the claim a concurrent
+ * aggr_add_port() for the same member passes the ac_trport check
+ * above as well. modification of ac->ac_trport is protected by
+ * NET_LOCK, which has not been released since that check.
+ */
+ KASSERT(SMR_PTR_GET_LOCKED(&ac0->ac_trport) == NULL);
+ aggr_port_take(p); /* for the SMR ptr */
+ SMR_PTR_SET_LOCKED(&ac0->ac_trport, &p->p_ether_port);
+ membar_producer();
+
error = aggr_group(sc, p, SIOCADDMULTI);
if (error != 0)
- goto free;
+ goto unpublish;
error = aggr_p_setlladdr(p, sc->sc_ac.ac_enaddr);
if (error != 0)
@@ -1287,21 +1327,6 @@ aggr_add_port(struct aggr_softc *sc, const struct trun
task_set(&p->p_dhook, aggr_p_detach, p);
if_detachhook_add(ifp0, &p->p_dhook);
- task_set(&p->p_rxm_task, aggr_rx, p);
- ml_init(&p->p_rxm_ml);
-
- timeout_set_proc(&p->p_ptm_tx, aggr_ptm_tx, p);
- timeout_set_proc(&p->p_txm_ntt, aggr_transmit_machine, p);
- timeout_set_proc(&p->p_current_while_timer,
- aggr_current_while_timer, p);
- timeout_set_proc(&p->p_wait_while_timer, aggr_wait_while_timer, p);
-
- p->p_muxed = 0;
- p->p_collecting = 0;
- p->p_distributing = 0;
- p->p_selected = AGGR_PORT_UNSELECTED;
- p->p_actor_state = LACP_STATE_AGGREGATION;
-
/* commit */
DPRINTF(sc, "%s %s trunkport: creating port\n",
ifp->if_xname, ifp0->if_xname);
@@ -1316,14 +1341,11 @@ aggr_add_port(struct aggr_softc *sc, const struct trun
aggr_update_capabilities(sc);
/*
- * modification of ac->ac_trport is protected by NET_LOCK.
+ * ac_trport was claimed above; switch to the real input handler.
+ * make sure p is visible before handlers can run.
*/
-
- KASSERT(SMR_PTR_GET_LOCKED(&ac0->ac_trport) == NULL);
- aggr_port_take(p); /* for the SMR ptr */
- SMR_PTR_SET_LOCKED(&ac0->ac_trport, &p->p_ether_port);
-
- /* make sure p is visible before handlers can run */
+ KASSERT(SMR_PTR_GET_LOCKED(&ac0->ac_trport) == &p->p_ether_port);
+ p->p_ether_port.ep_input = aggr_port_input;
membar_producer();
ifp0->if_ioctl = aggr_p_ioctl;
ifp0->if_output = aggr_p_output;
@@ -1350,7 +1372,24 @@ ungroup:
"unable to remove LACP group address\n",
ifp->if_xname, ifp0->if_xname);
}
-free:
+unpublish:
+ /*
+ * release the claim on the member, and wait for the input path
+ * to stop using the port as aggr_p_dtor() does.
+ */
+ KASSERT(SMR_PTR_GET_LOCKED(&ac0->ac_trport) == &p->p_ether_port);
+ SMR_PTR_SET_LOCKED(&ac0->ac_trport, NULL);
+
+ smr_init(&smrdtor);
+
+ /* fold the per cpu refcnt back into the port refcnt */
+ CPUMEM_FOREACH(r, &cmi, p->p_cpurefs)
+ aggr_cpu_rele(r, p);
+
+ /* release the SMR ptr ref and wait for all refs to finalize */
+ smr_call(&smrdtor, aggr_port_rele, p);
+ refcnt_finalize(&p->p_refs, "aggradd");
+
cpumem_free(p->p_cpurefs, M_DEVBUF, sizeof(*r));
free(p, M_DEVBUF, sizeof(*p));
put:
>Verification:
The diff above was applied with patch -p0, on its own, to a pristine
openbsd/src tree as of 2026-11-03 (git d5b06e73, sys/net/if_aggr.c
rev 1.53); all hunks applied with no offset or fuzz. Kernel:
GENERIC.MP + "option WITNESS" (DIAGNOSTIC comes from GENERIC),
amd64, built without warnings. Unpatched = the same tree and
config without the diff. 2-vcpu guest. How-To-Repeat run exactly
as listed (step 8 with "sleep 300" for the long run):
unpatched: 60 s x5: KASSERT "ac_trport == NULL" in aggr_add_port()
5/5
300 s x1: same KASSERT, 1/1
(plus 1/1 in an earlier trial run on a second guest)
patched: 60 s x5: no panic, assertion or wedge, 0/5
300 s x1: 0/1
Normal use on the patched kernel: an aggr with two vether ports, one
removed and re-added, a member destroyed (its port goes away), the
aggr destroyed (the other member is released); then two aggrs
LACP-peered over a pair(4) patch cable reach "status: active" with
the ports collecting and distributing. 0 failures, no panic or
assertion.