Summary: | pf NAT translates ICMP type 3 packects incorrectly | ||
---|---|---|---|
Product: | Base System | Reporter: | Alexey Pereklad <mybox> |
Component: | bin | Assignee: | Kristof Provost <kp> |
Status: | Closed FIXED | ||
Severity: | Affects Only Me | CC: | admin, clbuisson, franco, kp, kredaxx, maximos, mybox, pi, tablosazi.farahan |
Priority: | --- | ||
Version: | 10.3-STABLE | ||
Hardware: | Any | ||
OS: | Any |
Description
Alexey Pereklad
2015-07-13 09:10:38 UTC
I have the exact same problem on: FreeBSD r1 10.2-RELEASE-p5 FreeBSD 10.2-RELEASE-p5 #0: Sun Oct 11 14:19:57 CEST 2015 See https://lists.freebsd.org/pipermail/freebsd-pf/2016-May/008047.html for a patch. This patch is not fully tested. releng/10.3. --- sys/netpfil/pf/pf.c.orig 2016-05-21 17:57:29.420602000 +0300 +++ sys/netpfil/pf/pf.c 2016-05-22 00:54:16.043961000 +0300 @@ -4793,8 +4793,7 @@ pf_test_state_icmp(struct pf_state **sta &nk->addr[pd2.didx], pd2.af) || nk->port[pd2.didx] != th.th_dport) pf_change_icmp(pd2.dst, &th.th_dport, - NULL, /* XXX Inbound NAT? */ - &nk->addr[pd2.didx], + saddr, &nk->addr[pd2.didx], nk->port[pd2.didx], NULL, pd2.ip_sum, icmpsum, pd->ip_sum, 0, pd2.af); @@ -4866,8 +4865,7 @@ pf_test_state_icmp(struct pf_state **sta &nk->addr[pd2.didx], pd2.af) || nk->port[pd2.didx] != uh.uh_dport) pf_change_icmp(pd2.dst, &uh.uh_dport, - NULL, /* XXX Inbound NAT? */ - &nk->addr[pd2.didx], + saddr, &nk->addr[pd2.didx], nk->port[pd2.didx], &uh.uh_sum, pd2.ip_sum, icmpsum, pd->ip_sum, 1, pd2.af); @@ -4934,8 +4932,7 @@ pf_test_state_icmp(struct pf_state **sta &nk->addr[pd2.didx], pd2.af) || nk->port[pd2.didx] != iih.icmp_id) pf_change_icmp(pd2.dst, &iih.icmp_id, - NULL, /* XXX Inbound NAT? */ - &nk->addr[pd2.didx], + saddr, &nk->addr[pd2.didx], nk->port[pd2.didx], NULL, pd2.ip_sum, icmpsum, pd->ip_sum, 0, AF_INET); @@ -4987,8 +4984,7 @@ pf_test_state_icmp(struct pf_state **sta &nk->addr[pd2.didx], pd2.af) || nk->port[pd2.didx] != iih.icmp6_id) pf_change_icmp(pd2.dst, &iih.icmp6_id, - NULL, /* XXX Inbound NAT? */ - &nk->addr[pd2.didx], + saddr, &nk->addr[pd2.didx], nk->port[pd2.didx], NULL, pd2.ip_sum, icmpsum, pd->ip_sum, 0, AF_INET6); @@ -5027,8 +5023,7 @@ pf_test_state_icmp(struct pf_state **sta if (PF_ANEQ(pd2.dst, &nk->addr[pd2.didx], pd2.af)) - pf_change_icmp(pd2.src, NULL, - NULL, /* XXX Inbound NAT? */ + pf_change_icmp(pd2.dst, NULL, saddr, &nk->addr[pd2.didx], 0, NULL, pd2.ip_sum, icmpsum, pd->ip_sum, 0, pd2.af); A commit references this bug: Author: kp Date: Mon May 23 12:41:29 UTC 2016 New revision: 300501 URL: https://svnweb.freebsd.org/changeset/base/300501 Log: pf: Fix ICMP translation Fix ICMP source address rewriting in rdr scenarios. PR: 201519 Submitted by: Max <maximos@als.nnov.ru> MFC after: 1 week Changes: head/sys/netpfil/pf/pf.c (In reply to Max from comment #3) Awesome work Max! I'll try to MFC this to stable/10 next week. (In reply to Kristof Provost from comment #5) https://svnweb.freebsd.org/base/head/sys/netpfil/pf/pf.c?annotate=300501&pathrev=300501#l5017 should be "pf_change_icmp(pd2.dst, NULL, saddr,", not "pf_change_icmp(pd2.src, NULL, saddr," A commit references this bug: Author: kp Date: Mon May 23 13:59:49 UTC 2016 New revision: 300508 URL: https://svnweb.freebsd.org/changeset/base/300508 Log: pf: Fix more ICMP mistranslation In the default case fix the substitution of the destination address. PR: 201519 Submitted by: Max <maximos@als.nnov.ru> MFC after: 1 week Changes: head/sys/netpfil/pf/pf.c A commit references this bug: Author: kp Date: Mon May 30 01:21:44 UTC 2016 New revision: 300979 URL: https://svnweb.freebsd.org/changeset/base/300979 Log: MFC 300501, 300508 pf: Fix ICMP translation Fix ICMP source address rewriting in rdr scenarios. pf: Fix more ICMP mistranslation In the default case fix the substitution of the destination address. PR: 201519 Submitted by: Max <maximos@als.nnov.ru> Changes: _U stable/10/ stable/10/sys/netpfil/pf/pf.c Upgrading my Router/firwall from 9.3-STABLE svn 299225 to 10.3-STABLE svn 303269 I found that NATed traceroute's from the internal network to an external system displayed the IPv4 addresses/names of the final destination system instead of the IPv4 addresses/names of the intermediate systems/routers. I reverted 300979 and obtained correct traceroute addresses/name display. So I dare think that the bug cannot be closed. (In reply to clbuisson from comment #9) I'm afraid I don't understand what the problem is. Can you add a description of your network setup, the trace route output and a network capture (please specify where in the network the capture was made)? There is nothing complicated in my setup ! 1. An Internal network with "private" IPv4 addresses 2. A Gateway/Router/Firewall connected to this internal network, and to the Internet (ADSL), and NATing the traffic betwwen 1 and 3 3. The Internet with any system, for exemple www.freebsd.org On a system on the internal network, if I do traceroute www.freebsd.org I get - first line: the internal address/name of the gateway (OK) - a number of lines, one for each intermediate router on the Internet, but labelled with the address/name of www.freebsd.org (!OK) - last line: the address/name of www.freebsd.org (OK) Details seem irrelevant (anyone can find the address of www/freebsd.org ..), and the effect of outgoing NAT on UDP or ICMP (in case of traceroute -I) is supposed known. It is clear that the bug is in the NAT of the ICMP TIME_EXCEEDED received from the Internet (invalid substitution of the address of the responding router with address of the traceroute target). (In reply to clbuisson from comment #11) I'm unable to reproduce the described behaviour on my system. Please make a network capture so we can look in detail at what's going wrong. (In reply to clbuisson from comment #11) Show please your network diagram - L1 and L2. As well as the route to the external IP. I'm on FreeBSD 10.3-STABLE r302074 bunch of miracles happening with traceroute :( Only I still used carp, route-to with several uplinks ... (In reply to Vladislav V. Prodan from comment #13) I've been talking to clbuisson@orange.fr in private, and it looks like there is indeed something wrong in 10.3, but not in 11 or 12. Right now I have no idea why. I can confirm that the patches break traceroute output on 10.3. Can this be reopened? Yes, it's on the top of my list. I suspect I know what the cause is. stable/10 does not include the fix for 204005, so PF_ANEQ() doesn't work correctly. Merging r289932 and r289940 should fix the problem. I'm currently building a version of stable/10 with the fix, if I'm correct this will be fixed soon. This should be fixed as of r304293 in stable/10. Can one of the affected users confirm so we can close? Running now with a patched kernel: first (quick) tests are positive ! Thank you, for your work Looks good, thanks! MARKED AS SPAM |