>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 (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)

>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:

Built GENERIC.MP from -current with the diff applied and booted it
(OpenBSD 8.0-current GENERIC.MP #1, 2026-11-04) on an isolated amd64
KVM guest.  On the stock #125 kernel the How-To-Repeat sequence wedges
"ifconfig rport100 destroy" permanently (DU, unkillable); on the patched
kernel:

   # ifconfig rport100 parent rport100
   ifconfig: rport100: rport100: SIOCSIFPARENT: Invalid argument
   # ifconfig rport100 destroy
   # ifconfig rport100
   rport100: no such interface

i.e. the self-parent is still refused with EINVAL, and destroy now
completes cleanly with no leaked reference and no hang.

Reply via email to