Skip to contentSkip to conversation

pull request (net): ipsec 2020-09-28

PATCH New Steffen Klassert 2 participants 10 messages Sep 28, 2020

Subsystems (4)
lore
Share & tools
lore

Steffen Klassert

author maintainer
#0 lore raw

1) Fix a build warning in ip_vti if CONFIG_IPV6 is not set. From YueHaibing.

2) Restore IPCB on espintcp before handing the packet to xfrm as the information there is still needed.
From Sabrina Dubroca.

3) Fix pmtu updating for xfrm interfaces.
From Sabrina Dubroca.

4) Some xfrm state information was not cloned with xfrm_do_migrate. Fixes to clone the full xfrm state, from Antony Antony.

5) Use the correct address family in xfrm_state_find. The struct flowi must always be interpreted along with the original address family. This got lost over the years.
Fix from Herbert Xu.

Please pull or let me know if there are problems.

Thanks!

The following changes since commit 1c3b63f155f637594268cd1add8335461691b314:

net/tls: allow MSG_CMSG_COMPAT in sendmsg (2020-08-07 17:40:45 -0700)

are available in the Git repository at:

git://git.kernel.org/pub/scm/linux/kernel/git/klassert/ipsec.git master

for you to fetch changes up to e94ee171349db84c7cfdc5fefbebe414054d0924:

xfrm: Use correct address family in xfrm_state_find (2020-09-25 09:59:51 +0200)

----------------------------------------------------------------
Antony Antony (4):
xfrm: clone XFRMA_SET_MARK in xfrm_do_migrate
xfrm: clone XFRMA_REPLAY_ESN_VAL in xfrm_do_migrate
xfrm: clone XFRMA_SEC_CTX in xfrm_do_migrate
xfrm: clone whole liftime_cur structure in xfrm_do_migrate

Herbert Xu (1):
xfrm: Use correct address family in xfrm_state_find

Sabrina Dubroca (2):
espintcp: restore IP CB before handing the packet to xfrm
xfrmi: drop ignore_df check before updating pmtu

YueHaibing (1):
ip_vti: Fix unused variable warning

 include/net/xfrm.h        | 16 ++++++----------
 net/ipv4/ip_vti.c         |  2 ++
 net/xfrm/espintcp.c       |  6 +++++-
 net/xfrm/xfrm_interface.c |  2 +-
 net/xfrm/xfrm_state.c     | 42 +++++++++++++++++++++++++++++++++++++-----
 5 files changed, 51 insertions(+), 17 deletions(-)
author maintainer
#1 lore raw

PATCH 1/8 ip_vti: Fix unused variable warning

From: YueHaibing <[email protected]>

If CONFIG_INET_XFRM_TUNNEL is set but CONFIG_IPV6 is n,

net/ipv4/ip_vti.c:493:27: warning: 'vti_ipip6_handler' defined but not used [-Wunused-variable]

---
 net/ipv4/ip_vti.c | 2 ++
 1 file changed, 2 insertions(+)
net/ipv4/ip_vti.c +2 -0
index 49daaed89764..f687abb069fa 100644
@@ -490,6 +490,7 @@ static struct xfrm_tunnel vti_ipip_handler __read_mostly = {
 	.priority	=	0,
 };
 
