netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [NET] netfilter: nat: fix ICMP header corruption on ICMP errors
@ 2020-01-14  7:25 Eyal Birger
  0 siblings, 0 replies; only message in thread
From: Eyal Birger @ 2020-01-14  7:25 UTC (permalink / raw)
  To: pablo, kadlec, fw, davem, netfilter-devel, coreteam, netdev
  Cc: Eyal Birger, Shmulik Ladkani

Commit 8303b7e8f018 ("netfilter: nat: fix spurious connection timeouts")
made nf_nat_icmp_reply_translation() use icmp_manip_pkt() as the l4
manipulation function for the outer packet on ICMP errors.

However, icmp_manip_pkt() assumes the packet is an ICMP echo packet
and therefore that the ICMP header's 'un' field is an ICMP echo id.

This is not correct for ICMP error packets, and leads to bogus bytes
being written the ICMP header, which can be wrongfully regarded as
'length' bytes by RFC 4884 compliant receivers.

Fix by assigning the 'id' field only for ICMP echo packets similar
to the treatment in ICMPv6.

Reported-by: Shmulik Ladkani <shmulik.ladkani@gmail.com>
Fixes: 8303b7e8f018 ("netfilter: nat: fix spurious connection timeouts")
Signed-off-by: Eyal Birger <eyal.birger@gmail.com>
---
 net/netfilter/nf_nat_proto.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/net/netfilter/nf_nat_proto.c b/net/netfilter/nf_nat_proto.c
index 0a59c14b5177..92ef91c120f4 100644
--- a/net/netfilter/nf_nat_proto.c
+++ b/net/netfilter/nf_nat_proto.c
@@ -233,9 +233,12 @@ icmp_manip_pkt(struct sk_buff *skb,
 		return false;
 
 	hdr = (struct icmphdr *)(skb->data + hdroff);
-	inet_proto_csum_replace2(&hdr->checksum, skb,
-				 hdr->un.echo.id, tuple->src.u.icmp.id, false);
-	hdr->un.echo.id = tuple->src.u.icmp.id;
+	if (hdr->type == ICMP_ECHO || hdr->type == ICMP_ECHOREPLY) {
+		inet_proto_csum_replace2(&hdr->checksum, skb,
+					 hdr->un.echo.id, tuple->src.u.icmp.id,
+					 false);
+		hdr->un.echo.id = tuple->src.u.icmp.id;
+	}
 	return true;
 }
 
-- 
2.20.1


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2020-01-14  7:26 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-14  7:25 [NET] netfilter: nat: fix ICMP header corruption on ICMP errors Eyal Birger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).