Skip to content

Commit 61177e9

Browse files
ebirgerummakynes
authored andcommitted
netfilter: nat: fix ICMP header corruption on ICMP errors
Commit 8303b7e ("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: Shmulik Ladkani <[email protected]> Fixes: 8303b7e ("netfilter: nat: fix spurious connection timeouts") Signed-off-by: Eyal Birger <[email protected]> Acked-by: Florian Westphal <[email protected]> Signed-off-by: Pablo Neira Ayuso <[email protected]>
1 parent 335178d commit 61177e9

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

net/netfilter/nf_nat_proto.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,19 @@ icmp_manip_pkt(struct sk_buff *skb,
233233
return false;
234234

235235
hdr = (struct icmphdr *)(skb->data + hdroff);
236+
switch (hdr->type) {
237+
case ICMP_ECHO:
238+
case ICMP_ECHOREPLY:
239+
case ICMP_TIMESTAMP:
240+
case ICMP_TIMESTAMPREPLY:
241+
case ICMP_INFO_REQUEST:
242+
case ICMP_INFO_REPLY:
243+
case ICMP_ADDRESS:
244+
case ICMP_ADDRESSREPLY:
245+
break;
246+
default:
247+
return true;
248+
}
236249
inet_proto_csum_replace2(&hdr->checksum, skb,
237250
hdr->un.echo.id, tuple->src.u.icmp.id, false);
238251
hdr->un.echo.id = tuple->src.u.icmp.id;

0 commit comments

Comments
 (0)