>Synopsis: tpmr_add_port(), veb_add_port() and the bridge(4) SIOCBRDGADD
handler reject an interface that is already a bridge-family
port (ether_brport_isset) but do NOT reject one that is already
a trunk(4)/aggr(4) port (ac_trport).  aggr_add_port() and
trunk_port_create() check both.  The missing check lets an
interface be a member of an aggr/trunk AND a bridge-family
device at once; the two subsystems independently save/restore
the member's if_ioctl, corrupt each other on teardown, and a
stale aggr_p_ioctl/trunk handler is later re-entered after the
ether_port was cleared -> KASSERT "ep != NULL" (NULL deref on a
non-DIAGNOSTIC kernel).
>Category: kernel
>Severity: serious
>Priority: medium
>Class: sw-bug
>Release: OpenBSD 8.0-current (snapshot, GENERIC.MP #125, 2026-11-02)
>Environment:
System      : OpenBSD 8.0
Details     : OpenBSD 8.0-current (GENERIC.MP) #125
Architecture: OpenBSD.amd64
Machine     : amd64 (QEMU/KVM guest, 4 vcpu)

if_tpmr.c   $OpenBSD: if_tpmr.c,v 1.45 2026/02/05 03:26:00 dlg Exp $
if_veb.c    $OpenBSD: if_veb.c,v 1.74 2026/10/17 16:12:45 deraadt Exp $
if_bridge.c $OpenBSD: if_bridge.c,v 1.382 2025/12/02 03:24:19 dlg Exp $
if_aggr.c   $OpenBSD: if_aggr.c,v 1.53 2025/12/02 03:50:56 dlg Exp $

>Description:
I have manually verified this  bug
aggr(4) and trunk(4) protect against an interface being enslaved to
two incompatible subsystems: aggr_add_port() (if_aggr.c) and
trunk_port_create() (if_trunk.c) both reject a candidate port that is
already a bridge-family port, via

   error = ether_brport_isset(ifp0);   /* != 0 (EBUSY) if ac_brport set */

and also reject one already in a trunk/aggr, via

   if (SMR_PTR_GET_LOCKED(&ac0->ac_trport) != NULL)
   return (EBUSY);

The three bridge-family port-add paths only do HALF of this.  They
check ether_brport_isset() (so two bridge-family devices can't share a
port) and if_type == IFT_ETHER, but they never test ac_trport, so an
interface that is already an aggr(4)/trunk(4) port is accepted:

   tpmr_add_port()           if_tpmr.c
   veb_add_port()            if_veb.c
   bridge SIOCBRDGADD        if_bridge.c (bridge_ioctl)

Note aggr(4) sets if_type = IFT_IEEE8023ADLAG on the aggr *interface*,
not on its member ports, so the member keeps IFT_ETHER and the
if_type guard does not catch this.

Both aggr/trunk and the bridge-family interpose the member's if_ioctl
by saving the previous handler and installing their own (aggr:
if_ioctl = aggr_p_ioctl, saving p_ioctl; tpmr/veb likewise).  When the
same ifnet is a member of both, the two saved/restored chains overlap.
On teardown they clobber each other: e.g. removing the aggr port
restores the member's if_ioctl to aggr's saved original and clears
ac_trport, while tpmr/veb still hold p_ioctl == aggr_p_ioctl.  When the
bridge-family port is then destroyed, *_p_dtor() restores that stale
aggr_p_ioctl and (tpmr) calls ifpromisc(), re-entering aggr_p_ioctl
with ac_trport == NULL:

   const struct ether_port *ep = SMR_PTR_GET_LOCKED(&ac0->ac_trport);
   KASSERTMSG(ep != NULL, "%s: %s called without an ether_port set", ...)

   panic: kernel diagnostic assertion "ep != NULL" failed:
       file ".../sys/net/if_aggr.c", line 1470
       vether0: aggr_p_ioctl called without an ether_port set

On a GENERIC (non-DIAGNOSTIC) kernel the KASSERT is compiled out and
the following "p = ep->ep_port" is a NULL dereference.

Two teardown backtraces were captured (amd64, GENERIC.MP + WITNESS +
DIAGNOSTIC) under a concurrent ifconfig fuzzer:

(a) via tpmr destroy:
   aggr_p_ioctl()        at aggr_p_ioctl+0x242
   ifpromisc(ifp0, 0)
   tpmr_p_dtor()
   tpmr_clone_destroy()
   if_clone_destroy()
   ifioctl(..., SIOCIFDESTROY, ...)
   sys_ioctl(); syscall(); Xsyscall()

(b) via a status ioctl dispatched to a now-stale member handler
   (cmd 0xc0206943 = SIOCBRDGRTS, issued by "ifconfig <member>"):
   aggr_p_ioctl()        at aggr_p_ioctl+0x242
   ifioctl(..., SIOCBRDGRTS, ...) at ifioctl+0xa4f
   sys_ioctl(); syscall(); Xsyscall()

All operations are available to root via SIOCBRDGADD / SIOCSTRUNKPORT /
SIOCIFDESTROY; no special hardware is involved.

This is the deterministic, non-racing root of an "ep != NULL" panic
that was previously thought to be an intermittent teardown race: the
fuzzer simply reaches the aggr-first-then-bridge-family ordering.  It
is the symmetric counterpart of the earlier trunk_port_create() fix
that added ether_brport_isset() to trunk(4).

>How-To-Repeat:

As root (tpmr shown; veb and bridge behave identically):

   ifconfig aggr0 create
   ifconfig vether0 create
   ifconfig aggr0 trunkport vether0
   ifconfig tpmr0 create
   ifconfig tpmr0 add vether0     # should fail EBUSY, but succeeds
   ifconfig aggr0 destroy         # clears ac_trport; tpmr keeps stale p_ioctl
   ifconfig tpmr0 destroy         # tpmr_p_dtor -> ifpromisc ->
aggr_p_ioctl -> panic

"ifconfig vether0" now shows it simultaneously as "trunk: trunkdev
aggr0" and as a tpmr0 port -- dual membership that should be impossible.

>Fix:

Make the three bridge-family port-add paths reject an interface that is
already a trunk(4)/aggr(4) port, mirroring aggr_add_port().

Index: sys/net/if_tpmr.c
===================================================================
@@ -519,6 +519,12 @@ tpmr_add_port(...)
  if (error != 0)
  goto put;

+ /* Reject a port already enslaved to a trunk(4)/aggr(4) */
+ if (SMR_PTR_GET_LOCKED(&((struct arpcom *)ifp0)->ac_trport) != NULL) {
+ error = EBUSY;
+ goto put;
+ }
+
  /* let's try */
@@ -551,6 +557,11 @@ tpmr_add_port(...)
  error = ether_brport_isset(ifp0);
  if (error != 0)
  goto unpromisc;
+
+ if (SMR_PTR_GET_LOCKED(&((struct arpcom *)ifp0)->ac_trport) != NULL) {
+ error = EBUSY;
+ goto unpromisc;
+ }

Index: sys/net/if_veb.c
===================================================================
@@ -1765,6 +1765,12 @@ veb_add_port(...)
  if (error != 0)
  goto put;

+ /* Reject a port already enslaved to a trunk(4)/aggr(4) */
+ if (SMR_PTR_GET_LOCKED(&((struct arpcom *)ifp0)->ac_trport) != NULL) {
+ error = EBUSY;
+ goto put;
+ }
+
  /* let's try */
@@ -1830,6 +1836,11 @@ veb_add_port(...)
  error = ether_brport_isset(ifp0);
  if (error != 0)
  goto unpromisc;
+
+ if (SMR_PTR_GET_LOCKED(&((struct arpcom *)ifp0)->ac_trport) != NULL) {
+ error = EBUSY;
+ goto unpromisc;
+ }

Index: sys/net/if_bridge.c
===================================================================
@@ -301,6 +301,13 @@ bridge_ioctl(... SIOCBRDGADD ...)
  break;
  }

