>Synopsis: aggr_add_port() uses `>' instead of `>=' when enforcing
AGGR_MAX_PORTS (32), so a 33rd port is accepted.  aggr_get_trunk()
then reports ra_ports = 33 while copying out only 32 entries, and
ifconfig(8) trunk_status() loops to ra_ports and reads one element
past its 32-slot rpbuf[] (a stack over-read, printed as garbage).
>Category: kernel + ifconfig
>Severity: non-critical
>Priority: low
>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: Mon Nov  2
     04:56:12 CST 2026
     [email protected]:/usr/src/sys/arch/amd64/compile/GENERIC.MP
Architecture: OpenBSD.amd64
Machine     : amd64 (QEMU/KVM guest)

if_aggr.c at $OpenBSD: if_aggr.c,v 1.53 2025/12/02 03:50:56 dlg Exp $.

>Description:
if you add a 33rd interface when ifconfig aggr displays some other
values for the 33rd trunkport   over reading ..  I have validated this
manually myself
aggr(4) limits an aggregation to AGGR_MAX_PORTS ports:

   #define AGGR_PORT_BITS 5
   #define AGGR_MAX_PORTS (1 << AGGR_PORT_BITS) /* = 32 */

aggr_add_port() (sys/net/if_aggr.c) enforces the limit with:

   if (sc->sc_nports > AGGR_MAX_PORTS)
   return (ENOSPC);

Because the test is `>' and not `>=', the check passes when
sc_nports == 32 (its maximum legal value), and a 33rd port is added,
leaving sc_nports == 33.  trunk(4)'s trunk_port_create() uses the
correct `>=' against TRUNK_MAX_PORTS and is not affected.

The accepted 33rd port is also non-functional for transmit
distribution: aggr_map() rebuilds the active map with a fixed loop

   for (i = 0; i < nitems(map->m_ifp0s); i++) /* nitems == 32 */
   map->m_ifp0s[i] = p->p_ifp0;

so only 32 distributing ports are ever placed in the TX map
(round-robin); the array itself is not overflowed, so there is no
kernel memory corruption.  The visible fault is in userland: on a
SIOCGTRUNK, aggr_get_trunk() sets

   ra->ra_ports = sc->sc_nports; /* = 33 */

but copies out at most 32 trunk_reqport entries (it stops once the
caller's buffer is full).  ifconfig(8) trunk_status() reads the port
array into a fixed buffer

   struct trunk_reqport rpbuf[TRUNK_MAX_PORTS]; /* 32 */

and then loops `for (i = 0; i < ra.ra_ports; i++)' printing
rpbuf[i].rp_portname with %s.  With ra_ports == 33 the final iteration
dereferences rpbuf[32] -- one element past the end of the 32-slot
array -- so ifconfig prints an uninitialised stack trunk_reqport as a
bogus port line.  This is an out-of-bounds read in the ifconfig
process; the operation needs root (SIOCSTRUNKPORT), so the leaked
bytes are only exposed to root.

>How-To-Repeat:

As root, on a kernel without the fix below:

   ifconfig aggr0 create
   for i in $(jot 33 1); do
       ifconfig vether$i create
       ifconfig aggr0 trunkport vether$i
   done
   # the 33rd trunkport succeeds (should fail ENOSPC)
   ifconfig aggr0
   # trunk_status prints a 33rd "trunkport" line with a garbage name

On a fixed kernel the 33rd trunkport returns
"SIOCSTRUNKPORT: No space left on device" and ifconfig shows 32 ports.

>Fix:

Two parts.  (1) The kernel off-by-one -- change `>' to `>=' so the
limit is actually 32:

Index: sys/net/if_aggr.c
===================================================================
--- sys/net/if_aggr.c
+++ sys/net/if_aggr.c
@@ -1189,7 +1189,7 @@ aggr_add_port(struct aggr_softc *sc, con
  int error;

  NET_ASSERT_LOCKED();
- if (sc->sc_nports > AGGR_MAX_PORTS)
+ if (sc->sc_nports >= AGGR_MAX_PORTS)
  return (ENOSPC);

(2) Defence in depth in ifconfig(8): clamp the display loop to the
size of rpbuf[] so a kernel that ever reports ra_ports > nitems(rpbuf)
can never drive an over-read.  In sbin/ifconfig/ifconfig.c
trunk_status(), bound the loop with the buffer size, e.g.

   nports = ra.ra_ports;
   if (nports > (int)nitems(rpbuf))
   nports = nitems(rpbuf);
   for (i = 0; i < nports; i++)
   ... rpbuf[i] ...

With the kernel fix alone the over-read is already unreachable
(ra_ports can no longer exceed 32); the ifconfig clamp is belt-and-
suspenders and documents the invariant at the point of use.

>Verification:

The kernel fix was built into GENERIC.MP (DIAGNOSTIC) from -current and
booted (OpenBSD 8.0-current GENERIC.MP #4, 2026-11-04) on an isolated
amd64 KVM guest.  Before the fix the How-To-Repeat sequence accepts a
33rd port; after it:

   # ... 32 successful trunkport adds ...
   # ifconfig aggr0 trunkport vether33
   ifconfig: aggr0 vether33: SIOCSTRUNKPORT: No space left on device

i.e. exactly 32 ports are accepted, the 33rd is refused with ENOSPC,
and no panic occurs.  (The ifconfig clamp was not separately compiled
in this lab, which has only the kernel source tree available; it is a
trivial loop-bound change and the over-read it guards is unreachable
once the kernel caps the port count.)

Reply via email to