>Synopsis:      rport_set_parent() takes an interface reference with if_unit()
                but skips if_put() on the "parent == self" error path; the
                leaked reference makes a later SIOCIFDESTROY block forever in
                refcnt_finalize(), permanently wedging a kernel thread and the
                global rport lock (local denial of service, root).
>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_rport.c rev 1.13, openbsd/src as of 
2026-11-03, git d5b06e73

>Description:

        rport_set_parent() (sys/net/if_rport.c) resolves the requested parent
        with if_unit(), which returns a *referenced* ifnet:

            ifp0 = if_unit(p->ifp_parent);
            if (ifp0 == NULL) {
                    error = EINVAL;
                    goto leave;                 /* ok: no ref taken */
            }

            if (ifp0 == ifp) {
                    error = EINVAL;
                    goto leave;                 /* BUG: ref leaked */
            }

            ...
            put:
                    if_put(ifp0);               /* the release path */
            leave:
                    rw_exit(&rport_interfaces_lock);
                    return (error);

        Every other error branch below the if_unit() call uses "goto put", so
        if_put(ifp0) runs.  The self-parent branch ("ifp0 == ifp") instead uses
        "goto leave", which skips if_put() and leaks the reference that 
if_unit()
        just took on the interface itself.

        Because the leaked reference is on the rport's own ifnet, a subsequent
        "ifconfig rportN destroy" never completes: rport_clone_destroy() calls
        if_detach(), which blocks in refcnt_finalize() waiting for the ifnet
        reference count to drain to zero -- but that reference was leaked and
        will never be released.  The destroying thread is left unkillable in
        state DU (wchan "ifrm"); SIGKILL has no effect.  The 
rport_interfaces_lock
        is not involved in the hang itself, but any further rport configuration
        that takes that write lock then also blocks behind the dead thread.

        No panic or splassert is produced, so a ddb.panic=0 machine does NOT
        auto-reboot; only a hard reset recovers.

        The operations are available to any user with sufficient privilege to
        configure interfaces (root); no special hardware is involved.

>How-To-Repeat:

        As root:

            ifconfig rport100 create
            ifconfig rport100 parent rport100   # rejected EINVAL (ifconfig
                                                 # prints the warning but exits 
0)
            ifconfig rport100 destroy           # never returns; thread wedged 
in
                                                 # refcnt_finalize(), unkillable

>Fix:

        Make the self-parent branch release the reference like every other
        post-if_unit() error path: "goto put" instead of "goto leave".

Index: sys/net/if_rport.c
===================================================================
--- sys/net/if_rport.c
+++ sys/net/if_rport.c
@@ -354,7 +354,7 @@ rport_set_parent(struct rport_softc *sc,

        if (ifp0 == ifp) {
                error = EINVAL;
-               goto leave;
+               goto put;
        }

        if (ifp0->if_enqueue != rport_enqueue) {

        (The ifp0 == NULL branch correctly keeps "goto leave": there no
        reference was taken.)

>Verification:
        Diff applied as shown with patch -p0 to sys/net/if_rport.c r1.13
        (openbsd/src as of 2026-11-03), hunk applied with an offset of 2
        lines; kernel GENERIC.MP + WITNESS + DIAGNOSTIC, amd64, built without
        warnings.  Unpatched = the same tree without the diff, same config.
        How-To-Repeat run three times on each kernel; a wedge is "ifconfig
        rport100 destroy" still in state D on "ifrm" 10 seconds later:

          unpatched: 3/3 wedged (destroy in "ifrm", unkillable; reset needed).
          patched:   3/3 the self-parent was refused ("SIOCSIFPARENT: Invalid
                     argument") and the destroy completed ("rport100: no such
                     interface").  In the same runs a normal rport pair
                     (rport101 parent rport102) was configured and destroyed.

Reply via email to