netfilter fixes for net
Subsystems (4)
Pablo Neira Ayuso
maintainercover netfilter fixes for net
Hi David,
The following patchset contains netfilter updates for your net tree, they are:
1) Fix refcount leak when dumping the dying/unconfirmed conntrack lists, from Florian Westphal.
2) Fix crash in NAT when removing a netnamespace, also from Florian.
3) Fix a crash in IPVS when trying to remove an estimator out of the sysctl scope, from Julian Anastasov.
4) Add zone attribute to the routing to calculate the message size in ctnetlink events, from Ken-ichirou MATSUZAWA.
5) Another fix for the dying/unconfirmed list which was preventing to dump more than one memory page of entries (~17 entries in x86_64).
6) Fix missing RCU-safe list insertion in the rule replacement code in nf_tables.
7) Since the new transaction infrastructure is in place, we have to upgrade the chain use counter from u16 to u32 to avoid overflow after more than 2^16 rules are added.
8) Fix refcount leak when replacing rule in nf_tables. This problem was also introduced in new transaction.
9) Call the ->destroy() callback when releasing nft-xt rules to fix module refcount leaks.
10) Set the family in the netlink messages that contain set elements in nf_tables to make it consistent with other object types.
11) Don't dump NAT port information if it is unset in nft_nat.
12) Update the MAINTAINERS file, I have merged the ebtables entry into netfilter. While at it, also removed the netfilter users mailing list, the development list should be enough.
You can pull these changes from:
git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf.git
Thanks!
----------------------------------------------------------------
The following changes since commit 7171511eaec5bf23fb06078f59784a3a0626b38f:
Linux 3.16-rc1 (2014-06-15 17:45:28 -1000)
are available in the git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf.git master
for you to fetch changes up to db9cf3a345d310bd459f369e8fa5f039076293f2:
MAINTAINERS: merge ebtables into netfilter entry (2014-06-18 11:27:03 +0200)
----------------------------------------------------------------
Florian Westphal (2):
netfilter: ctnetlink: fix refcnt leak in dying/unconfirmed list dumper
netfilter: nf_nat: fix oops on netns removal
Julian Anastasov (1):
ipvs: stop tot_stats estimator only under CONFIG_SYSCTL
Ken-ichirou MATSUZAWA (1):
netfilter: ctnetlink: add zone size to length
Pablo Neira Ayuso (10):
netfilter: ctnetlink: fix dumping of dying/unconfirmed conntracks
netfilter: nf_tables: use RCU-safe list insertion when replacing rules
netfilter: nf_tables: use u32 for chain use counter
netfilter: nf_tables: decrement chain use counter when replacing rules
netfilter: nf_tables: fix wrong type in transaction when replacing rules
netfilter: nft_compat: call {target, match}->destroy() to cleanup entry
netfilter: nf_tables: indicate family when dumping set elements
netfilter: nft_nat: don't dump port information if unset Merge branch 'ipvs'
MAINTAINERS: merge ebtables into netfilter entry
MAINTAINERS | 11 +---------- include/net/netfilter/nf_tables.h | 6 +++--- net/netfilter/ipvs/ip_vs_ctl.c | 2 +- net/netfilter/nf_conntrack_netlink.c | 20 ++++++++++++------- net/netfilter/nf_nat_core.c | 35 +++++++++++++++++++++++++++++++++- net/netfilter/nf_tables_api.c | 11 ++++++++--- net/netfilter/nft_compat.c | 18 +++++++++++++++++ net/netfilter/nft_nat.c | 14 ++++++++------ 8 files changed, 86 insertions(+), 31 deletions(-)
Pablo Neira Ayuso
maintainerPATCH 1/13 ipvs: stop tot_stats estimator only under CONFIG_SYSCTL
From: Julian Anastasov <[email protected]>
The tot_stats estimator is started only when CONFIG_SYSCTL is defined. But it is stopped without checking CONFIG_SYSCTL. Fix the crash by moving ip_vs_stop_estimator into ip_vs_control_net_cleanup_sysctl.
The change is needed after commit 14e405461e664b ("IPVS: Add __ip_vs_control_{init,cleanup}_sysctl()") from 2.6.39.
--- net/netfilter/ipvs/ip_vs_ctl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/ipvs/ip_vs_ctl.c +1 -1
@@ -3778,6 +3778,7 @@ static void __net_exit ip_vs_control_net_cleanup_sysctl(struct net *net)cancel_delayed_work_sync (&ipvs->defense_work);cancel_work_sync (&ipvs->defense_work.work);unregister_net_sysctl_table (ipvs->sysctl_hdr); + ip_vs_stop_estimator(net, &ipvs->tot_stats); }#else
@@ -3840,7 +3841,6 @@ void __net_exit ip_vs_control_net_cleanup(struct net *net)struct netns_ipvs *ipvs =net_ipvs (net);ip_vs_trash_cleanup (net); -ip_vs_stop_estimator (net, &ipvs->tot_stats);ip_vs_control_net_cleanup_sysctl (net);remove_proc_entry ("ip_vs_stats_percpu" , net->proc_net);remove_proc_entry ("ip_vs_stats" , net->proc_net);
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 2/13 netfilter: ctnetlink: fix dumping of dying/unconfirmed conntracks
In reply to Pablo Neira AyusoThe dumping prematurely stops, it seems the callback argument that indicates that all entries have been dumped is set after iterating on the first cpu list. The dumping also may stop before the entire per-cpu list content is also dumped.
With this patch, conntrack -L dying now shows the dying list content again.
--- net/netfilter/nf_conntrack_netlink.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
net/netfilter/nf_conntrack_netlink.c +3 -5
@@ -1163,9 +1163,6 @@ ctnetlink_dump_list(struct sk_buff *skb, struct netlink_callback *cb, bool dyingif (cb->args[2 ])return 0 ; -if (cb->args[0 ] == nr_cpu_ids) -return 0 ; -for (cpu = cb->args[0 ]; cpu < nr_cpu_ids; cpu++) {struct ct_pcpu *pcpu;
@@ -1194,6 +1191,7 @@ restart:rcu_read_unlock ();if (res <0 ) {nf_conntrack_get (&ct->ct_general); + cb->args[0 ] = cpu; cb->args[1 ] = (unsigned long )ct;spin_unlock_bh (&pcpu->lock); goto out;
@@ -1202,10 +1200,10 @@ restart:if (cb->args[1 ]) { cb->args[1 ] =0 ; goto restart; - }else - cb->args[2 ] =1 ; + }spin_unlock_bh (&pcpu->lock); } + cb->args[2 ] =1 ; out:if (last)nf_ct_put (last);
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 3/13 netfilter: ctnetlink: fix refcnt leak in dying/unconfirmed list dumper
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
'last' keeps track of the ct that had its refcnt bumped during previous dump cycle. Thus it must not be overwritten until end-of-function.
Another (unrelated, theoretical) issue: Don't attempt to bump refcnt of a conntrack whose reference count is already 0. Such conntrack is being destroyed right now, its memory is freed once we release the percpu dying spinlock.
--- net/netfilter/nf_conntrack_netlink.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
net/netfilter/nf_conntrack_netlink.c +5 -3
@@ -1150,7 +1150,7 @@ static int ctnetlink_done_list(struct netlink_callback *cb)static int ctnetlink_dump_list (struct sk_buff *skb,struct netlink_callback *cb,bool dying) { -struct nf_conn *ct, *last =NULL ; +struct nf_conn *ct, *last;struct nf_conntrack_tuple_hash *h;struct hlist_nulls_node *n;struct nfgenmsg *nfmsg =nlmsg_data (cb->nlh);
@@ -1163,6 +1163,8 @@ ctnetlink_dump_list(struct sk_buff *skb, struct netlink_callback *cb, bool dyingif (cb->args[2 ])return 0 ; + last = (struct nf_conn *)cb->args[1 ]; +for (cpu = cb->args[0 ]; cpu < nr_cpu_ids; cpu++) {struct ct_pcpu *pcpu;
@@ -1171,7 +1173,6 @@ ctnetlink_dump_list(struct sk_buff *skb, struct netlink_callback *cb, bool dying pcpu =per_cpu_ptr (net->ct.pcpu_lists, cpu);spin_lock_bh (&pcpu->lock); - last = (struct nf_conn *)cb->args[1 ]; list = dying ? &pcpu->dying : &pcpu->unconfirmed; restart:hlist_nulls_for_each_entry (h, n, list, hnnode) {
@@ -1190,7 +1191,8 @@ restart: ct);rcu_read_unlock ();if (res <0 ) { -nf_conntrack_get (&ct->ct_general); +if (!atomic_inc_not_zero (&ct->ct_general.use)) +continue ; cb->args[0 ] = cpu; cb->args[1 ] = (unsigned long )ct;spin_unlock_bh (&pcpu->lock);
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 4/13 netfilter: nf_tables: use RCU-safe list insertion when replacing rules
In reply to Pablo Neira AyusoThe patch 5e94846 ("netfilter: nf_tables: add insert operation") did not include RCU-safe list insertion when replacing rules.
--- net/netfilter/nf_tables_api.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/nf_tables_api.c +1 -1
@@ -1796,7 +1796,7 @@ static int nf_tables_newrule(struct sock *nlsk, struct sk_buff *skb, goto err2; }nft_rule_disactivate_next (net, old_rule); -list_add_tail (&rule->list, &old_rule->list); +list_add_tail_rcu (&rule->list, &old_rule->list); }else { err = -ENOENT ; goto err2;
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 5/13 netfilter: nf_tables: use u32 for chain use counter
In reply to Pablo Neira AyusoSince 4fefee5 ("netfilter: nf_tables: allow to delete several objects from a batch"), every new rule bumps the chain use counter. However, this is limited to 16 bits, which means that it will overrun after 2^16 rules.
Use a u32 chain counter and check for overflows (just like we do for table objects).
--- include/net/netfilter/nf_tables.h | 6 +++--- net/netfilter/nf_tables_api.c | 3 +++ 2 files changed, 6 insertions(+), 3 deletions(-)
include/net/netfilter/nf_tables.h +3 -3
@@ -503,9 +503,9 @@ enum nft_chain_flags {* @net: net namespace that this chain belongs to * @table: table that this chain belongs to * @handle: chain handle -* @flags: bitmask of enum nft_chain_flags * @use: number of jump references to this chain * @level: length of longest path to this chain +* @flags: bitmask of enum nft_chain_flags * @name: name of the chain */ struct nft_chain {
@@ -514,9 +514,9 @@ struct nft_chain {struct net *net;struct nft_table *table;u64 handle; -u8 flags; -u16 use; +u32 use;u16 level; +u8 flags;char name[NFT_CHAIN_MAXNAMELEN ]; };
net/netfilter/nf_tables_api.c +3 -0
@@ -1730,6 +1730,9 @@ static int nf_tables_newrule(struct sock *nlsk, struct sk_buff *skb,if (!create || nlh->nlmsg_flags &NLM_F_REPLACE )return -EINVAL ; handle =nf_tables_alloc_handle (table); + +if (chain->use ==UINT_MAX ) +return -EOVERFLOW ; }if (nla[NFTA_RULE_POSITION ]) {
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 6/13 netfilter: nf_tables: decrement chain use counter when replacing rules
In reply to Pablo Neira AyusoThus, the chain use counter remains with the same value after the rule replacement.
--- net/netfilter/nf_tables_api.c | 2 ++ 1 file changed, 2 insertions(+)
net/netfilter/nf_tables_api.c +2 -0
@@ -1799,6 +1799,7 @@ static int nf_tables_newrule(struct sock *nlsk, struct sk_buff *skb, goto err2; }nft_rule_disactivate_next (net, old_rule); + chain->use--;list_add_tail_rcu (&rule->list, &old_rule->list); }else { err = -ENOENT ;
@@ -1829,6 +1830,7 @@ err3:list_del_rcu (&nft_trans_rule (trans)->list);nft_rule_clear (net,nft_trans_rule (trans));nft_trans_destroy (trans); + chain->use++; } err2:nf_tables_rule_destroy (&ctx, rule);
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 7/13 netfilter: nf_tables: fix wrong type in transaction when replacing rules
In reply to Pablo Neira AyusoIn b380e5c ("netfilter: nf_tables: add message type to transactions"), I used the wrong message type in the rule replacement case. The rule that is replaced needs to be handled as a deleted rule.
--- net/netfilter/nf_tables_api.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/nf_tables_api.c +1 -1
@@ -1792,7 +1792,7 @@ static int nf_tables_newrule(struct sock *nlsk, struct sk_buff *skb,if (nlh->nlmsg_flags &NLM_F_REPLACE ) {if (nft_rule_is_active_next (net, old_rule)) { - trans =nft_trans_rule_add (&ctx,NFT_MSG_NEWRULE , + trans =nft_trans_rule_add (&ctx,NFT_MSG_DELRULE , old_rule);if (trans ==NULL ) { err = -ENOMEM ;
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 8/13 netfilter: nft_compat: call {target, match}->destroy() to cleanup entry
In reply to Pablo Neira AyusoOtherwise, the reference to external objects (eg. modules) are not released when the rules are removed.
--- net/netfilter/nft_compat.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
net/netfilter/nft_compat.c +18 -0
@@ -195,6 +195,15 @@ static void nft_target_destroy(const struct nft_ctx *ctx, const struct nft_expr *expr) { struct xt_target *target = expr->ops->data; +void *info =nft_expr_priv (expr); +struct xt_tgdtor_param par; + + par.net = ctx->net; + par.target = target; + par.targinfo = info; + par.family = ctx->afi->family; +if (par.target->destroy !=NULL ) + par.target->destroy (&par);module_put (target->me); }
@@ -382,6 +391,15 @@ static void nft_match_destroy(const struct nft_ctx *ctx, const struct nft_expr *expr) { struct xt_match *match = expr->ops->data; +void *info =nft_expr_priv (expr); +struct xt_mtdtor_param par; + + par.net = ctx->net; + par.match = match; + par.matchinfo = info; + par.family = ctx->afi->family; +if (par.match->destroy !=NULL ) + par.match->destroy (&par);module_put (match->me); }
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 9/13 netfilter: nf_tables: indicate family when dumping set elements
In reply to Pablo Neira AyusoSet the nfnetlink header that indicates the family of this element.
--- net/netfilter/nf_tables_api.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/nf_tables_api.c +1 -1
@@ -2850,7 +2850,7 @@ static int nf_tables_dump_set(struct sk_buff *skb, struct netlink_callback *cb) goto nla_put_failure; nfmsg =nlmsg_data (nlh); - nfmsg->nfgen_family =NFPROTO_UNSPEC ; + nfmsg->nfgen_family = ctx.afi->family; nfmsg->version =NFNETLINK_V0 ; nfmsg->res_id =0 ;
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 10/13 netfilter: nft_nat: don't dump port information if unset
In reply to Pablo Neira AyusoDon't include port information attributes if they are unset.
--- net/netfilter/nft_nat.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)
net/netfilter/nft_nat.c +8 -6
@@ -175,12 +175,14 @@ static int nft_nat_dump(struct sk_buff *skb, const struct nft_expr *expr)if (nla_put_be32 (skb,NFTA_NAT_REG_ADDR_MAX ,htonl (priv->sreg_addr_max))) goto nla_put_failure; -if (nla_put_be32 (skb, -NFTA_NAT_REG_PROTO_MIN ,htonl (priv->sreg_proto_min))) - goto nla_put_failure; -if (nla_put_be32 (skb, -NFTA_NAT_REG_PROTO_MAX ,htonl (priv->sreg_proto_max))) - goto nla_put_failure; +if (priv->sreg_proto_min) { +if (nla_put_be32 (skb,NFTA_NAT_REG_PROTO_MIN , +htonl (priv->sreg_proto_min))) + goto nla_put_failure; +if (nla_put_be32 (skb,NFTA_NAT_REG_PROTO_MAX , +htonl (priv->sreg_proto_max))) + goto nla_put_failure; + }return 0 ; nla_put_failure:
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 11/13 netfilter: ctnetlink: add zone size to length
In reply to Pablo Neira AyusoFrom: Ken-ichirou MATSUZAWA <[email protected]>
--- net/netfilter/nf_conntrack_netlink.c | 6 ++++++ 1 file changed, 6 insertions(+)
net/netfilter/nf_conntrack_netlink.c +6 -0
@@ -597,6 +597,9 @@ ctnetlink_nlmsg_size(const struct nf_conn *ct)#ifdef CONFIG_NF_CONNTRACK_MARK + nla_total_size(sizeof(u_int32_t)) /* CTA_MARK */#endif +#ifdef CONFIG_NF_CONNTRACK_ZONES + + nla_total_size(sizeof(u_int16_t)) /* CTA_ZONE */ +#endif +ctnetlink_proto_size (ct) +ctnetlink_label_size (ct) ;
@@ -2040,6 +2043,9 @@ ctnetlink_nfqueue_build_size(const struct nf_conn *ct)#ifdef CONFIG_NF_CONNTRACK_MARK + nla_total_size(sizeof(u_int32_t)) /* CTA_MARK */#endif +#ifdef CONFIG_NF_CONNTRACK_ZONES + + nla_total_size(sizeof(u_int16_t)) /* CTA_ZONE */ +#endif +ctnetlink_proto_size (ct) ; }
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 12/13 netfilter: nf_nat: fix oops on netns removal
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
Quoting Samu Kallio:
Basically what's happening is, during netns cleanup, nf_nat_net_exit gets called before ipv4_net_exit. As I understand it, nf_nat_net_exit is supposed to kill any conntrack entries which have NAT context (through nf_ct_iterate_cleanup), but for some reason this doesn't happen (perhaps something else is still holding refs to those entries?).
When ipv4_net_exit is called, conntrack entries (including those with NAT context) are cleaned up, but the
nat_bysource hashtable is long gone - freed in nf_nat_net_exit. The bug happens when attempting to free a conntrack entry whose NAT hash 'prev' field points to a slot in the freed hash table (head for that bin).
We ignore conntracks with null nat bindings. But this is wrong, as these are in bysource hash table as well.
Restore nat-cleaning for the netns-is-being-removed case.
bug:
https://bugzilla.kernel.org/show_bug.cgi?id=65191
--- net/netfilter/nf_nat_core.c | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-)
net/netfilter/nf_nat_core.c +34 -1
@@ -525,6 +525,39 @@ static int nf_nat_proto_remove(struct nf_conn *i, void *data)return i->status &IPS_NAT_MASK ?1 :0 ; } +static int nf_nat_proto_clean (struct nf_conn *ct,void *data) +{ +struct nf_conn_nat *nat =nfct_nat (ct); + +if (nf_nat_proto_remove (ct, data)) +return 1 ; + +if (!nat || !nat->ct) +return 0 ; + +/* This netns is being destroyed, and conntrack has nat null binding. +* Remove it from bysource hash, as the table will be freed soon. +* +* Else, when the conntrack is destoyed, nf_nat_cleanup_conntrack() +* will delete entry from already-freed table. +*/ +if (!del_timer (&ct->timeout)) +return 1 ; + +spin_lock_bh (&nf_nat_lock); +hlist_del_rcu (&nat->bysource); + ct->status &= ~IPS_NAT_DONE_MASK ; + nat->ct =NULL ; +spin_unlock_bh (&nf_nat_lock); + +add_timer (&ct->timeout); + +/* don't delete conntrack. Although that would make things a lot +* simpler, we'd end up flushing all conntracks on nat rmmod. +*/ +return 0 ; +} +static void nf_nat_l4proto_clean (u8 l3proto,u8 l4proto) {struct nf_nat_proto_clean clean = {
@@ -795,7 +828,7 @@ static void __net_exit nf_nat_net_exit(struct net *net) {struct nf_nat_proto_clean clean = {}; -nf_ct_iterate_cleanup (net, &nf_nat_proto_remove, &clean,0 ,0 ); +nf_ct_iterate_cleanup (net, nf_nat_proto_clean, &clean,0 ,0 );synchronize_rcu ();nf_ct_free_hashtable (net->ct.nat_bysource, net->ct.nat_htable_size); }
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 13/13 MAINTAINERS: merge ebtables into netfilter entry
In reply to Pablo Neira AyusoMoreover, remove reference to the netfilter users mailing list, so they don't receive patches.
--- MAINTAINERS | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-)
MAINTAINERS +1 -10
@@ -3189,14 +3189,6 @@ L: [email protected] S: Maintained F: drivers/scsi/eata_pio.* -EBTABLES -L: [email protected] -W: http://ebtables.sourceforge.net/ -S: Orphan -F: include/linux/netfilter_bridge/ebt_*.h -F: include/uapi/linux/netfilter_bridge/ebt_*.h -F: net/bridge/netfilter/ebt*.c - EC100 MEDIA DRIVER M: Antti Palosaari <[email protected]> L: [email protected]
@@ -6105,12 +6097,11 @@ F: Documentation/networking/s2io.txt F: Documentation/networking/vxge.txt F: drivers/net/ethernet/neterion/ -NETFILTER/IPTABLES +NETFILTER ({IP,IP6,ARP,EB,NF}TABLES) M: Pablo Neira Ayuso <[email protected]> M: Patrick McHardy <[email protected]> M: Jozsef Kadlecsik <[email protected]> L: [email protected] -L: [email protected] L: [email protected] W: http://www.netfilter.org/ W: http://www.iptables.org/
Signature · 1 line
1.7.10.4
David Miller
maintainerFrom: Pablo Neira Ayuso <[email protected]>
Date: Wed, 18 Jun 2014 11:44:26 +0200
Quoted 2 lines
The following patchset contains netfilter updates for your net tree, they are:
...
Quoted 3 lines
You can pull these changes from:
git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf.git
Pulled, thanks Pablo.