On Wed, Nov 04, 2026 at 01:06:18AM +0000, Tom Smyth wrote:
> >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 (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_mpw.c at $OpenBSD: if_mpw.c,v 1.71 2026/02/05 03:26:00 dlg Exp $.
> 
> >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 in ddb on a
> GENERIC.MP (DIAGNOSTIC) kernel, "ifconfig mpw100 mplslabel 100; ifconfig
> mpw100 destroy":
> 
>    uvm_fault(..., 0x1, 0, 1) -> e
>    kernel: page fault trap, code=0
>    Stopped at rtable_clearsource+0x22: movzbl 0x1(%rsi),%esi
>    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(...) at ifioctl+0x1f5
>    sys_ioctl(...) at sys_ioctl+0x30
>    syscall(...) at syscall+0x60d
>    Xsyscall() at Xsyscall+0x128
> 
> (%rsi is the NULL src; offset 0x1 is sockaddr.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:
> 

I would prefer to keep `sc_ifa' initialization together. Does this diff
works to you?

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, i
        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, i
 
        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 */

Reply via email to