Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 22 Jan 2020 06:10:41 +0000 (UTC)
From:      Gleb Smirnoff <glebius@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r356983 - head/sys/netinet
Message-ID:  <202001220610.00M6AfiD034933@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: glebius
Date: Wed Jan 22 06:10:41 2020
New Revision: 356983
URL: https://svnweb.freebsd.org/changeset/base/356983

Log:
  Make in_pcbladdr() require network epoch entered by its callers.  Together
  with this widen network epoch coverage up to tcp_connect() and udp_connect().
  
  Revisions from r356974 and up to this revision cover D23187.
  
  Differential Revision:	https://reviews.freebsd.org/D23187

Modified:
  head/sys/netinet/in_pcb.c
  head/sys/netinet/raw_ip.c
  head/sys/netinet/tcp_usrreq.c
  head/sys/netinet/udp_usrreq.c

Modified: head/sys/netinet/in_pcb.c
==============================================================================
--- head/sys/netinet/in_pcb.c	Wed Jan 22 06:07:27 2020	(r356982)
+++ head/sys/netinet/in_pcb.c	Wed Jan 22 06:10:41 2020	(r356983)
@@ -1028,9 +1028,9 @@ in_pcbladdr(struct inpcb *inp, struct in_addr *faddr, 
 	struct sockaddr *sa;
 	struct sockaddr_in *sin;
 	struct route sro;
-	struct epoch_tracker et;
 	int error;
 
+	NET_EPOCH_ASSERT();
 	KASSERT(laddr != NULL, ("%s: laddr NULL", __func__));
 	/*
 	 * Bypass source address selection and use the primary jail IP
@@ -1064,7 +1064,6 @@ in_pcbladdr(struct inpcb *inp, struct in_addr *faddr, 
 	 * network and try to find a corresponding interface to take
 	 * the source address from.
 	 */
-	NET_EPOCH_ENTER(et);
 	if (sro.ro_rt == NULL || sro.ro_rt->rt_ifp == NULL) {
 		struct in_ifaddr *ia;
 		struct ifnet *ifp;
@@ -1228,7 +1227,6 @@ in_pcbladdr(struct inpcb *inp, struct in_addr *faddr, 
 	}
 
 done:
-	NET_EPOCH_EXIT(et);
 	if (sro.ro_rt != NULL)
 		RTFREE(sro.ro_rt);
 	return (error);
@@ -1266,6 +1264,7 @@ in_pcbconnect_setup(struct inpcb *inp, struct sockaddr
 	 * Because a global state change doesn't actually occur here, a read
 	 * lock is sufficient.
 	 */
+	NET_EPOCH_ASSERT();
 	INP_LOCK_ASSERT(inp);
 	INP_HASH_LOCK_ASSERT(inp->inp_pcbinfo);
 

Modified: head/sys/netinet/raw_ip.c
==============================================================================
--- head/sys/netinet/raw_ip.c	Wed Jan 22 06:07:27 2020	(r356982)
+++ head/sys/netinet/raw_ip.c	Wed Jan 22 06:10:41 2020	(r356983)
@@ -491,8 +491,10 @@ rip_output(struct mbuf *m, struct socket *so, ...)
 			 * want to see from jails.
 			 */
 			if (ip->ip_src.s_addr == INADDR_ANY) {
-				error = in_pcbladdr(inp, &ip->ip_dst, &ip->ip_src,
-				    inp->inp_cred);
+				NET_EPOCH_ENTER(et);
+				error = in_pcbladdr(inp, &ip->ip_dst,
+				    &ip->ip_src, inp->inp_cred);
+				NET_EPOCH_EXIT(et);
 			} else {
 				error = prison_local_ip4(inp->inp_cred,
 				    &ip->ip_src);

Modified: head/sys/netinet/tcp_usrreq.c
==============================================================================
--- head/sys/netinet/tcp_usrreq.c	Wed Jan 22 06:07:27 2020	(r356982)
+++ head/sys/netinet/tcp_usrreq.c	Wed Jan 22 06:10:41 2020	(r356983)
@@ -557,17 +557,18 @@ tcp_usr_connect(struct socket *so, struct sockaddr *na
 	}
 	tp = intotcpcb(inp);
 	TCPDEBUG1();
+	NET_EPOCH_ENTER(et);
 	if ((error = tcp_connect(tp, nam, td)) != 0)
-		goto out;
+		goto out_in_epoch;
 #ifdef TCP_OFFLOAD
 	if (registered_toedevs > 0 &&
 	    (so->so_options & SO_NO_OFFLOAD) == 0 &&
 	    (error = tcp_offload_connect(so, nam)) == 0)
-		goto out;
+		goto out_in_epoch;
 #endif
 	tcp_timer_activate(tp, TT_KEEP, TP_KEEPINIT(tp));
-	NET_EPOCH_ENTER(et);
 	error = tp->t_fb->tfb_tcp_output(tp);
+out_in_epoch:
 	NET_EPOCH_EXIT(et);
 out:
 	TCPDEBUG2(PRU_CONNECT);
@@ -644,18 +645,17 @@ tcp6_usr_connect(struct socket *so, struct sockaddr *n
 			goto out;
 		inp->inp_vflag |= INP_IPV4;
 		inp->inp_vflag &= ~INP_IPV6;
+		NET_EPOCH_ENTER(et);
 		if ((error = tcp_connect(tp, (struct sockaddr *)&sin, td)) != 0)
-			goto out;
+			goto out_in_epoch;
 #ifdef TCP_OFFLOAD
 		if (registered_toedevs > 0 &&
 		    (so->so_options & SO_NO_OFFLOAD) == 0 &&
 		    (error = tcp_offload_connect(so, nam)) == 0)
-			goto out;
+			goto out_in_epoch;
 #endif
-		NET_EPOCH_ENTER(et);
 		error = tp->t_fb->tfb_tcp_output(tp);
-		NET_EPOCH_EXIT(et);
-		goto out;
+		goto out_in_epoch;
 	} else {
 		if ((inp->inp_vflag & INP_IPV6) == 0) {
 			error = EAFNOSUPPORT;
@@ -679,6 +679,7 @@ tcp6_usr_connect(struct socket *so, struct sockaddr *n
 	tcp_timer_activate(tp, TT_KEEP, TP_KEEPINIT(tp));
 	NET_EPOCH_ENTER(et);
 	error = tp->t_fb->tfb_tcp_output(tp);
+out_in_epoch:
 	NET_EPOCH_EXIT(et);
 out:
 	/*
@@ -1468,6 +1469,7 @@ tcp_connect(struct tcpcb *tp, struct sockaddr *nam, st
 	u_short lport;
 	int error;
 
+	NET_EPOCH_ASSERT();
 	INP_WLOCK_ASSERT(inp);
 	INP_HASH_WLOCK(&V_tcbinfo);
 

Modified: head/sys/netinet/udp_usrreq.c
==============================================================================
--- head/sys/netinet/udp_usrreq.c	Wed Jan 22 06:07:27 2020	(r356982)
+++ head/sys/netinet/udp_usrreq.c	Wed Jan 22 06:10:41 2020	(r356983)
@@ -1606,6 +1606,7 @@ udp_close(struct socket *so)
 static int
 udp_connect(struct socket *so, struct sockaddr *nam, struct thread *td)
 {
+	struct epoch_tracker et;
 	struct inpcb *inp;
 	struct inpcbinfo *pcbinfo;
 	struct sockaddr_in *sin;
@@ -1625,9 +1626,11 @@ udp_connect(struct socket *so, struct sockaddr *nam, s
 		INP_WUNLOCK(inp);
 		return (error);
 	}
+	NET_EPOCH_ENTER(et);
 	INP_HASH_WLOCK(pcbinfo);
 	error = in_pcbconnect(inp, nam, td->td_ucred);
 	INP_HASH_WUNLOCK(pcbinfo);
+	NET_EPOCH_EXIT(et);
 	if (error == 0)
 		soisconnected(so);
 	INP_WUNLOCK(inp);



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