From: Pablo Neira Ayuso <pablo@netfilter.org>
Hi David,
The following batch contains Netfilter fixes for 3.8-rc1. They are
a mixture of old bugs that have passed unnoticed (I'll pass these to
stable) and more fresh ones from the previous merge window, they are:
* Fix for MAC address in 6in4 tunnels via NFLOG that results in ulogd
showing up wrong address, from Bob Hockney.
* Fix a comment in nf_conntrack_ipv6, from Florent Fourcot.
* Fix a leak an error path in ctnetlink while creating an expectation,
from Jesper Juhl.
* Fix missing ICMP time exceeded in the IPv6 defragmentation code, from
Haibo Xi.
* Fix inconsistent handling of routing changes in MASQUERADE for the
new connections case, from Andrew Collins.
* Fix a missing skb_reset_transport in ip[6]t_REJECT that leads to
crashes in the ixgbe driver (since it seems to access the transport
header with TSO enabled), from Mukund Jampala.
* Recover obsoleted NOTRACK target by including it into the CT and spot
a warning via printk about being obsoleted. Many people don't check the
scheduled to be removal file under Documentation, so we follow some
less agressive approach to kill this in a year or so. Spotted by Florian
Westphal, patch from myself.
* Fix race condition in xt_hashlimit that allows to create two or more
entries, from myself.
* Fix crash if the CT is used due to the recently added facilities to
consult the dying and unconfirmed conntrack lists, from myself.
That's basically it, you can pull these changes from:
git://1984.lsi.us.es/nf master
Have a nice entrance for the new year. Thanks.
Andrew Collins (1):
netfilter: nf_nat: Also handle non-ESTABLISHED routing changes in MASQUERADE
Bob Hockney (1):
netfilter: nfnetlink_log: fix mac address for 6in4 tunnels
Florent Fourcot (1):
netfilter: nf_conntrack_ipv6: fix comment for packets without data
Haibo Xi (1):
netfilter: nf_ct_reasm: fix conntrack reassembly expire code
Jesper Juhl (1):
netfilter: ctnetlink: fix leak in error path of ctnetlink_create_expect
Mukund Jampala (1):
netfilter: ip[6]t_REJECT: fix wrong transport header pointer in TCP reset
Pablo Neira Ayuso (4):
netfilter: xt_CT: fix crash while destroy ct templates
netfilter: nfnetlink_log: fix possible compilation issue due to missing include
netfilter: xt_CT: recover NOTRACK target support
netfilter: xt_hashlimit: fix race that results in duplicated entries
Vitaly E. Lavrov (2):
netfilter: xt_recent: fix namespace destroy path
netfilter: xt_hashlimit: fix namespace destroy path
include/net/netns/conntrack.h | 1 +
include/net/netns/x_tables.h | 1 +
net/ipv4/netfilter/ipt_REJECT.c | 1 +
net/ipv4/netfilter/iptable_nat.c | 15 ++++--
net/ipv6/netfilter/ip6t_REJECT.c | 1 +
net/ipv6/netfilter/ip6table_nat.c | 15 ++++--
net/ipv6/netfilter/nf_conntrack_l3proto_ipv6.c | 4 +-
net/ipv6/netfilter/nf_conntrack_reasm.c | 5 +-
net/netfilter/Kconfig | 4 ++
net/netfilter/nf_conntrack_core.c | 2 +
net/netfilter/nf_conntrack_netlink.c | 2 +-
net/netfilter/nfnetlink_log.c | 16 +++++--
net/netfilter/xt_CT.c | 58 +++++++++++++++++++++++-
net/netfilter/xt_hashlimit.c | 54 ++++++++++++++++++----
net/netfilter/xt_recent.c | 20 ++++++--
15 files changed, 169 insertions(+), 30 deletions(-)
--
1.7.10.4
From: Andrew Collins <redacted>
Since (a0ecb85 netfilter: nf_nat: Handle routing changes in MASQUERADE
target), the MASQUERADE target handles routing changes which affect
the output interface of a connection, but only for ESTABLISHED
connections. It is also possible for NEW connections which
already have a conntrack entry to be affected by routing changes.
This adds a check to drop entries in the NEW+conntrack state
when the oif has changed.
Signed-off-by: Andrew Collins <redacted>
Acked-by: Jozsef Kadlecsik <redacted>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
net/ipv4/netfilter/iptable_nat.c | 15 ++++++++++-----
net/ipv6/netfilter/ip6table_nat.c | 15 ++++++++++-----
2 files changed, 20 insertions(+), 10 deletions(-)
@@ -124,23 +124,28 @@ nf_nat_ipv4_fn(unsigned int hooknum,ret=nf_nat_rule_find(skb,hooknum,in,out,ct);if(ret!=NF_ACCEPT)returnret;-}else+}else{pr_debug("Already setup manip %s for ct %p\n",maniptype==NF_NAT_MANIP_SRC?"SRC":"DST",ct);+if(nf_nat_oif_changed(hooknum,ctinfo,nat,out))+gotooif_changed;+}break;default:/* ESTABLISHED */NF_CT_ASSERT(ctinfo==IP_CT_ESTABLISHED||ctinfo==IP_CT_ESTABLISHED_REPLY);-if(nf_nat_oif_changed(hooknum,ctinfo,nat,out)){-nf_ct_kill_acct(ct,ctinfo,skb);-returnNF_DROP;-}+if(nf_nat_oif_changed(hooknum,ctinfo,nat,out))+gotooif_changed;}returnnf_nat_packet(ct,ctinfo,hooknum,skb);++oif_changed:+nf_ct_kill_acct(ct,ctinfo,skb);+returnNF_DROP;}staticunsignedint
@@ -127,23 +127,28 @@ nf_nat_ipv6_fn(unsigned int hooknum,ret=nf_nat_rule_find(skb,hooknum,in,out,ct);if(ret!=NF_ACCEPT)returnret;-}else+}else{pr_debug("Already setup manip %s for ct %p\n",maniptype==NF_NAT_MANIP_SRC?"SRC":"DST",ct);+if(nf_nat_oif_changed(hooknum,ctinfo,nat,out))+gotooif_changed;+}break;default:/* ESTABLISHED */NF_CT_ASSERT(ctinfo==IP_CT_ESTABLISHED||ctinfo==IP_CT_ESTABLISHED_REPLY);-if(nf_nat_oif_changed(hooknum,ctinfo,nat,out)){-nf_ct_kill_acct(ct,ctinfo,skb);-returnNF_DROP;-}+if(nf_nat_oif_changed(hooknum,ctinfo,nat,out))+gotooif_changed;}returnnf_nat_packet(ct,ctinfo,hooknum,skb);++oif_changed:+nf_ct_kill_acct(ct,ctinfo,skb);+returnNF_DROP;}staticunsignedint
From: Pablo Neira Ayuso <pablo@netfilter.org>
In (d871bef netfilter: ctnetlink: dump entries from the dying and
unconfirmed lists), we assume that all conntrack objects are
inserted in any of the existing lists. However, template conntrack
objects were not. This results in hitting BUG_ON in the
destroy_conntrack path while removing a rule that uses the CT target.
This patch fixes the situation by adding the template lists, which
is where template conntrack objects reside now.
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
include/net/netns/conntrack.h | 1 +
net/netfilter/nf_conntrack_core.c | 2 ++
net/netfilter/xt_CT.c | 8 ++++++++
3 files changed, 11 insertions(+)
@@ -1534,6 +1535,7 @@ static int nf_conntrack_init_net(struct net *net)atomic_set(&net->ct.count,0);INIT_HLIST_NULLS_HEAD(&net->ct.unconfirmed,UNCONFIRMED_NULLS_VAL);INIT_HLIST_NULLS_HEAD(&net->ct.dying,DYING_NULLS_VAL);+INIT_HLIST_NULLS_HEAD(&net->ct.tmpl,TEMPLATE_NULLS_VAL);net->ct.stat=alloc_percpu(structip_conntrack_stat);if(!net->ct.stat){ret=-ENOMEM;
@@ -149,6 +149,10 @@ static int xt_ct_tg_check_v0(const struct xt_tgchk_param *par)__set_bit(IPS_TEMPLATE_BIT,&ct->status);__set_bit(IPS_CONFIRMED_BIT,&ct->status);++/* Overload tuple linked list to put us in template list. */+hlist_nulls_add_head_rcu(&ct->tuplehash[IP_CT_DIR_ORIGINAL].hnnode,+&par->net->ct.tmpl);out:info->ct=ct;return0;
@@ -289,6 +293,10 @@ static int xt_ct_tg_check_v1(const struct xt_tgchk_param *par)__set_bit(IPS_TEMPLATE_BIT,&ct->status);__set_bit(IPS_CONFIRMED_BIT,&ct->status);++/* Overload tuple linked list to put us in template list. */+hlist_nulls_add_head_rcu(&ct->tuplehash[IP_CT_DIR_ORIGINAL].hnnode,+&par->net->ct.tmpl);out:info->ct=ct;return0;
From: Pablo Neira Ayuso <pablo@netfilter.org>
Two packets may race to create the same entry in the hashtable,
double check if this packet lost race. This double checking only
happens in the path of the packet that creates the hashtable for
first time.
Note that, with this patch, no packet drops occur if the race happens.
Reported-by: Feng Gao <redacted>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
net/netfilter/xt_hashlimit.c | 25 +++++++++++++++++++++----
1 file changed, 21 insertions(+), 4 deletions(-)
@@ -157,11 +157,22 @@ dsthash_find(const struct xt_hashlimit_htable *ht,/* allocate dsthash_ent, initialize dst, put in htable and lock it */staticstructdsthash_ent*dsthash_alloc_init(structxt_hashlimit_htable*ht,-conststructdsthash_dst*dst)+conststructdsthash_dst*dst,bool*race){structdsthash_ent*ent;spin_lock(&ht->lock);++/* Two or more packets may race to create the same entry in the+*hashtable,doublecheckifthispacketlostrace.+*/+ent=dsthash_find(ht,dst);+if(ent!=NULL){+spin_unlock(&ht->lock);+*race=true;+returnent;+}+/* initialize hash with random val at the time we allocate*thefirsthashtableentry*/if(unlikely(!ht->rnd_initialized)){
From: "Vitaly E. Lavrov" <redacted>
recent_net_exit() is called before recent_mt_destroy() in the
destroy path of network namespaces. Make sure there are no entries
in the parent proc entry xt_recent before removing it.
Signed-off-by: Vitaly E. Lavrov <redacted>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
net/netfilter/xt_recent.c | 20 ++++++++++++++++----
1 file changed, 16 insertions(+), 4 deletions(-)
@@ -615,6 +616,20 @@ static int __net_init recent_proc_net_init(struct net *net)staticvoid__net_exitrecent_proc_net_exit(structnet*net){+structrecent_net*recent_net=recent_pernet(net);+structrecent_table*t;++/* recent_net_exit() is called before recent_mt_destroy(). Make sure+*thattheparentxt_recentprocentryisisemptybeforetryingto+*removeit.+*/+spin_lock_bh(&recent_lock);+list_for_each_entry(t,&recent_net->tables,list)+remove_proc_entry(t->name,recent_net->xt_recent);++recent_net->xt_recent=NULL;+spin_unlock_bh(&recent_lock);+proc_net_remove(net,"xt_recent");}#else
@@ -638,9 +653,6 @@ static int __net_init recent_net_init(struct net *net)staticvoid__net_exitrecent_net_exit(structnet*net){-structrecent_net*recent_net=recent_pernet(net);--BUG_ON(!list_empty(&recent_net->tables));recent_proc_net_exit(net);}
From: "Vitaly E. Lavrov" <redacted>
recent_net_exit() is called before recent_mt_destroy() in the
destroy path of network namespaces. Make sure there are no entries
in the parent proc entry xt_recent before removing it.
Signed-off-by: Vitaly E. Lavrov <redacted>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
net/netfilter/xt_hashlimit.c | 29 +++++++++++++++++++++++++----
1 file changed, 25 insertions(+), 4 deletions(-)
@@ -873,6 +876,27 @@ static int __net_init hashlimit_proc_net_init(struct net *net)staticvoid__net_exithashlimit_proc_net_exit(structnet*net){+structxt_hashlimit_htable*hinfo;+structhlist_node*pos;+structproc_dir_entry*pde;+structhashlimit_net*hashlimit_net=hashlimit_pernet(net);++/* recent_net_exit() is called before recent_mt_destroy(). Make sure+*thattheparentxt_recentprocentryisisemptybeforetryingto+*removeit.+*/+mutex_lock(&hashlimit_mutex);+pde=hashlimit_net->ipt_hashlimit;+if(pde==NULL)+pde=hashlimit_net->ip6t_hashlimit;++hlist_for_each_entry(hinfo,pos,&hashlimit_net->htables,node)+remove_proc_entry(hinfo->pde->name,pde);++hashlimit_net->ipt_hashlimit=NULL;+hashlimit_net->ip6t_hashlimit=NULL;+mutex_unlock(&hashlimit_mutex);+proc_net_remove(net,"ipt_hashlimit");#if IS_ENABLED(CONFIG_IP6_NF_IPTABLES)proc_net_remove(net,"ip6t_hashlimit");
@@ -889,9 +913,6 @@ static int __net_init hashlimit_net_init(struct net *net)staticvoid__net_exithashlimit_net_exit(structnet*net){-structhashlimit_net*hashlimit_net=hashlimit_pernet(net);--BUG_ON(!hlist_empty(&hashlimit_net->htables));hashlimit_proc_net_exit(net);}
@@ -81,8 +81,8 @@ static int ipv6_get_l4proto(const struct sk_buff *skb, unsigned int nhoff,}protoff=ipv6_skip_exthdr(skb,extoff,&nexthdr,&frag_off);/*-*(protoff==skb->len)meanthatthepacketdoesn'thavenodata-*exceptofIPv6&extheaders.butit'strackedanyway.-YK+*(protoff==skb->len)meansthepackethasnotdata,just+*IPv6andpossiblyextensionsheaders,butitistrackedanyway*/if(protoff<0||(frag_off&htons(~0x7))!=0){pr_debug("ip6_conntrack_core: can't find proto in pkt\n");
From: Bob Hockney <redacted>
For tunnelled ipv6in4 packets, the LOG target (xt_LOG.c) adjusts
the start of the mac field to start at the ethernet header instead
of the ipv4 header for the tunnel. This patch conforms what is
passed by the NFLOG target through nfnetlink to what the LOG target
does. Code borrowed from xt_LOG.c.
Signed-off-by: Bob Hockney <redacted>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
net/netfilter/nfnetlink_log.c | 15 ++++++++++++---
1 file changed, 12 insertions(+), 3 deletions(-)
From: Haibo Xi <redacted>
Commit b836c99fd6c9 (ipv6: unify conntrack reassembly expire
code with standard one) use the standard IPv6 reassembly
code(ip6_expire_frag_queue) to handle conntrack reassembly expire.
In ip6_expire_frag_queue, it invoke dev_get_by_index_rcu to get
which device received this expired packet.so we must save ifindex
when NF_conntrack get this packet.
With this patch applied, I can see ICMP Time Exceeded sent
from the receiver when the sender sent out 1/2 fragmented
IPv6 packet.
Signed-off-by: Haibo Xi <redacted>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
net/ipv6/netfilter/nf_conntrack_reasm.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
From: Pablo Neira Ayuso <pablo@netfilter.org>
In (0c36b48 netfilter: nfnetlink_log: fix mac address for 6in4 tunnels)
the include file that defines ARPD_SIT was missing. This passed unnoticed
during my tests (I did not hit this problem here).
net/netfilter/nfnetlink_log.c: In function '__build_packet_message':
net/netfilter/nfnetlink_log.c:494:25: error: 'ARPHRD_SIT' undeclared (first use in this function)
net/netfilter/nfnetlink_log.c:494:25: note: each undeclared identifier is reported only once for
+each function it appears in
Reported-by: kbuild test robot <redacted>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
net/netfilter/nfnetlink_log.c | 1 +
1 file changed, 1 insertion(+)
From: Pablo Neira Ayuso <pablo@netfilter.org>
Florian Westphal reported that the removal of the NOTRACK target
(9655050 netfilter: remove xt_NOTRACK) is breaking some existing
setups.
That removal was scheduled for removal since long time ago as
described in Documentation/feature-removal-schedule.txt
What: xt_NOTRACK
Files: net/netfilter/xt_NOTRACK.c
When: April 2011
Why: Superseded by xt_CT
Still, people may have not notice / may have decided to stick to an
old iptables version. I agree with him in that some more conservative
approach by spotting some printk to warn users for some time is less
agressive.
Current iptables 1.4.16.3 already contains the aliasing support
that makes it point to the CT target, so upgrading would fix it.
Still, the policy so far has been to avoid pushing our users to
upgrade.
As a solution, this patch recovers the NOTRACK target inside the CT
target and it now spots a warning.
Reported-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
include/net/netns/x_tables.h | 1 +
net/netfilter/Kconfig | 4 ++++
net/netfilter/xt_CT.c | 50 +++++++++++++++++++++++++++++++++++++++++-
3 files changed, 54 insertions(+), 1 deletion(-)
From: Jesper Juhl <redacted>
This patch fixes a leak in one of the error paths of
ctnetlink_create_expect if no helper and no timeout is specified.
Signed-off-by: Jesper Juhl <redacted>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
net/netfilter/nf_conntrack_netlink.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)