Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 15 Jan 2017 15:43:19 +0000 (UTC)
From:      "Andrey V. Elsukov" <ae@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org
Subject:   svn commit: r312233 - stable/11/sys/netipsec
Message-ID:  <201701151543.v0FFhJh5029547@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: ae
Date: Sun Jan 15 15:43:19 2017
New Revision: 312233
URL: https://svnweb.freebsd.org/changeset/base/312233

Log:
  MFC r311679:
    Add direction argument to ipsec_setspidx_inpcb() function.
  
    This function is used only by ipsec_getpolicybysock() to fill security
    policy index selector for locally generated packets (that have INPCB).
    The function incorrectly assumes that spidx is the same for both directions.
    Fix this by using new direction argument to specify correct INPCB security
    policy - sp_in or sp_out. There is no need to fill both policy indeces,
    because they are overwritten for each packet.
    This fixes security policy matching for outbound packets when user has
    specified TCP/UDP ports in the security policy upperspec.
  
    PR:		213869

Modified:
  stable/11/sys/netipsec/ipsec.c
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/sys/netipsec/ipsec.c
==============================================================================
--- stable/11/sys/netipsec/ipsec.c	Sun Jan 15 13:57:42 2017	(r312232)
+++ stable/11/sys/netipsec/ipsec.c	Sun Jan 15 15:43:19 2017	(r312233)
@@ -241,7 +241,7 @@ SYSCTL_VNET_PCPUSTAT(_net_inet6_ipsec6, 
 #endif /* INET6 */
 
 static int ipsec_in_reject(struct secpolicy *, const struct mbuf *);
-static int ipsec_setspidx_inpcb(const struct mbuf *, struct inpcb *);
+static int ipsec_setspidx_inpcb(const struct mbuf *, struct inpcb *, u_int);
 static int ipsec_setspidx(const struct mbuf *, struct secpolicyindex *, int);
 static void ipsec4_get_ulp(const struct mbuf *m, struct secpolicyindex *, int);
 static int ipsec4_setspidx_ipaddr(const struct mbuf *, struct secpolicyindex *);
@@ -344,7 +344,7 @@ ipsec_getpolicybysock(const struct mbuf 
 	}
 
 	/* Set spidx in pcb. */
-	*error = ipsec_setspidx_inpcb(m, inp);
+	*error = ipsec_setspidx_inpcb(m, inp, dir);
 	if (*error)
 		return (NULL);
 
@@ -501,8 +501,9 @@ ipsec4_checkpolicy(const struct mbuf *m,
 }
 
 static int
-ipsec_setspidx_inpcb(const struct mbuf *m, struct inpcb *inp)
+ipsec_setspidx_inpcb(const struct mbuf *m, struct inpcb *inp, u_int dir)
 {
+	struct secpolicyindex *spidx;
 	int error;
 
 	IPSEC_ASSERT(inp != NULL, ("null inp"));
@@ -510,11 +511,13 @@ ipsec_setspidx_inpcb(const struct mbuf *
 	IPSEC_ASSERT(inp->inp_sp->sp_out != NULL && inp->inp_sp->sp_in != NULL,
 		("null sp_in || sp_out"));
 
-	error = ipsec_setspidx(m, &inp->inp_sp->sp_in->spidx, 1);
+	if (dir == IPSEC_DIR_INBOUND)
+		spidx = &inp->inp_sp->sp_in->spidx;
+	else
+		spidx = &inp->inp_sp->sp_out->spidx;
+	error = ipsec_setspidx(m, spidx, 1);
 	if (error == 0) {
-		inp->inp_sp->sp_in->spidx.dir = IPSEC_DIR_INBOUND;
-		inp->inp_sp->sp_out->spidx = inp->inp_sp->sp_in->spidx;
-		inp->inp_sp->sp_out->spidx.dir = IPSEC_DIR_OUTBOUND;
+		spidx->dir = dir;
 	} else {
 		bzero(&inp->inp_sp->sp_in->spidx,
 			sizeof (inp->inp_sp->sp_in->spidx));



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