Do soreserve() before `kp' allocation. This simplifies error path. The
authormvs <mvs@openbsd.org>
Sun, 2 May 2021 14:22:05 +0000 (14:22 +0000)
committermvs <mvs@openbsd.org>
Sun, 2 May 2021 14:22:05 +0000 (14:22 +0000)
same was done for route_attach().

Also do soisconnected() after `kp' is fully initialized. This chair
movement affects nothing for PF_KEY sockets but makes code more
consistent.

ok bluhm@ mpi@

sys/net/pfkeyv2.c

index a757bf0..e03c899 100644 (file)
@@ -1,4 +1,4 @@
-/* $OpenBSD: pfkeyv2.c,v 1.208 2020/12/14 20:20:06 tobhe Exp $ */
+/* $OpenBSD: pfkeyv2.c,v 1.209 2021/05/02 14:22:05 mvs Exp $ */
 
 /*
  *     @(#)COPYRIGHT   1.1 (NRL) 17 January 1995
@@ -269,24 +269,20 @@ pfkeyv2_attach(struct socket *so, int proto)
        if ((so->so_state & SS_PRIV) == 0)
                return EACCES;
 
-       kp = pool_get(&pkpcb_pool, PR_WAITOK|PR_ZERO);
-       so->so_pcb = kp;
-       refcnt_init(&kp->kcb_refcnt);
-
        error = soreserve(so, PFKEYSNDQ, PFKEYRCVQ);
-       if (error) {
-               pool_put(&pkpcb_pool, kp);
+       if (error)
                return (error);
-       }
 
+       kp = pool_get(&pkpcb_pool, PR_WAITOK|PR_ZERO);
+       so->so_pcb = kp;
+       refcnt_init(&kp->kcb_refcnt);
        kp->kcb_socket = so;
+       kp->kcb_pid = curproc->p_p->ps_pid;
+       kp->kcb_rdomain = rtable_l2(curproc->p_p->ps_rtableid);
 
        so->so_options |= SO_USELOOPBACK;
        soisconnected(so);
 
-       kp->kcb_pid = curproc->p_p->ps_pid;
-       kp->kcb_rdomain = rtable_l2(curproc->p_p->ps_rtableid);
-
        rw_enter(&pkptable.pkp_lk, RW_WRITE);
        SRPL_INSERT_HEAD_LOCKED(&pkptable.pkp_rc, &pkptable.pkp_list, kp, kcb_list);
        rw_exit(&pkptable.pkp_lk);