>Synopsis:      nd6_rtrequest() joins the solicited-node group for a
                proxy (RTF_ANNOUNCE) entry only if the address is not
                configured on the interface, but always leaves it when
                the entry is deleted.  A proxy entry for one of the
                interface's own addresses therefore drops the reference
                that belongs to the address: the group is left and its
                in6_multi freed while the address still points to it,
                and deleting the address later panics (refcnt_rele()
                underflow or "Data modified on freelist").
>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/netinet6/nd6.c rev 1.305, openbsd/src as of
                      2026-11-03, git d5b06e73

>Description:

        Prerequisite: on an unpatched kernel every deletion of a proxy
        NDP entry already panics with "maddr rwlock: lock not held",
        because nd6_rtrequest() calls in6_lookupmulti() without
        ifp->if_maddrlock.  That is a separate bug with its own fix
        (rw_enter_read()/rw_exit_read() around the in6_lookupmulti() in
        the RTM_DELETE case, nd6.c:918).  Everything below was seen on
        a kernel with that fix applied.

        For RTM_ADD, nd6_rtrequest() looks up whether the key of the
        new entry is one of the interface's own addresses
        (nd6.c:855-857) and joins the solicited-node group for a proxy
        entry only if it is not (nd6.c:865-882):

            /* join solicited node multicast for proxy ND */
            if (ifa == NULL &&
                (rt->rt_flags & RTF_ANNOUNCE) &&
                (ifp->if_flags & IFF_MULTICAST)) {
                    ...
                    in6_addmulti(&llsol, ifp, &error);
            }

        For RTM_DELETE it leaves the group for every proxy entry, without
        that condition (nd6.c:904-921):

            /* leave from solicited node multicast for proxy ND */
            if ((rt->rt_flags & RTF_ANNOUNCE) != 0 &&
                (ifp->if_flags & IFF_MULTICAST) != 0) {
                    ...
                    in6m = in6_lookupmulti(&llsol, ifp);
                    if (in6m)
                            in6_delmulti(in6m);
            }

        A proxy entry for an address that is configured on the interface
        can be added: "ndp -s addr lladdr proxy" adds a static route with
        priority 8 next to the local route of the address (priority 1),
        and rtable_insert() only refuses an exact duplicate at the same
        priority.  The address itself holds one reference on its
        solicited-node group (in6_joingroup() in in6_update_ifa(),
        in6.c:765), and the proxy entry takes none.  Deleting the proxy
        entry finds that group and calls in6_delmulti() on it: the last
        reference is gone, the group is left (SIOCDELMULTI, MLD done)
        and the in6_multi is freed while ia6_memberships of the address
        still points to it.  Neighbor solicitations for the address are
        no longer received ("multicast packets which we don't join" in
        netstat -s -p ip6 goes up, a neighbor that has to resolve the
        address can not reach it).

        When the address is deleted, in6_purgeaddr() (in6.c:911-914)
        calls in6_leavegroup() and in6_delmulti() on the freed in6_multi
        again.  With DIAGNOSTIC this ends in either

            panic: kernel diagnostic assertion "refs != ~0" failed: file
                "/usr/src-n6P/sys/kern/kern_synch.c", line 934
            panic(ffffffff826cf436) at panic+0x170
            __assert(ffffffff8270bfec,ffffffff826ef08e,
                3a6,ffffffff827468bd) at __assert+0x29
            refcnt_rele(ffff800000df9618) at refcnt_rele+0xc4
            in6_delmulti(ffff800000df9600) at in6_delmulti+0x30
            in6_purgeaddr(ffff800000dfa600) at in6_purgeaddr+0xe5

        or, when the decrement went into freed memory, at the next
        allocation from the same malloc bucket:

            panic: Data modified on freelist: word 6 of object
                0xffff800000e02b00 size 0x80 previous type in_multi
                (0xdead410f != 0xdead4110)
            panic(ffffffff8269337a) at panic+0x170
            malloc(80,62,a) at malloc+0x859
            amap_alloc1(7fe,2,1) at amap_alloc1+0x17f

        (word 6 is the reference count of struct in6_multi; it was
        decremented by one after the free).

