svn commit: r334876 - head/sys/netpfil/pf

Kristof Provost kp at FreeBSD.org
Sat Jun 9 17:15:53 UTC 2018


Author: kp
Date: Sat Jun  9 14:17:06 2018
New Revision: 334876
URL: https://svnweb.freebsd.org/changeset/base/334876

Log:
  pf: Fix deadlock with route-to
  
  If a locally generated packet is routed (with route-to/reply-to/dup-to) out of
  a different interface it's passed through the firewall again. This meant we
  lost the inp pointer and if we required the pointer (e.g. for user ID matching)
  we'd deadlock trying to acquire an inp lock we've already got.
  
  Pass the inp pointer along with pf_route()/pf_route6().
  
  PR:		228782
  MFC after:	1 week

Modified:
  head/sys/netpfil/pf/pf.c

Modified: head/sys/netpfil/pf/pf.c
==============================================================================
--- head/sys/netpfil/pf/pf.c	Sat Jun  9 09:57:14 2018	(r334875)
+++ head/sys/netpfil/pf/pf.c	Sat Jun  9 14:17:06 2018	(r334876)
@@ -295,14 +295,14 @@ static void		 pf_mtag_free(struct m_tag *);
 #ifdef INET
 static void		 pf_route(struct mbuf **, struct pf_rule *, int,
 			    struct ifnet *, struct pf_state *,
-			    struct pf_pdesc *);
+			    struct pf_pdesc *, struct inpcb *);
 #endif /* INET */
 #ifdef INET6
 static void		 pf_change_a6(struct pf_addr *, u_int16_t *,
 			    struct pf_addr *, u_int8_t);
 static void		 pf_route6(struct mbuf **, struct pf_rule *, int,
 			    struct ifnet *, struct pf_state *,
-			    struct pf_pdesc *);
+			    struct pf_pdesc *, struct inpcb *);
 #endif /* INET6 */
 
 int in4_cksum(struct mbuf *m, u_int8_t nxt, int off, int len);
@@ -5442,7 +5442,7 @@ pf_routable(struct pf_addr *addr, sa_family_t af, stru
 #ifdef INET
 static void
 pf_route(struct mbuf **m, struct pf_rule *r, int dir, struct ifnet *oifp,
-    struct pf_state *s, struct pf_pdesc *pd)
+    struct pf_state *s, struct pf_pdesc *pd, struct inpcb *inp)
 {
 	struct mbuf		*m0, *m1;
 	struct sockaddr_in	dst;
@@ -5510,7 +5510,7 @@ pf_route(struct mbuf **m, struct pf_rule *r, int dir, 
 		goto bad;
 
 	if (oifp != ifp) {
-		if (pf_test(PF_OUT, 0, ifp, &m0, NULL) != PF_PASS)
+		if (pf_test(PF_OUT, 0, ifp, &m0, inp) != PF_PASS)
 			goto bad;
 		else if (m0 == NULL)
 			goto done;
@@ -5603,7 +5603,7 @@ bad:
 #ifdef INET6
 static void
 pf_route6(struct mbuf **m, struct pf_rule *r, int dir, struct ifnet *oifp,
-    struct pf_state *s, struct pf_pdesc *pd)
+    struct pf_state *s, struct pf_pdesc *pd, struct inpcb *inp)
 {
 	struct mbuf		*m0;
 	struct sockaddr_in6	dst;
@@ -5672,7 +5672,7 @@ pf_route6(struct mbuf **m, struct pf_rule *r, int dir,
 		goto bad;
 
 	if (oifp != ifp) {
-		if (pf_test6(PF_OUT, PFIL_FWD, ifp, &m0, NULL) != PF_PASS)
+		if (pf_test6(PF_OUT, PFIL_FWD, ifp, &m0, inp) != PF_PASS)
 			goto bad;
 		else if (m0 == NULL)
 			goto done;
@@ -6236,7 +6236,7 @@ done:
 	default:
 		/* pf_route() returns unlocked. */
 		if (r->rt) {
-			pf_route(m0, r, dir, kif->pfik_ifp, s, &pd);
+			pf_route(m0, r, dir, kif->pfik_ifp, s, &pd, inp);
 			return (action);
 		}
 		break;
@@ -6633,7 +6633,7 @@ done:
 	default:
 		/* pf_route6() returns unlocked. */
 		if (r->rt) {
-			pf_route6(m0, r, dir, kif->pfik_ifp, s, &pd);
+			pf_route6(m0, r, dir, kif->pfik_ifp, s, &pd, inp);
 			return (action);
 		}
 		break;


More information about the svn-src-all mailing list