]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
gre6: Fix reception with IP6_TNL_F_RCV_DSCP_COPY
authorMark Tomlinson <mark.tomlinson@alliedtelesis.co.nz>
Wed, 19 Aug 2020 01:53:58 +0000 (13:53 +1200)
committerDavid S. Miller <davem@davemloft.net>
Thu, 20 Aug 2020 23:28:04 +0000 (16:28 -0700)
When receiving an IPv4 packet inside an IPv6 GRE packet, and the
IP6_TNL_F_RCV_DSCP_COPY flag is set on the tunnel, the IPv4 header would
get corrupted. This is due to the common ip6_tnl_rcv() function assuming
that the inner header is always IPv6. This patch checks the tunnel
protocol for IPv4 inner packets, but still defaults to IPv6.

Fixes: 308edfdf1563 ("gre6: Cleanup GREv6 receive path, call common GRE functions")
Signed-off-by: Mark Tomlinson <mark.tomlinson@alliedtelesis.co.nz>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/ipv6/ip6_tunnel.c

index f635914f42ec6057afe97fb03a78c4dd856886d9..a0217e5bf3bc1132969e0ed7421cf5eceff54d69 100644 (file)
@@ -915,7 +915,15 @@ int ip6_tnl_rcv(struct ip6_tnl *t, struct sk_buff *skb,
                struct metadata_dst *tun_dst,
                bool log_ecn_err)
 {
-       return __ip6_tnl_rcv(t, skb, tpi, tun_dst, ip6ip6_dscp_ecn_decapsulate,
+       int (*dscp_ecn_decapsulate)(const struct ip6_tnl *t,
+                                   const struct ipv6hdr *ipv6h,
+                                   struct sk_buff *skb);
+
+       dscp_ecn_decapsulate = ip6ip6_dscp_ecn_decapsulate;
+       if (tpi->proto == htons(ETH_P_IP))
+               dscp_ecn_decapsulate = ip4ip6_dscp_ecn_decapsulate;
+
+       return __ip6_tnl_rcv(t, skb, tpi, tun_dst, dscp_ecn_decapsulate,
                             log_ecn_err);
 }
 EXPORT_SYMBOL(ip6_tnl_rcv);