>Synopsis: vlan_set_parent() does not reject a parent that would create a
loop: the vlan itself ("ifconfig vlanN parent vlanN") or another
vlan whose parent chain leads back to it ("vlan100 parent vlan10;
vlan10 parent vlan100"). A vlan is IFT_ETHER, so both are
accepted. Thereafter SIOCGIFMEDIA on any vlan in the loop recurses
vlan_media_get() -> vlan_ioctl() -> vlan_media_get() without bound
and overflows the kernel stack. svlan(4) shares the driver and is
affected identically.
>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: 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, 2 vcpu)
if_vlan.c at $OpenBSD: if_vlan.c,v 1.224 2025/12/18 02:14:09 dlg Exp $.
>Description:
vlan(4) interfaces are ethernet-like (ether_ifattach() sets
if_type = IFT_ETHER), and a vlan may be stacked on another vlan.
vlan_set_parent() (sys/net/if_vlan.c) validates the proposed parent
only as follows:
ifp0 = if_unit(parent);
if (ifp0 == NULL) return (EINVAL);
if (ifp0->if_type != IFT_ETHER) { error = EPROTONOSUPPORT; goto put; }
if (sc->sc_ifidx0 == ifp0->if_index) { /* nop */ goto put; }
if (ISSET(ifp->if_flags, IFF_RUNNING)) { error = EBUSY; goto put; }
error = vlan_inuse(sc->sc_type, ifp0->if_index, sc->sc_tag);
...
sc->sc_ifidx0 = ifp0->if_index; /* commit */
A vlan is IFT_ETHER, so a vlan passes the type check. Nothing checks
whether the proposed parent is the vlan itself, or whether following
the parent's own parent chain leads back to it. (The only
self-related test, sc_ifidx0 == ifp0->if_index, means "parent
unchanged", not "parent is me".) So both of these are accepted:
vlanN parent vlanN (self, 1-cycle)
vlan100 parent vlan10; vlan10 parent vlan100 (2-cycle; and so on)
Once a loop exists, any media query recurses. vlan_ioctl()'s
SIOCGIFMEDIA case calls vlan_media_get():
case SIOCGIFMEDIA:
error = vlan_media_get(sc, ifr);
and vlan_media_get() forwards the same ioctl to the parent's if_ioctl:
ifp0 = if_get(sc->sc_ifidx0); /* next in loop */
error = (ifp0 == NULL) ? ENOTTY :
(*ifp0->if_ioctl)(ifp0, SIOCGIFMEDIA, ifr); /* == vlan_ioctl */
Every member of the loop is a vlan, so the forwarding never reaches a
real ethernet driver:
vlan_ioctl -> vlan_media_get -> vlan_ioctl -> vlan_media_get -> ...
recurses with no termination and overflows the kernel stack. Any
"ifconfig vlanN" issues SIOCGIFMEDIA, so merely displaying the
interface (or running a bare "ifconfig") is enough to trigger it.
Captured on a GENERIC.MP #125 kernel (pool_debug=1), "ifconfig
vlan100 parent vlan100; ifconfig vlan100" -- 162 recursion frames,
overflow onto the trap stack:
Xcalltrap_specstk_untramp() at Xcalltrap_specstk_untramp+0xf
kerntrap(...) at kerntrap+0x15d
vlan_media_get(...) at vlan_media_get+0x25
vlan_ioctl(...,c0406938,...) at vlan_ioctl+0x1c8
vlan_media_get(...) at vlan_media_get+0x52
vlan_ioctl(...,c0406938,...) at vlan_ioctl+0x1c8
... [repeats] ...
ifioctl(...,c0406938,...) at ifioctl+0xaa1
sys_ioctl(...) at sys_ioctl+0x30e
syscall(...) at syscall+0x60d
Xsyscall() at Xsyscall+0x128
(ioctl 0xc0406938 == SIOCGIFMEDIA.) The two-vlan loop gives the same
recursion, ending in "fatal double fault in supervisor mode" in
vlan_media_get(). Because the overflow fault is taken while the
SIOCGIFMEDIA path holds NET_LOCK, the subsequent reboot path
(boot() -> if_downall() -> rw_enter_write(netlock)) re-panics
"netlock rwlock: enter write deadlock" recursively, so with
ddb.panic=0 the machine hangs instead of rebooting.
The operation is available to root via ioctl(SIOCSIFPARENT) +
ioctl(SIOCGIFMEDIA); no special hardware is involved. svlan(4) uses
the same vlan_set_parent()/vlan_media_get() and is affected identically.
>How-To-Repeat:
I manually verified this
As root (vlan or svlan). Either sequence crashes the machine.
1. vlan as its own parent:
ifconfig vlan100 create
ifconfig vlan100 parent vlan100 # accepted; should be EINVAL
ifconfig vlan100 # SIOCGIFMEDIA -> stack overflow
2. Indirect loop through a second vlan:
ifconfig vlan100 create
ifconfig vlan10 create
ifconfig vlan100 parent vlan10 # fine: vlan-on-vlan is legal
ifconfig vlan10 parent vlan100 # closes the loop; should be EINVAL
ifconfig # SIOCGIFMEDIA -> stack overflow
Longer loops (vlanA -> vlanB -> vlanC -> vlanA) behave the same way.
>Fix:
allow nesting up to 64 times and anything after that assume it is a loop,
A check for "parent == self" only is not enough: a kernel with just
that check refuses case 1 but accepts case 2 and still double-faults
(see Verification).
Instead, vlan_set_parent() calls a new vlan_parent_loop(ifp, ifp0).
It starts at the proposed parent and follows the vlan parent chain
(identified by if_ioctl == vlan_ioctl, which vlan and svlan share).
It returns EINVAL if it reaches the vlan being configured, and stops
at the first non-vlan interface (the bottom of the stack).
Only interface identity is compared, never the vlan tag (vnetid).
So vlan-on-vlan and QinQ (svlan over vlan) stacks, including ones
where both layers use the same tag, are still allowed. The walk
holds references with if_ref()/if_get()/if_put(), and is capped at
64 hops in case a loop already exists.
Index: sys/net/if_vlan.c
===================================================================
RCS file: /cvs/src/sys/net/if_vlan.c,v
retrieving revision 1.224
diff -u -p -r1.224 if_vlan.c
--- sys/net/if_vlan.c 18 Dec 2025 02:14:09 -0000 1.224
+++ sys/net/if_vlan.c 4 Nov 2026 17:23:02 -0000
@@ -130,6 +130,7 @@
int vlan_set_vnetid(struct vlan_softc *, uint16_t);
int vlan_set_parent(struct vlan_softc *, const char *);
+int vlan_parent_loop(struct ifnet *, struct ifnet *);
int vlan_del_parent(struct vlan_softc *);
int vlan_inuse(uint16_t, unsigned int, uint16_t);
int vlan_inuse_locked(uint16_t, unsigned int, uint16_t);
@@ -918,7 +919,36 @@
return (error);
}
+/*
+ * 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 vlan parent chain
+ * from ifp0. The walk is bounded in case a loop already exists.
+ */
int
+vlan_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 != vlan_ioctl)
+ break;
+ next = if_get(((struct vlan_softc *)p->if_softc)->sc_ifidx0);
+ if_put(p);
+ p = next;
+ }
+ if_put(p);
+
+ return (loop);
+}
+
+int
vlan_set_parent(struct vlan_softc *sc, const char *parent)
{
struct ifnet *ifp = &sc->sc_if;
@@ -931,6 +961,12 @@
if (ifp0->if_type != IFT_ETHER) {
error = EPROTONOSUPPORT;
+ goto put;
+ }
+
+ if (vlan_parent_loop(ifp, ifp0)) {
+ /* a vlan cannot be (indirectly) its own parent */
+ error = EINVAL;
goto put;
}
>Verification:
Found by an interface-nesting fuzzer and verified on an isolated
amd64 KVM guest, one source tree, three kernels (GENERIC.MP with
DIAGNOSTIC and POOL_DEBUG, 2026-11-04):
#1 unpatched self-parent accepted; "ifconfig vlan100" overflows
the stack and hangs the machine.
#2 self-check self-parent refused, but the 2-vlan loop (case 2)
only is accepted, and "ifconfig vlan100" then gives
"fatal double fault in supervisor mode" in
vlan_media_get().
#3 this diff the loop-closing step is refused with
"SIOCSIFPARENT: Invalid argument" for: self, the
2-vlan loop, a 3-vlan loop, svlan self, and an
svlan in a loop. Media queries on all of them
succeed. A legitimate QinQ stack (svlan on vlan
on vether) comes up RUNNING with working media.
Teardown is clean, and there was no WITNESS or
DIAGNOSTIC output during the boot.