>Synopsis: bpe_set_parent() does not reject a parent that would create a
loop: the bpe itself ("ifconfig bpeN parent bpeN") or another
bpe
whose parent chain leads back to it ("bpe0 parent bpe1; bpe1
parent bpe0"). A bpe is IFT_ETHER, so both pass the only type
check. Thereafter SIOCGIFMEDIA on any bpe in the loop recurses
bpe_media_get() -> bpe_ioctl() -> bpe_media_get() without bound
and
overflows the kernel stack (fatal double fault). This is the
same
defect fixed in vlan(4)/svlan(4); bpe(4) is a separate driver
(if_bpe.c) and was not covered by that fix.
>Category: kernel
>Severity: serious
>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 as shipped: DIAGNOSTIC,
POOL_DEBUG)
Architecture: OpenBSD.amd64
Machine : amd64 (QEMU/KVM guest, 2 vcpu)
Source : sys/net/if_bpe.c rev 1.27, openbsd/src as of 2026-11-03,
git d5b06e73
>Description:
bpe_set_parent() (sys/net/if_bpe.c) resolves the requested parent and
rejects it only if it is not an Ethernet interface:
ifp0 = if_unit(p->ifp_parent);
if (ifp0 == NULL)
return (ENXIO);
if (ifp0->if_type != IFT_ETHER) {
error = ENXIO;
goto put;
}
if (ifp0->if_index == sc->sc_key.k_if)
goto put; /* only catches re-setting the
SAME parent, not self on first
configuration (k_if == 0) */
...
sc->sc_key.k_if = ifp0->if_index; /* commit */
A bpe(4) interface is itself IFT_ETHER, so naming a bpe as the parent
passes the type check, and the k_if guard only rejects re-setting the
parent a bpe already has -- not making a freshly created bpe its own
parent, nor a two-bpe cycle. bpe_media_get() then follows the parent:
ifp0 = if_get(sc->sc_key.k_if);
if (ifp0 != NULL)
error = (*ifp0->if_ioctl)(ifp0, SIOCGIFMEDIA, ...);
When the parent is the bpe itself (or another bpe that leads back to
it), ifp0->if_ioctl is bpe_ioctl, so SIOCGIFMEDIA calls bpe_media_get()
again, and so on until the kernel stack is exhausted:
fatal double fault in supervisor mode
trap type 13 ... cr2 <stack bottom> rsp <stack bottom + 1 page>
panic: trap type 13 ...
Xcalltrap_specstk_untramp()
(recursion through bpe_media_get <- bpe_ioctl <- ifioctl)
Any user who can configure interfaces (root) can wedge the machine
with two shipped commands. The same mistake in vlan(4) was fixed by
rejecting parent loops; bpe(4) has the identical media-ioctl recursion
but no such check.
>How-To-Repeat:
As root (bpe200, bpe201 unused):
1. ifconfig bpe200 create
2. ifconfig bpe200 parent bpe200
3. ifconfig bpe200
Step 2 should fail but succeeds; step 3 issues SIOCGIFMEDIA and the
kernel double-faults. The two-bpe cycle crashes the same way:
ifconfig bpe200 create; ifconfig bpe201 create
ifconfig bpe200 parent bpe201 vnetid 7
ifconfig bpe201 parent bpe200 vnetid 8 # closes the loop
ifconfig bpe201 # overflow
>Fix:
Reject a parent that is the bpe itself or that reaches the bpe by
following the bpe parent chain, exactly as vlan_set_parent() does.
The walk is bounded in case a loop already exists.
Index: sys/net/if_bpe.c
===================================================================
--- sys/net/if_bpe.c
+++ sys/net/if_bpe.c
@@ -98,6 +98,7 @@ static int bpe_multi(struct bpe_softc *, struct ifnet
static int bpe_set_vnetid(struct bpe_softc *, const struct ifreq *);
static void bpe_set_group(struct bpe_softc *, uint32_t);
static int bpe_set_parent(struct bpe_softc *, const struct if_parent *);
+static int bpe_parent_loop(struct ifnet *, struct ifnet *);
static int bpe_get_parent(struct bpe_softc *, struct if_parent *);
static int bpe_del_parent(struct bpe_softc *);
static int bpe_add_addr(struct bpe_softc *, const struct ifbareq *);
@@ -611,7 +612,36 @@ bpe_set_vnetid(struct bpe_softc *sc, const struct ifre
return (0);
}
+/*
+ * Return non-zero if making ifp0 the parent of ifp would create a loop,
+ * i.e. ifp is ifp0 or is reachable by following the bpe parent chain
+ * from ifp0. The walk is bounded in case a loop already exists.
+ */
static int
+bpe_parent_loop(struct ifnet *ifp, struct ifnet *ifp0)
+{
+ struct ifnet *p, *next;
+ unsigned int depth = 0;
+ int loop = 0;
+
+ p = if_ref(ifp0);
+ while (p != NULL) {
+ if (p == ifp || ++depth > 64) {
+ loop = 1;
+ break;
+ }
+ if (p->if_ioctl != bpe_ioctl)
+ break;
+ next = if_get(((struct bpe_softc *)p->if_softc)->sc_key.k_if);
+ if_put(p);
+ p = next;
+ }
+ if_put(p);
+
+ return (loop);
+}
+
+static int
bpe_set_parent(struct bpe_softc *sc, const struct if_parent *p)
{
struct ifnet *ifp = &sc->sc_ac.ac_if;
@@ -624,6 +654,12 @@ bpe_set_parent(struct bpe_softc *sc, const struct if_p
if (ifp0->if_type != IFT_ETHER) {
error = ENXIO;
+ goto put;
+ }
+
+ if (bpe_parent_loop(ifp, ifp0)) {
+ /* a bpe cannot be (indirectly) its own parent */
+ error = EINVAL;
goto put;
}
>Verification:
Diff applied as shown with patch -p0 to sys/net/if_bpe.c r1.27
(openbsd/src as of 2026-11-03, git d5b06e73), no fuzz or offset;
kernel GENERIC.MP, amd64, built without warnings. Unpatched = the
same tree without the diff, same config.
Unpatched (stock d5b06e73 GENERIC.MP, VM with 2 vcpu):
self-parent ("ifconfig bpe200 parent bpe200; ifconfig bpe200"):
3/3 fatal double fault in supervisor mode, cr2 at the bottom of
the kernel stack, pc ffffffff81b67b03, trace unwinding through
bpe_media_get <- bpe_ioctl <- ifioctl; the machine then hung in
the reboot path (NET_LOCK) and was reset.
two-bpe cycle ("bpe200 parent bpe201; bpe201 parent bpe200;
ifconfig bpe201"): same double fault, identical pc and cr2.
Patched (same tree + the diff):
self-parent and two-bpe cycle both refused 3/3 with
"SIOCSIFPARENT: Invalid argument"; the bpe keeps "parent none" (or
its previous parent), SIOCGIFMEDIA returns normally and the machine
stays up.
Normal use on the patched kernel, 3 runs, 15/15 checks each:
a bpe on a vether(4) parent with a vnetid configures and shows
"encap: vnetid N parent vether200", SIOCGIFMEDIA returns, up/down
work, a legal two-deep stack (bpe201 on bpe200 on vether200) is
accepted ("parent bpe200"), and all interfaces tear down cleanly.
The same legal parent / media / two-deep-stack paths behave
identically on the unpatched kernel.