+#if IS_ENABLED(CONFIG_IPV6)
 static struct xfrm_tunnel vti_ipip6_handler __read_mostly = {
 	.handler	=	vti_rcv_tunnel,
 	.cb_handler	=	vti_rcv_cb,
@@ -497,6 +498,7 @@ static struct xfrm_tunnel vti_ipip6_handler __read_mostly = {
 	.priority	=	0,
 };
 #endif
+#endif
 
 static int __net_init vti_init_net(struct net *net)
 {
Signature · 1 line
2.17.1
author maintainer
#2 lore raw

PATCH 2/8 espintcp: restore IP CB before handing the packet to xfrm

In reply to Steffen Klassert

From: Sabrina Dubroca <[email protected]>

Xiumei reported a bug with espintcp over IPv6 in transport mode, because xfrm6_transport_finish expects to find IP6CB data (struct inet6_skb_cb). Currently, espintcp zeroes the CB, but the relevant part is actually preserved by previous layers (first set up by tcp, then strparser only zeroes a small part of tcp_skb_tb), so we can just relocate it to the start of skb->cb.

Fixes e27cca96cd68 ("xfrm: add espintcp (RFC 8229)")
---
 net/xfrm/espintcp.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
net/xfrm/espintcp.c +5 -1
index 827ccdf2db57..1f08ebf7d80c 100644
@@ -29,8 +29,12 @@ static void handle_nonesp(struct espintcp_ctx *ctx, struct sk_buff *skb,
 
 static void handle_esp(struct sk_buff *skb, struct sock *sk)
 {
+	struct tcp_skb_cb *tcp_cb = (struct tcp_skb_cb *)skb->cb;
+
 	skb_reset_transport_header(skb);
-	memset(skb->cb, 0, sizeof(skb->cb));
+
+	/* restore IP CB, we need at least IP6CB->nhoff */
+	memmove(skb->cb, &tcp_cb->header, sizeof(tcp_cb->header));
 
 	rcu_read_lock();
 	skb->dev = dev_get_by_index_rcu(sock_net(sk), skb->skb_iif);
Signature · 1 line
2.17.1
author maintainer
#3 lore raw

PATCH 3/8 xfrmi: drop ignore_df check before updating pmtu

In reply to Steffen Klassert

From: Sabrina Dubroca <[email protected]>

xfrm interfaces currently test for !skb->ignore_df when deciding whether to update the pmtu on the skb's dst. Because of this, no pmtu exception is created when we do something like:

    ping -s 1438 <dest>

By dropping this check, the pmtu exception will be created and the next ping attempt will work.

Fixes f203b76d7809 ("xfrm: Add virtual xfrm interfaces")
---
 net/xfrm/xfrm_interface.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/xfrm/xfrm_interface.c +1 -1
index eb8181987620..a8f66112c52b 100644
@@ -303,7 +303,7 @@ xfrmi_xmit2(struct sk_buff *skb, struct net_device *dev, struct flowi *fl)
 	}
 
 	mtu = dst_mtu(dst);
-	if (!skb->ignore_df && skb->len > mtu) {
+	if (skb->len > mtu) {
 		skb_dst_update_pmtu_no_confirm(skb, mtu);
 
 		if (skb->protocol == htons(ETH_P_IPV6)) {
Signature · 1 line
2.17.1
author maintainer
#4 lore raw

PATCH 4/8 xfrm: clone XFRMA_SET_MARK in xfrm_do_migrate

In reply to Steffen Klassert

From: Antony Antony <[email protected]>

XFRMA_SET_MARK and XFRMA_SET_MARK_MASK was not cloned from the old to the new. Migrate these two attributes during XFRMA_MSG_MIGRATE

Fixes 9b42c1f179a6 ("xfrm: Extend the output_mark to support input direction and masking.")
---
 net/xfrm/xfrm_state.c | 1 +
 1 file changed, 1 insertion(+)
net/xfrm/xfrm_state.c +1 -0
index 69520ad3d83b..3a000f289dcd 100644
@@ -1510,6 +1510,7 @@ static struct xfrm_state *xfrm_state_clone(struct xfrm_state *orig,
 	}
 
 	memcpy(&x->mark, &orig->mark, sizeof(x->mark));
+	memcpy(&x->props.smark, &orig->props.smark, sizeof(x->props.smark));
 
 	if (xfrm_init_state(x) < 0)
 		goto error;
Signature · 1 line
2.17.1
author maintainer
#5 lore raw

PATCH 5/8 xfrm: clone XFRMA_REPLAY_ESN_VAL in xfrm_do_migrate

In reply to Steffen Klassert

From: Antony Antony <[email protected]>

XFRMA_REPLAY_ESN_VAL was not cloned completely from the old to the new. Migrate this attribute during XFRMA_MSG_MIGRATE

v1->v2:
- move curleft cloning to a separate patch

Fixes af2f464e326e ("xfrm: Assign esn pointers when cloning a state")
---
 include/net/xfrm.h | 16 ++++++----------
 1 file changed, 6 insertions(+), 10 deletions(-)
include/net/xfrm.h +6 -10
index 2737d24ec244..9e806c781025 100644
@@ -1773,21 +1773,17 @@ static inline unsigned int xfrm_replay_state_esn_len(struct xfrm_replay_state_es
 static inline int xfrm_replay_clone(struct xfrm_state *x,
 				     struct xfrm_state *orig)
 {
-	x->replay_esn = kzalloc(xfrm_replay_state_esn_len(orig->replay_esn),
+
+	x->replay_esn = kmemdup(orig->replay_esn,
+				xfrm_replay_state_esn_len(orig->replay_esn),
 				GFP_KERNEL);
 	if (!x->replay_esn)
 		return -ENOMEM;
-
-	x->replay_esn->bmp_len = orig->replay_esn->bmp_len;
-	x->replay_esn->replay_window = orig->replay_esn->replay_window;
-
-	x->preplay_esn = kmemdup(x->replay_esn,
-				 xfrm_replay_state_esn_len(x->replay_esn),
+	x->preplay_esn = kmemdup(orig->preplay_esn,
+				 xfrm_replay_state_esn_len(orig->preplay_esn),
 				 GFP_KERNEL);
-	if (!x->preplay_esn) {
-		kfree(x->replay_esn);
+	if (!x->preplay_esn)
 		return -ENOMEM;
-	}
 
 	return 0;
 }
Signature · 1 line
2.17.1
author maintainer
#6 lore raw

PATCH 6/8 xfrm: clone XFRMA_SEC_CTX in xfrm_do_migrate

In reply to Steffen Klassert

From: Antony Antony <[email protected]>

XFRMA_SEC_CTX was not cloned from the old to the new. Migrate this attribute during XFRMA_MSG_MIGRATE

v1->v2:
- return -ENOMEM on error
v2->v3:
- fix return type to int

Fixes 80c9abaabf42 ("[XFRM]: Extension for dynamic update of endpoint address(es)")
---
 net/xfrm/xfrm_state.c | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)
net/xfrm/xfrm_state.c +28 -0
index 3a000f289dcd..5e5ed8108498 100644
@@ -1441,6 +1441,30 @@ int xfrm_state_add(struct xfrm_state *x)
 EXPORT_SYMBOL(xfrm_state_add);
 
 #ifdef CONFIG_XFRM_MIGRATE
+static inline int clone_security(struct xfrm_state *x, struct xfrm_sec_ctx *security)
+{
+	struct xfrm_user_sec_ctx *uctx;
+	int size = sizeof(*uctx) + security->ctx_len;
+	int err;
+
+	uctx = kmalloc(size, GFP_KERNEL);
+	if (!uctx)
+		return -ENOMEM;
+
+	uctx->exttype = XFRMA_SEC_CTX;
+	uctx->len = size;
+	uctx->ctx_doi = security->ctx_doi;
+	uctx->ctx_alg = security->ctx_alg;
+	uctx->ctx_len = security->ctx_len;
+	memcpy(uctx + 1, security->ctx_str, security->ctx_len);
+	err = security_xfrm_state_alloc(x, uctx);
+	kfree(uctx);
+	if (err)
+		return err;
+
+	return 0;
+}
+
 static struct xfrm_state *xfrm_state_clone(struct xfrm_state *orig,
 					   struct xfrm_encap_tmpl *encap)
 {
@@ -1497,6 +1521,10 @@ static struct xfrm_state *xfrm_state_clone(struct xfrm_state *orig,
 			goto error;
 	}
 
+	if (orig->security)
+		if (clone_security(x, orig->security))
+			goto error;
+
 	if (orig->coaddr) {
 		x->coaddr = kmemdup(orig->coaddr, sizeof(*x->coaddr),
 				    GFP_KERNEL);
Signature · 1 line
2.17.1
author maintainer
#7 lore raw

PATCH 7/8 xfrm: clone whole liftime_cur structure in xfrm_do_migrate

In reply to Steffen Klassert

From: Antony Antony <[email protected]>

When we clone state only add_time was cloned. It missed values like bytes, packets. Now clone the all members of the structure.

v1->v3:
- use memcpy to copy the entire structure

Fixes 80c9abaabf42 ("[XFRM]: Extension for dynamic update of endpoint address(es)")
---
 net/xfrm/xfrm_state.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/xfrm/xfrm_state.c +1 -1
index 5e5ed8108498..5ff392e6f3c1 100644
@@ -1550,7 +1550,7 @@ static struct xfrm_state *xfrm_state_clone(struct xfrm_state *orig,
 	x->tfcpad = orig->tfcpad;
 	x->replay_maxdiff = orig->replay_maxdiff;
 	x->replay_maxage = orig->replay_maxage;
-	x->curlft.add_time = orig->curlft.add_time;
+	memcpy(&x->curlft, &orig->curlft, sizeof(x->curlft));
 	x->km.state = orig->km.state;
 	x->km.seq = orig->km.seq;
 	x->replay = orig->replay;
Signature · 1 line
2.17.1
author maintainer
#8 lore raw

PATCH 8/8 xfrm: Use correct address family in xfrm_state_find

In reply to Steffen Klassert

From: Herbert Xu <[email protected]>

The struct flowi must never be interpreted by itself as its size depends on the address family. Therefore it must always be grouped with its original family value.

In this particular instance, the original family value is lost in the function xfrm_state_find. Therefore we get a bogus read when it's coupled with the wrong family which would occur with inter- family xfrm states.

This patch fixes it by keeping the original family value.

Note that the same bug could potentially occur in LSM through the xfrm_state_pol_flow_match hook. I checked the current code there and it seems to be safe for now as only secid is used which is part of struct flowi_common. But that API should be changed so that so that we don't get new bugs in the future. We could do that by replacing fl with just secid or adding a family field.

Reported-by [email protected]
Fixes 48b8d78315bf ("[XFRM]: State selection update to use inner...")
---
 net/xfrm/xfrm_state.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
net/xfrm/xfrm_state.c +7 -4
index 5ff392e6f3c1..efc89a92961d 100644
@@ -1019,7 +1019,8 @@ static void xfrm_state_look_at(struct xfrm_policy *pol, struct xfrm_state *x,
 	 */
 	if (x->km.state == XFRM_STATE_VALID) {
 		if ((x->sel.family &&
-		     !xfrm_selector_match(&x->sel, fl, x->sel.family)) ||
+		     (x->sel.family != family ||
+		      !xfrm_selector_match(&x->sel, fl, family))) ||
 		    !security_xfrm_state_pol_flow_match(x, pol, fl))
 			return;
 
@@ -1032,7 +1033,9 @@ static void xfrm_state_look_at(struct xfrm_policy *pol, struct xfrm_state *x,
 		*acq_in_progress = 1;
 	} else if (x->km.state == XFRM_STATE_ERROR ||
 		   x->km.state == XFRM_STATE_EXPIRED) {
-		if (xfrm_selector_match(&x->sel, fl, x->sel.family) &&
+		if ((!x->sel.family ||
+		     (x->sel.family == family &&
+		      xfrm_selector_match(&x->sel, fl, family))) &&
 		    security_xfrm_state_pol_flow_match(x, pol, fl))
 			*error = -ESRCH;
 	}
@@ -1072,7 +1075,7 @@ xfrm_state_find(const xfrm_address_t *daddr, const xfrm_address_t *saddr,
 		    tmpl->mode == x->props.mode &&
 		    tmpl->id.proto == x->id.proto &&
 		    (tmpl->id.spi == x->id.spi || !tmpl->id.spi))
-			xfrm_state_look_at(pol, x, fl, encap_family,
+			xfrm_state_look_at(pol, x, fl, family,
 					   &best, &acquire_in_progress, &error);
 	}
 	if (best || acquire_in_progress)
@@ -1089,7 +1092,7 @@ xfrm_state_find(const xfrm_address_t *daddr, const xfrm_address_t *saddr,
 		    tmpl->mode == x->props.mode &&
 		    tmpl->id.proto == x->id.proto &&
 		    (tmpl->id.spi == x->id.spi || !tmpl->id.spi))
-			xfrm_state_look_at(pol, x, fl, encap_family,
+			xfrm_state_look_at(pol, x, fl, family,
 					   &best, &acquire_in_progress, &error);
 	}
 
Signature · 1 line
2.17.1
maintainer
#9 lore raw
In reply to Steffen Klassert

From: Steffen Klassert <[email protected]>
Date: Mon, 28 Sep 2020 10:24:42 +0200

Quoted 13 lines

1) Fix a build warning in ip_vti if CONFIG_IPV6 is not set. From YueHaibing.

2) Restore IPCB on espintcp before handing the packet to xfrm as the information there is still needed.
From Sabrina Dubroca.

3) Fix pmtu updating for xfrm interfaces.
From Sabrina Dubroca.

4) Some xfrm state information was not cloned with xfrm_do_migrate. Fixes to clone the full xfrm state, from Antony Antony.

Quoted 6 lines

5) Use the correct address family in xfrm_state_find. The struct flowi must always be interpreted along with the original address family. This got lost over the years.
Fix from Herbert Xu.

Please pull or let me know if there are problems.

Pulled, thank you.