Wrong icmp6 checksum for ICMPV6_TIME_EXCEED in reverse SNATv6 path
Subsystems (2)
I Have the following setup.
3 linux systems A, B, and C.
host A is an end host with IPv6 address Z2.
host B is doing v6/v6 forwarding (no NAT) between an ethernet interface and a tun (openvpn) with addresses Z1 and Y2.
host C is doing v6/v6 SNAT between a tun (openvpn) and an ethernet interface with addresses Y1 and X2. X2 is a static address so SNAT instead of MASQUERADE is used.
Network X is a public IPv6 subnet.
Networks Y and Z are private networks and need NAT66 SNAT on their way to the internet done in host C.
+--------+ +---------------+ +---------------+ +------...
| host-A | | host-B | | host-C | | internet
| IP-Z2 <- eth -> IP-Z1 IP-Y2 <- tun -> IP-Y1 IP-X2 <- eth -> IP-X1
+--------+ +---------------+ +---------------+ +------...
(IPv6 Fwd) (IPv6 SNAT)See problem when doing a traceroute with icmp6 from host A to internet.
All ICMPV6_TIME_EXCEED responses from X1 and beyond are getting corrupted by host C on the reverse path back to host A.
Final hop return ICMPV6_ECHO_REPLY which is fine.
host-A$ traceroute -6 --icmp -n www.google.com
traceroute to www.google.com (2607:f8b0:4004:800::2004), 30 hops max, 80 byte packets
1 [host-B-Z1] 0.313 ms 0.326 ms 0.371 ms 2 [host-C-Y1] 19.732 ms 20.040 ms 20.051 ms 3 * * * 4 * * * 5 * * * 6 * * * 7 * * * 8 * * * 9 * * * 10 * * * 11 2607:f8b0:4004:800::2004 26.670 ms 27.193 ms 27.202 ms
All those ICMPV6_TIME_EXCEED packets are corrupted by host C and are discarded by host A:
host A is logging:
Apr 18 17:10:56 host-A kernel: [9843084.191460] ICMPv6 checksum failed [some-internet-router-3 > host-A-Z2] Apr 18 17:10:56 host-A kernel: [9843084.191504] ICMPv6 checksum failed [some-internet-router-3 > host-A-Z2] Apr 18 17:10:56 host-A kernel: [9843084.193587] ICMPv6 checksum failed [some-internet-router-3 > host-A-Z2] Apr 18 17:10:56 host-A kernel: [9843084.196254] ICMPv6 checksum failed [some-internet-router-4 > host-A-Z2] Apr 18 17:10:56 host-A kernel: [9843084.196398] ICMPv6 checksum failed [some-internet-router-4 > host-A-Z2] Apr 18 17:10:56 host-A kernel: [9843084.196526] ICMPv6 checksum failed [some-internet-router-4 > host-A-Z2]
A packet capture on host-C's X2 interface show correct (pre-nat) packets on the reverse path, and on host-C's Y1 tun interface show incorrect (post-nat) packets on the reverse path.
Looking at the packet capture, 4 updates are needed by host C on it's way from internet back to host A:
1) outer (ICMPV6_TIME_EXCEED) packet dest ip from X2 to Z2
2) outer (ICMPV6_TIME_EXCEED) packet icmp6 checksum recalc
3) inner (ICMPV6_ECHO_REQUEST) packet src ip from X2 to Z2
4) inner (ICMPV6_ECHO_REQUEST) packet icmp6 checksum recalc
1,3,4 are done correctly by host C.
2 is changed by host C but to an incorrect value.
Originally seen in kernel 3.16, but brought host C up to kernel 4.9.23 to make sure it's not already fixed in recent builds, still happens in that version.
seems like possible issue in nf_nat_icmpv6_reply_translation() or icmpv6_manip_pkt() area.
Thoughts before I start digging deaper?
Signature · 1 line
Dave
PATCH 1/1 netfilter: Wrong icmp6 checksum for ICMPV6_TIME_EXCEED in reverse SNATv6 path
When recalculating the outer ICMPv6 checksum for a reverse path NATv6 such as ICMPV6_TIME_EXCEED nf_nat_icmpv6_reply_translation() was accessing data beyond the headlen of the skb for non-linear skb. This resulted in incorrect ICMPv6 checksum as garbage data was used.
---
net/ipv6/netfilter/nf_nat_l3proto_ipv6.c +6 -1
@@ -229,7 +229,12 @@ int nf_nat_icmpv6_reply_translation(strureturn 0 ;if (skb->ip_summed !=CHECKSUM_PARTIAL ) { -struct ipv6hdr *ipv6h =ipv6_hdr (skb); +struct ipv6hdr *ipv6h; + +if (!skb_make_writable (skb, skb->len)) +return 0 ; + + ipv6h =ipv6_hdr (skb); inside = (void *)skb->data + hdrlen; inside->icmp6.icmp6_cksum =0 ; inside->icmp6.icmp6_cksum =
Pablo Neira Ayuso
maintainerRe: [PATCH] netfilter: Wrong icmp6 checksum for ICMPV6_TIME_EXCEED in reverse SNATv6 path
Quoted 12 lines · Dave Johnson
When recalculating the outer ICMPv6 checksum for a reverse path NATv6 such as
ICMPV6_TIME_EXCEEDnf_nat_icmpv6_reply_translation()was accessing data beyond the headlen of the skb for non-linear skb. This resulted in incorrect ICMPv6 checksum as garbage data was used.Signed-off-by Dave Johnson <[email protected]>---
diff -ruplinux-4.9.23.orig/net/ipv6/netfilter/nf_nat_l3proto_ipv6.clinux-4.9.23/net/ipv6/netfilter/nf_nat_l3proto_ipv6.c
net/ipv6/netfilter/nf_nat_l3proto_ipv6.c int nf_nat_icmpv6_reply_translation(stru · line 234
Quoted 7 lines
net/ipv6/netfilter/nf_nat_l3proto_ipv6.c +3
-1@@ -229,7 +229,12 @@ int nf_nat_icmpv6_reply_translation(strureturn 0 ;if (skb->ip_summed !=CHECKSUM_PARTIAL ) { -struct ipv6hdr *ipv6h =ipv6_hdr (skb); +struct ipv6hdr *ipv6h; + +if (!skb_make_writable (skb, skb->len))
can we just make sure what we need is linear? I mean, just the ipv6 header that is what we need, instead of the entire skbuff.
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [PATCH] netfilter: Wrong icmp6 checksum for ICMPV6_TIME_EXCEED in reverse SNATv6 path
When recalculating the outer ICMPv6 checksum for a reverse path NATv6 such as ICMPV6_TIME_EXCEED nf_nat_icmpv6_reply_translation() was accessing data beyond the headlen of the skb for non-linear skb. This resulted in incorrect ICMPv6 checksum as garbage data was used.
Patch replaces csum_partial() with skb_checksum() which supports non-linear skbs similar to nf_nat_icmp_reply_translation() from ipv4.
---
net/ipv6/netfilter/nf_nat_l3proto_ipv6.c +1 -1
@@ -235,7 +235,7 @@ int nf_nat_icmpv6_reply_translation(stru inside->icmp6.icmp6_cksum =csum_ipv6_magic (&ipv6h->saddr, &ipv6h->daddr, skb->len - hdrlen,IPPROTO_ICMPV6 , -csum_partial (&inside->icmp6, +skb_checksum (skb, hdrlen, skb->len - hdrlen,0 )); }
Re: [PATCH] netfilter: Wrong icmp6 checksum for ICMPV6_TIME_EXCEED in reverse SNATv6 path
In reply to a message not in the archiveQuoted 15 lines · Pablo Neira Ayuso
Quoted 14 lines · Dave Johnson
When recalculating the outer ICMPv6 checksum for a reverse path NATv6 such as
ICMPV6_TIME_EXCEEDnf_nat_icmpv6_reply_translation()was accessing data beyond the headlen of the skb for non-linear skb. This resulted in incorrect ICMPv6 checksum as garbage data was used.Signed-off-by Dave Johnson <[email protected]>---
diff -ruplinux-4.9.23.orig/net/ipv6/netfilter/nf_nat_l3proto_ipv6.clinux-4.9.23/net/ipv6/netfilter/nf_nat_l3proto_ipv6.cnet/ipv6/netfilter/nf_nat_l3proto_ipv6.c +0
-0@@ -229,7 +229,12 @@ int nf_nat_icmpv6_reply_translation(strureturn 0 ;
Quoted 8 lines
net/ipv6/netfilter/nf_nat_l3proto_ipv6.c int nf_nat_icmpv6_reply_translation(stru · line 234
Quoted 5 lines
net/ipv6/netfilter/nf_nat_l3proto_ipv6.c +3
-1if (skb->ip_summed !=CHECKSUM_PARTIAL ) { -struct ipv6hdr *ipv6h =ipv6_hdr (skb); +struct ipv6hdr *ipv6h; + +if (!skb_make_writable (skb, skb->len))can we just make sure what we need is linear? I mean, just the ipv6 header that is what we need, instead of the entire skbuff.
the checksum below those lines is across the entire skb as unknown updates were done in the l4 manip call just prior to this.
nf_nat_icmp_reply_translation() for ipv4 uses skb_checksum() to walk non-linear skbs. gave that a try and it works, will send an updated patch in a bit.
Re: [PATCH] netfilter: Wrong icmp6 checksum for ICMPV6_TIME_EXCEED in reverse SNATv6 path
In reply to Dave JohnsonQuoted 5 lines · Dave Johnson
When recalculating the outer ICMPv6 checksum for a reverse path NATv6 such as
ICMPV6_TIME_EXCEEDnf_nat_icmpv6_reply_translation()was accessing data beyond the headlen of the skb for non-linear skb. This resulted in incorrect ICMPv6 checksum as garbage data was used.
Applied to nf, thanks.