+ /* Reject a port already enslaved to a trunk(4)/aggr(4) */
+ if (SMR_PTR_GET_LOCKED(&((struct arpcom *)ifs)->ac_trport) != NULL) {
+ if_put(ifs);
+ error = EBUSY;
+ break;
+ }
+
  /* If it's in the span list, it can't be a member. */

(bridge(4) does not stack the member's if_ioctl, so it is less likely
to hit the exact panic above, but it has the same acceptance gap and
the same fix keeps an aggr/trunk member out of a bridge for the same
reason aggr/trunk keep bridge members out.)

>Verification:

Built GENERIC.MP + WITNESS + DIAGNOSTIC from -current with all three
diffs applied and booted it (OpenBSD 8.0-current GENERIC.MP #7,
2026-11-04) on an isolated amd64 KVM guest.

- Before: "ifconfig tpmr0 add vether0" (vether0 an aggr port) succeeds;
 the How-To-Repeat teardown panics "ep != NULL" at if_aggr.c:1470.  A
 concurrent ifconfig fuzzer panics the stock kernel within ~30 s.
- After: every bridge-family x trunk/aggr combination is refused --
 tpmr/veb/bridge each reject both an aggr member and a trunk member
 with "Device busy" (EBUSY) -- and the fuzzer that reliably panicked
 now runs to completion with no "ep != NULL" panic.

 # ifconfig tpmr0 add vether0
 ifconfig: tpmr0: vether0: Device busy

Reply via email to