On 2026/11/05 07:18, Tom Smyth wrote:
> allow nesting up to 64 times and anything after that assume it is a loop,
this seems reasonable. perhaps a bit of a contrived situation but I
reckon you could typo this if configuring things under adverse
conditions.
> 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.
the cap makes sense but I don't get the mention of "if a loop already
exists", it's not like you're going to switch the kernel out without
reconfiguring interfaces, at which point they'll be checked, so I don't
see how a loop _can_ exist.
> 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
diff is mangled, copying direct from a terminal won't work. redirect to
a file and include that via your editor, or maybe 'cvs diff | xclip' and
paste. if you're using webmail you may need to switch to a different
client or maybe include as an attachment (though attachments aren't the
preferred option for tech@, inline is preferred if it works).
> --- 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.
>