[<prev] [next>] [day] [month] [year] [list]
Message-Id: <20200114072548.23426-1-eyal.birger@gmail.com>
Date: Tue, 14 Jan 2020 09:25:48 +0200
From: Eyal Birger <eyal.birger@...il.com>
To: pablo@...filter.org, kadlec@...filter.org, fw@...len.de,
davem@...emloft.net, netfilter-devel@...r.kernel.org,
coreteam@...filter.org, netdev@...r.kernel.org
Cc: Eyal Birger <eyal.birger@...il.com>,
Shmulik Ladkani <shmulik.ladkani@...il.com>
Subject: [NET] netfilter: nat: fix ICMP header corruption on ICMP errors
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@...il.com>
Fixes: 8303b7e8f018 ("netfilter: nat: fix spurious connection timeouts")
Signed-off-by: Eyal Birger <eyal.birger@...il.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
Powered by blists - more mailing lists