>How-To-Repeat:

        As root, on a kernel with the if_maddrlock fix mentioned above:

        1. ifconfig pair100 create rdomain 100
        2. ifconfig pair100 lladdr 02:00:00:00:01:00
        3. ifconfig pair100 inet6 2001:db8:1::1/64 up
        4. ndp -V 100 -s 2001:db8:1::1 02:00:00:00:01:00 proxy
        5. route -T 100 delete -inet6 -host 2001:db8:1::1 -priority 8
        6. ifconfig pair100 inet6 2001:db8:1::1 delete

        Step 4 adds the proxy entry next to the local one ("ndp -d" does
        not remove it, so step 5 removes the proxy entry by its
        priority).  After step 5 "vmstat -m" shows one in_multi less.
        Step 6 panics, or the next allocation from the same bucket does.

>Fix:
        This Fix assumes the previous bug "nd6: removing a proxy 
        NDP entry panics "maddr rwlock: lock not held" has already been  
        addressed.
        Take the reference for every proxy entry, also when the address
        is one of ours, so that the unconditional leave on RTM_DELETE
        drops the reference the entry took.  Joining a group that the
        address has joined already only increments its reference count.

Index: sys/netinet6/nd6.c
===================================================================
RCS file: /cvs/src/sys/netinet6/nd6.c,v
diff -u -p -r1.305 nd6.c
--- sys/netinet6/nd6.c  27 Nov 2025 21:54:28 -0000      1.305
+++ sys/netinet6/nd6.c  6 Nov 2026 08:50:00 -0000
@@ -862,9 +862,11 @@ nd6_rtrequest(struct ifnet *ifp, int req
                }
                mtx_leave(&nd6_mtx);
 
-               /* join solicited node multicast for proxy ND */
-               if (ifa == NULL &&
-                   (rt->rt_flags & RTF_ANNOUNCE) &&
+               /*
+                * join solicited node multicast for proxy ND, also for
+                * one of our addresses, as RTM_DELETE always leaves
+                */
+               if ((rt->rt_flags & RTF_ANNOUNCE) &&
                    (ifp->if_flags & IFF_MULTICAST)) {
                        struct in6_addr llsol;
                        int error;

>Verification:

        The diff above (md5 1a2fd9359a1096d4cc29880e4b19b1f6, sha256
        a83174259a201c82a2a86e2a826057fc7cbd1d21631bb9110fbddab46ace0a3b)
        applies with patch -p0 -F0 to sys/netinet6/nd6.c rev 1.305 (git
        d5b06e73) on its own (hunk at 862) and before or after the
        if_maddrlock fix, both orders giving the same nd6.c, with no
        offset or fuzz.  Unpatched kernel: a fresh export of the
        2026-11-03 tree with only the if_maddrlock fix applied; patched
        kernel: the same plus the diff above.  Both trees were checked
        file by file against the git tree (they differ from it only in
        nd6.c).  Kernels: GENERIC.MP + "option WITNESS" (DIAGNOSTIC comes
        from GENERIC), amd64, built without warnings; 2-vcpu guest.  Each
        run below was on a freshly booted kernel.

        How-To-Repeat, steps 1-6 exactly as listed (followed by adding
        another address and destroying pair100):
          unpatched   3/3 runs panic "Data modified on freelist: word 6
                      ... previous type in_multi"; three earlier runs of
                      the same steps with extra "vmstat -m" output gave
                      the refcnt_rele() assertion once and the freelist
                      panic twice, with in_multi InUse one lower after
                      step 5 each time
          patched     3/3 runs without any kernel message

        Normal use on the patched kernel (fresh boot each, 3/3 runs, 10
        checks each, all passed): two pair(4) interfaces in rdomains 100
        and 101; the peer reaches the address on pair100; a proxy entry
        for a foreign address (2001:db8:1::5) is listed with the "p" flag
        and the peer resolves that address to pair100's lladdr; "ndp -d"
        removes it and the peer no longer resolves it; a proxy entry for
        pair100's own address is added and removed again (by priority),
        and the peer still reaches the address afterwards; a second
        address works and both addresses are deleted; after destroying
        the interfaces "vmstat -m" shows the same in_multi InUse as
        before; no kernel messages.

Reply via email to