Skip to contentSkip to conversation

xfrm: bug fixes when processing multiple transforms

PATCH Superseded Sowmini Varadhan 2 participants 4 messages Sep 3, 2018

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover xfrm: bug fixes when processing multiple transforms

This series contains bug fixes that were encountered when I set up a libreswan tunnel using the config below, which will set up an IPsec policy involving 2 tmpls.

type=transport
compress=yes
esp=aes_gcm_c-128-null # offloaded to Niantic
auto=start

The non-offload test case uses esp=aes_gcm_c-256-null.

Each patch has a technical description of the contents of the fix.

Sowmini Varadhan (2):
xfrm: reset transport header back to network header after all input
transforms ahave been applied
xfrm: reset crypto_done when iterating over multiple input xfrms

 net/ipv4/xfrm4_input.c          |    1 +
 net/ipv4/xfrm4_mode_transport.c |    4 +---
 net/ipv6/xfrm6_input.c          |    1 +
 net/ipv6/xfrm6_mode_transport.c |    4 +---
 net/xfrm/xfrm_input.c           |    1 +
 5 files changed, 5 insertions(+), 6 deletions(-)
#1 lore raw

PATCH 1/2 xfrm: reset transport header back to network header after all input transforms ahave been applied

A policy may have been set up with multiple transforms (e.g., ESP and ipcomp). In this situation, the ingress IPsec processing iterates in xfrm_input() and applies each transform in turn, processing the nexthdr to find any additional xfrm that may apply.

This patch resets the transport header back to network header only after the last transformation so that subsequent xfrms can find the correct transport header.

---
 net/ipv4/xfrm4_input.c          |    1 +
 net/ipv4/xfrm4_mode_transport.c |    4 +---
 net/ipv6/xfrm6_input.c          |    1 +
 net/ipv6/xfrm6_mode_transport.c |    4 +---
 4 files changed, 4 insertions(+), 6 deletions(-)
net/ipv4/xfrm4_input.c +1 -0
index bcfc00e..f8de248 100644
@@ -67,6 +67,7 @@ int xfrm4_transport_finish(struct sk_buff *skb, int async)
 
 	if (xo && (xo->flags & XFRM_GRO)) {
 		skb_mac_header_rebuild(skb);
+		skb_reset_transport_header(skb);
 		return 0;
 	}
 
net/ipv4/xfrm4_mode_transport.c +1 -3
index 3d36644..1ad2c2c 100644
@@ -46,7 +46,6 @@ static int xfrm4_transport_output(struct xfrm_state *x, struct sk_buff *skb)
 static int xfrm4_transport_input(struct xfrm_state *x, struct sk_buff *skb)
 {
 	int ihl = skb->data - skb_transport_header(skb);
-	struct xfrm_offload *xo = xfrm_offload(skb);
 
 	if (skb->transport_header != skb->network_header) {
 		memmove(skb_transport_header(skb),
@@ -54,8 +53,7 @@ static int xfrm4_transport_input(struct xfrm_state *x, struct sk_buff *skb)
 		skb->network_header = skb->transport_header;
 	}
 	ip_hdr(skb)->tot_len = htons(skb->len + ihl);
-	if (!xo || !(xo->flags & XFRM_GRO))
-		skb_reset_transport_header(skb);
+	skb_reset_transport_header(skb);
 	return 0;
 }
 
net/ipv6/xfrm6_input.c +1 -0
index 841f4a0..9ef490d 100644
@@ -59,6 +59,7 @@ int xfrm6_transport_finish(struct sk_buff *skb, int async)
 
 	if (xo && (xo->flags & XFRM_GRO)) {
 		skb_mac_header_rebuild(skb);
+		skb_reset_transport_header(skb);
 		return -1;
 	}
 
net/ipv6/xfrm6_mode_transport.c +1 -3
index 9ad07a9..3c29da5 100644
@@ -51,7 +51,6 @@ static int xfrm6_transport_output(struct xfrm_state *x, struct sk_buff *skb)
 static int xfrm6_transport_input(struct xfrm_state *x, struct sk_buff *skb)
 {
 	int ihl = skb->data - skb_transport_header(skb);
-	struct xfrm_offload *xo = xfrm_offload(skb);
 
 	if (skb->transport_header != skb->network_header) {
 		memmove(skb_transport_header(skb),
@@ -60,8 +59,7 @@ static int xfrm6_transport_input(struct xfrm_state *x, struct sk_buff *skb)
 	}
 	ipv6_hdr(skb)->payload_len = htons(skb->len + ihl -
 					   sizeof(struct ipv6hdr));
-	if (!xo || !(xo->flags & XFRM_GRO))
-		skb_reset_transport_header(skb);
+	skb_reset_transport_header(skb);
 	return 0;
 }
 
Signature · 1 line
1.7.1
#3 lore raw

PATCH 2/2 xfrm: reset crypto_done when iterating over multiple input xfrms

In reply to Sowmini Varadhan

We only support one offloaded xfrm (we do not have devices that can handle more than one offload), so reset crypto_done in xfrm_input() when iterating over multiple transforms in xfrm_input, so that we can invoke the appropriate x->type->input for the non-offloaded transforms

---
 net/xfrm/xfrm_input.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
net/xfrm/xfrm_input.c +1 -0
index b89c9c7..be3520e 100644
@@ -458,6 +458,7 @@ int xfrm_input(struct sk_buff *skb, int nexthdr, __be32 spi, int encap_type)
 			XFRM_INC_STATS(net, LINUX_MIB_XFRMINHDRERROR);
 			goto drop;
 		}
+		crypto_done = false;
 	} while (!err);
 
 	err = xfrm_rcv_cb(skb, family, x->type->proto, 0);
Signature · 1 line
1.7.1
maintainer
#2 lore raw

Re: [PATCH ipsec-next 1/2] xfrm: reset transport header back to network header after all input transforms ahave been applied

In reply to Sowmini Varadhan
Quoted 11 lines · Sowmini Varadhan

A policy may have been set up with multiple transforms (e.g., ESP and ipcomp). In this situation, the ingress IPsec processing iterates in xfrm_input() and applies each transform in turn, processing the nexthdr to find any additional xfrm that may apply.

This patch resets the transport header back to network header only after the last transformation so that subsequent xfrms can find the correct transport header.

This patch is a fix, so please add a proper fixes tag so that it can be backported to the stable trees. Same applied to the other patch in this series.