Commit 61177e91 authored by Eyal Birger's avatar Eyal Birger Committed by Pablo Neira Ayuso

netfilter: nat: fix ICMP header corruption on ICMP errors

Commit 8303b7e8 ("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 has an 'id' field which
is not correct for all types of ICMP messages.

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 messages that have this
semantic.
Reported-by: default avatarShmulik Ladkani <shmulik.ladkani@gmail.com>
Fixes: 8303b7e8 ("netfilter: nat: fix spurious connection timeouts")
Signed-off-by: default avatarEyal Birger <eyal.birger@gmail.com>
Acked-by: default avatarFlorian Westphal <fw@strlen.de>
Signed-off-by: default avatarPablo Neira Ayuso <pablo@netfilter.org>
parent 335178d5
...@@ -233,6 +233,19 @@ icmp_manip_pkt(struct sk_buff *skb, ...@@ -233,6 +233,19 @@ icmp_manip_pkt(struct sk_buff *skb,
return false; return false;
hdr = (struct icmphdr *)(skb->data + hdroff); hdr = (struct icmphdr *)(skb->data + hdroff);
switch (hdr->type) {
case ICMP_ECHO:
case ICMP_ECHOREPLY:
case ICMP_TIMESTAMP:
case ICMP_TIMESTAMPREPLY:
case ICMP_INFO_REQUEST:
case ICMP_INFO_REPLY:
case ICMP_ADDRESS:
case ICMP_ADDRESSREPLY:
break;
default:
return true;
}
inet_proto_csum_replace2(&hdr->checksum, skb, 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, false);
hdr->un.echo.id = tuple->src.u.icmp.id; hdr->un.echo.id = tuple->src.u.icmp.id;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment