All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH ipsec] xfrm: esp6: fix encapsulation header offset computation
@ 2020-07-03 14:57 Sabrina Dubroca
  2020-07-06  8:09 ` Tobias Brunner
  2020-07-08  8:14 ` Steffen Klassert
  0 siblings, 2 replies; 3+ messages in thread
From: Sabrina Dubroca @ 2020-07-03 14:57 UTC (permalink / raw)
  To: netdev; +Cc: steffen.klassert, Sabrina Dubroca, Tobias Brunner

In commit 0146dca70b87, I incorrectly adapted the code that computes
the location of the UDP or TCP encapsulation header from IPv4 to
IPv6. In esp6_input_done2, skb->transport_header points to the ESP
header, so by adding skb_network_header_len, uh and th will point to
the ESP header, not the encapsulation header that's in front of it.

Since the TCP header's size can change with options, we have to start
from the IPv6 header and walk past possible extensions.

Fixes: 0146dca70b87 ("xfrm: add support for UDPv6 encapsulation of ESP")
Fixes: 26333c37fc28 ("xfrm: add IPv6 support for espintcp")
Reported-by: Tobias Brunner <tobias@strongswan.org>
Signed-off-by: Sabrina Dubroca <sd@queasysnail.net>
---
 net/ipv6/esp6.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/net/ipv6/esp6.c b/net/ipv6/esp6.c
index c43592771126..55ae70be91b3 100644
--- a/net/ipv6/esp6.c
+++ b/net/ipv6/esp6.c
@@ -805,10 +805,16 @@ int esp6_input_done2(struct sk_buff *skb, int err)
 
 	if (x->encap) {
 		const struct ipv6hdr *ip6h = ipv6_hdr(skb);
+		int offset = skb_network_offset(skb) + sizeof(*ip6h);
 		struct xfrm_encap_tmpl *encap = x->encap;
-		struct udphdr *uh = (void *)(skb_network_header(skb) + hdr_len);
-		struct tcphdr *th = (void *)(skb_network_header(skb) + hdr_len);
-		__be16 source;
+		u8 nexthdr = ip6h->nexthdr;
+		__be16 frag_off, source;
+		struct udphdr *uh;
+		struct tcphdr *th;
+
+		offset = ipv6_skip_exthdr(skb, offset, &nexthdr, &frag_off);
+		uh = (void *)(skb->data + offset);
+		th = (void *)(skb->data + offset);
 
 		switch (x->encap->encap_type) {
 		case TCP_ENCAP_ESPINTCP:
-- 
2.27.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH ipsec] xfrm: esp6: fix encapsulation header offset computation
  2020-07-03 14:57 [PATCH ipsec] xfrm: esp6: fix encapsulation header offset computation Sabrina Dubroca
@ 2020-07-06  8:09 ` Tobias Brunner
  2020-07-08  8:14 ` Steffen Klassert
  1 sibling, 0 replies; 3+ messages in thread
From: Tobias Brunner @ 2020-07-06  8:09 UTC (permalink / raw)
  To: Sabrina Dubroca, netdev; +Cc: steffen.klassert

Hi Sabrina,

> In commit 0146dca70b87, I incorrectly adapted the code that computes
> the location of the UDP or TCP encapsulation header from IPv4 to
> IPv6. In esp6_input_done2, skb->transport_header points to the ESP
> header, so by adding skb_network_header_len, uh and th will point to
> the ESP header, not the encapsulation header that's in front of it.
> 
> Since the TCP header's size can change with options, we have to start
> from the IPv6 header and walk past possible extensions.
> 
> Fixes: 0146dca70b87 ("xfrm: add support for UDPv6 encapsulation of ESP")
> Fixes: 26333c37fc28 ("xfrm: add IPv6 support for espintcp")
> Reported-by: Tobias Brunner <tobias@strongswan.org>
> Signed-off-by: Sabrina Dubroca <sd@queasysnail.net>

Thanks for the fix!

Tested-by: Tobias Brunner <tobias@strongswan.org>

Regards,
Tobias

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH ipsec] xfrm: esp6: fix encapsulation header offset computation
  2020-07-03 14:57 [PATCH ipsec] xfrm: esp6: fix encapsulation header offset computation Sabrina Dubroca
  2020-07-06  8:09 ` Tobias Brunner
@ 2020-07-08  8:14 ` Steffen Klassert
  1 sibling, 0 replies; 3+ messages in thread
From: Steffen Klassert @ 2020-07-08  8:14 UTC (permalink / raw)
  To: Sabrina Dubroca; +Cc: netdev, Tobias Brunner

On Fri, Jul 03, 2020 at 04:57:09PM +0200, Sabrina Dubroca wrote:
> In commit 0146dca70b87, I incorrectly adapted the code that computes
> the location of the UDP or TCP encapsulation header from IPv4 to
> IPv6. In esp6_input_done2, skb->transport_header points to the ESP
> header, so by adding skb_network_header_len, uh and th will point to
> the ESP header, not the encapsulation header that's in front of it.
> 
> Since the TCP header's size can change with options, we have to start
> from the IPv6 header and walk past possible extensions.
> 
> Fixes: 0146dca70b87 ("xfrm: add support for UDPv6 encapsulation of ESP")
> Fixes: 26333c37fc28 ("xfrm: add IPv6 support for espintcp")
> Reported-by: Tobias Brunner <tobias@strongswan.org>
> Signed-off-by: Sabrina Dubroca <sd@queasysnail.net>

Applied, thanks Sabrina!

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-07-08  8:14 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-03 14:57 [PATCH ipsec] xfrm: esp6: fix encapsulation header offset computation Sabrina Dubroca
2020-07-06  8:09 ` Tobias Brunner
2020-07-08  8:14 ` Steffen Klassert

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.