Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 8 Jun 2018 20:32:00 +0000 (UTC)
From:      Matt Macy <mmacy@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r334855 - head/sys/kern
Message-ID:  <201806082032.w58KW0Ie084689@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: mmacy
Date: Fri Jun  8 20:31:59 2018
New Revision: 334855
URL: https://svnweb.freebsd.org/changeset/base/334855

Log:
  AF_UNIX: bring uipc_ready in compliance with new locking protocol
  
  PR:	228742
  Submitted by: markj
  Reviewed by:	markj

Modified:
  head/sys/kern/uipc_usrreq.c

Modified: head/sys/kern/uipc_usrreq.c
==============================================================================
--- head/sys/kern/uipc_usrreq.c	Fri Jun  8 19:47:04 2018	(r334854)
+++ head/sys/kern/uipc_usrreq.c	Fri Jun  8 20:31:59 2018	(r334855)
@@ -1262,14 +1262,21 @@ uipc_ready(struct socket *so, struct mbuf *m, int coun
 
 	unp = sotounpcb(so);
 
-	UNP_LINK_RLOCK();
+	UNP_PCB_LOCK(unp);
 	if ((unp2 = unp->unp_conn) == NULL) {
-		UNP_LINK_RUNLOCK();
-		for (int i = 0; i < count; i++)
-			m = m_free(m);
-		return (ECONNRESET);
+		UNP_PCB_UNLOCK(unp);
+		goto error;
 	}
-	UNP_PCB_LOCK(unp2);
+	if (unp != unp2) {
+		if (UNP_PCB_TRYLOCK(unp2) == 0) {
+			unp_pcb_hold(unp2);
+			UNP_PCB_UNLOCK(unp);
+			UNP_PCB_LOCK(unp2);
+			if (unp_pcb_rele(unp2))
+				goto error;
+		} else
+			UNP_PCB_UNLOCK(unp);
+	}
 	so2 = unp2->unp_socket;
 
 	SOCKBUF_LOCK(&so2->so_rcv);
@@ -1279,9 +1286,12 @@ uipc_ready(struct socket *so, struct mbuf *m, int coun
 		SOCKBUF_UNLOCK(&so2->so_rcv);
 
 	UNP_PCB_UNLOCK(unp2);
-	UNP_LINK_RUNLOCK();
 
 	return (error);
+ error:
+	for (int i = 0; i < count; i++)
+		m = m_free(m);
+	return (ECONNRESET);
 }
 
 static int



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201806082032.w58KW0Ie084689>