>Synopsis:      mpw_clone_create() sets sc_ifa.ifa_addr = sdltosa(ifp->if_sadl)
                before ether_ifattach() has allocated if_sadl, so ifa_addr is
                left NULL.  Removing a configured MPLS label (via destroy or
                -mplslabel) calls rt_ifa_del(), which dereferences ifa->ifa_addr
                in rtable_clearsource() and page-faults.  mpe(4)/mpip(4) set
                ifa_addr after if_alloc_sadl() and are not affected.
>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), WITNESS + DIAGNOSTIC
        Architecture: OpenBSD.amd64
        Machine     : amd64 (QEMU/KVM guest, 2 vcpu)
        Source      : sys/net/if_mpw.c rev 1.71, openbsd/src as of 2026-11-03, 
git d5b06e73

>Description:

        mpw(4) is an Ethernet pseudo-interface: mpw_clone_create() calls
        ether_ifattach(), which (via if_alloc_sadl()) allocates ifp->if_sadl.
        But the embedded MPLS interface address is initialised earlier in the
        same function, before ether_ifattach():

            sc->sc_ifa.ifa_ifp  = ifp;
            sc->sc_ifa.ifa_addr = sdltosa(ifp->if_sadl);   /* if_sadl == NULL 
here */
            ...
            ether_fakeaddr(ifp);
            ...
            ether_ifattach(ifp);                            /* if_sadl 
allocated now */

        The softc is M_ZERO-allocated, so at the assignment ifp->if_sadl is 
still
        NULL and sc_ifa.ifa_addr is set to NULL permanently.

        mpe(4) and mpip(4) perform the identical setup but in the correct order 
--
        if_attach(); if_alloc_sadl(); then sc_ifa.ifa_addr = 
sdltosa(ifp->if_sadl)
        -- so their ifa_addr is valid.  That is why they are unaffected.

        Setting a label ("ifconfig mpwN mplslabel <n>" -> mpw_set_route() ->
        rt_ifa_add()) does not fault.  Removing it does.  Both removal paths 
call
        rt_ifa_del(&sc->sc_ifa, ...) (sys/net/route.c), which unconditionally 
does:

            rtable_clearsource(rdomain, ifa->ifa_addr);     /* route.c:1340 */

        and rtable_clearsource() immediately dereferences the source sockaddr:

            addr = rtable_getsource(rtableid, src->sa_family);   /* 
rtable.c:422 */

        With ifa_addr == NULL this is a NULL dereference.  Captured on
        GENERIC.MP with WITNESS and DIAGNOSTIC, "ifconfig mpw100 create;
        ifconfig mpw100 mplslabel 100; ifconfig mpw100 destroy":

            uvm_fault(0xffffef81540d35e0, 0x1, 0, 1) -> e
            fatal page fault in supervisor mode
            trap type 6 code 0 rip ffffffff81670732 cs 8 rflags 10282 cr2 1
            panic: trap type 6, code=0, pc=ffffffff81670732
            rtable_clearsource(0,0) at rtable_clearsource+0x22
            rt_ifa_del(...) at rt_ifa_del+0x25e
            mpw_clone_destroy(...) at mpw_clone_destroy+0x73
            if_clone_destroy(...) at if_clone_destroy+0x13f
            ifioctl(...,80206979,...) at ifioctl+0x1f5
            sys_ioctl(...) at sys_ioctl+0x30e
            syscall(...) at syscall+0x60d
            Xsyscall() at Xsyscall+0x128

        The fault is taken with NET_LOCK held, so the ddb.panic=0 reboot
        path cannot take NET_LOCK again and the machine hangs instead of
        rebooting.

        (cr2 1 is offset 1 of a NULL sockaddr, i.e. sa_family.)  The
        -mplslabel path (SIOCDELLABEL -> mpw_del_label() -> rt_ifa_del()) faults
        the same way.

        The operations are available to root via ioctl(SIOCSETLABEL /
        SIOCDELLABEL / SIOCIFDESTROY); no special hardware is involved.

>How-To-Repeat:

        As root, either of:

            ifconfig mpw100 create
            ifconfig mpw100 mplslabel 100
            ifconfig mpw100 destroy          # page fault, 
rtable_clearsource+0x22

            ifconfig mpw101 create
            ifconfig mpw101 mplslabel 101
            ifconfig mpw101 -mplslabel       # same fault via mpw_del_label()

        Setting the label and leaving it in place does not crash.

>Fix:

        Move the whole sc_ifa initialisation to after ether_ifattach() has
        allocated if_sadl, matching mpe(4)/mpip(4) and keeping the three
        sc_ifa assignments together.  The diff is against if_mpw.c r1.71.

Index: sys/net/if_mpw.c
===================================================================
RCS file: /cvs/src/sys/net/if_mpw.c,v
retrieving revision 1.71
diff -u -p -r1.71 if_mpw.c
--- sys/net/if_mpw.c    5 Feb 2026 03:26:00 -0000       1.71
+++ sys/net/if_mpw.c    4 Nov 2026 09:29:47 -0000
@@ -97,9 +97,6 @@ mpw_clone_create(struct if_clone *ifc, int unit)
        sc->sc_txhprio = 0;
        sc->sc_rxhprio = IF_HDRPRIO_PACKET;
        sc->sc_rdomain = 0;
-       refcnt_init_trace(&sc->sc_ifa.ifa_refcnt, DT_REFCNT_IDX_IFADDR);
-       sc->sc_ifa.ifa_ifp = ifp;
-       sc->sc_ifa.ifa_addr = sdltosa(ifp->if_sadl);
        sc->sc_smpls.smpls_len = sizeof(sc->sc_smpls);
        sc->sc_smpls.smpls_family = AF_MPLS;
 
@@ -117,6 +114,11 @@ mpw_clone_create(struct if_clone *ifc, int unit)
 
        ether_ifattach(ifp);
        ifp->if_input = mpw_input;
+
+       /* ether_ifattach did if_sadl allocation */
+       refcnt_init_trace(&sc->sc_ifa.ifa_refcnt, DT_REFCNT_IDX_IFADDR);
+       sc->sc_ifa.ifa_ifp = ifp;
+       sc->sc_ifa.ifa_addr = sdltosa(ifp->if_sadl);
 
 #if NBPFILTER > 0
        bpfdetach(ifp); /* undo bpfattach in ether_ifattach */

>Verification:
        Diff applied as shown with patch -p0 to the revisions listed under
        Environment (openbsd/src as of 2026-11-03), no fuzz or offset;
        kernel GENERIC.MP + WITNESS + DIAGNOSTIC, amd64, built without
        warnings.  Unpatched = the same tree without the diff, same config.
        Both How-To-Repeat sequences run three times on each kernel:

          unpatched: destroy-with-label 3/3 and -mplslabel 3/3: page fault
                     in rtable_clearsource+0x22 (cr2 1), machine hung
                     (NET_LOCK held), reset needed.
          patched:   3/3 and 3/3 no fault.  In the same runs a label was set,
                     changed, removed, set again and the interface destroyed;
                     the local MPLS route showed the interface's link-layer
                     address as gateway (e.g. "103 - POP fe:e1:ba:d1:18:5a").

Reply via email to