When unp_connect() releases both solock() and vnode(9) locks the socket we
authormvs <mvs@openbsd.org>
Wed, 17 Nov 2021 22:56:19 +0000 (22:56 +0000)
committermvs <mvs@openbsd.org>
Wed, 17 Nov 2021 22:56:19 +0000 (22:56 +0000)
were connected could be closed by concurrent thread. Check connection
state and return ECONNREFUSED if the connection was lost.

ok bluhm@

sys/kern/uipc_usrreq.c

index 2db67d7..1c0a445 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: uipc_usrreq.c,v 1.157 2021/11/16 08:56:19 mvs Exp $   */
+/*     $OpenBSD: uipc_usrreq.c,v 1.158 2021/11/17 22:56:19 mvs Exp $   */
 /*     $NetBSD: uipc_usrreq.c,v 1.18 1996/02/09 19:00:50 christos Exp $        */
 
 /*
@@ -716,6 +716,13 @@ unlock:
        solock(so);
        unp->unp_flags &= ~UNP_CONNECTING;
 
+       /*
+        * The peer socket could be closed by concurrent thread
+        * when `so' and `vp' are unlocked.
+        */
+       if (error == 0 && unp->unp_conn == NULL)
+               error = ECONNREFUSED;
+
        return (error);
 }