netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 00/13] netfilter fixes for net
@ 2014-06-18  9:44 Pablo Neira Ayuso
  2014-06-18  9:44 ` [PATCH 01/13] ipvs: stop tot_stats estimator only under CONFIG_SYSCTL Pablo Neira Ayuso
                   ` (13 more replies)
  0 siblings, 14 replies; 15+ messages in thread
From: Pablo Neira Ayuso @ 2014-06-18  9:44 UTC (permalink / raw)
  To: netfilter-devel; +Cc: davem, netdev

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(-)

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [PATCH 01/13] ipvs: stop tot_stats estimator only under CONFIG_SYSCTL
  2014-06-18  9:44 [PATCH 00/13] netfilter fixes for net Pablo Neira Ayuso
@ 2014-06-18  9:44 ` Pablo Neira Ayuso
  2014-06-18  9:44 ` [PATCH 02/13] netfilter: ctnetlink: fix dumping of dying/unconfirmed conntracks Pablo Neira Ayuso
                   ` (12 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: Pablo Neira Ayuso @ 2014-06-18  9:44 UTC (permalink / raw)
  To: netfilter-devel; +Cc: davem, netdev

From: Julian Anastasov <ja@ssi.bg>

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.

Reported-by: Jet Chen <jet.chen@intel.com>
Tested-by: Jet Chen <jet.chen@intel.com>
Signed-off-by: Julian Anastasov <ja@ssi.bg>
Signed-off-by: Simon Horman <horms@verge.net.au>
---
 net/netfilter/ipvs/ip_vs_ctl.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
index c42e83d..581a658 100644
--- a/net/netfilter/ipvs/ip_vs_ctl.c
+++ b/net/netfilter/ipvs/ip_vs_ctl.c
@@ -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);
-- 
1.7.10.4

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH 02/13] netfilter: ctnetlink: fix dumping of dying/unconfirmed conntracks
  2014-06-18  9:44 [PATCH 00/13] netfilter fixes for net Pablo Neira Ayuso
  2014-06-18  9:44 ` [PATCH 01/13] ipvs: stop tot_stats estimator only under CONFIG_SYSCTL Pablo Neira Ayuso
@ 2014-06-18  9:44 ` Pablo Neira Ayuso
  2014-06-18  9:44 ` [PATCH 03/13] netfilter: ctnetlink: fix refcnt leak in dying/unconfirmed list dumper Pablo Neira Ayuso
                   ` (11 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: Pablo Neira Ayuso @ 2014-06-18  9:44 UTC (permalink / raw)
  To: netfilter-devel; +Cc: davem, netdev

The 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.

Fixes: b7779d06 ("netfilter: conntrack: spinlock per cpu to protect special lists.")
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
 net/netfilter/nf_conntrack_netlink.c |    8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/net/netfilter/nf_conntrack_netlink.c b/net/netfilter/nf_conntrack_netlink.c
index 5857963..ef0eedd 100644
--- a/net/netfilter/nf_conntrack_netlink.c
+++ b/net/netfilter/nf_conntrack_netlink.c
@@ -1163,9 +1163,6 @@ ctnetlink_dump_list(struct sk_buff *skb, struct netlink_callback *cb, bool dying
 	if (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);
-- 
1.7.10.4

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH 03/13] netfilter: ctnetlink: fix refcnt leak in dying/unconfirmed list dumper
  2014-06-18  9:44 [PATCH 00/13] netfilter fixes for net Pablo Neira Ayuso
  2014-06-18  9:44 ` [PATCH 01/13] ipvs: stop tot_stats estimator only under CONFIG_SYSCTL Pablo Neira Ayuso
  2014-06-18  9:44 ` [PATCH 02/13] netfilter: ctnetlink: fix dumping of dying/unconfirmed conntracks Pablo Neira Ayuso
@ 2014-06-18  9:44 ` Pablo Neira Ayuso
  2014-06-18  9:44 ` [PATCH 04/13] netfilter: nf_tables: use RCU-safe list insertion when replacing rules Pablo Neira Ayuso
                   ` (10 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: Pablo Neira Ayuso @ 2014-06-18  9:44 UTC (permalink / raw)
  To: netfilter-devel; +Cc: davem, netdev

From: Florian Westphal <fw@strlen.de>

'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.

Fixes: b7779d06 ('netfilter: conntrack: spinlock per cpu to protect special lists.')
Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
 net/netfilter/nf_conntrack_netlink.c |    8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/net/netfilter/nf_conntrack_netlink.c b/net/netfilter/nf_conntrack_netlink.c
index ef0eedd..70123f4 100644
--- a/net/netfilter/nf_conntrack_netlink.c
+++ b/net/netfilter/nf_conntrack_netlink.c
@@ -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 dying
 	if (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);
-- 
1.7.10.4

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH 04/13] netfilter: nf_tables: use RCU-safe list insertion when replacing rules
  2014-06-18  9:44 [PATCH 00/13] netfilter fixes for net Pablo Neira Ayuso
                   ` (2 preceding siblings ...)
  2014-06-18  9:44 ` [PATCH 03/13] netfilter: ctnetlink: fix refcnt leak in dying/unconfirmed list dumper Pablo Neira Ayuso
@ 2014-06-18  9:44 ` Pablo Neira Ayuso
  2014-06-18  9:44 ` [PATCH 05/13] netfilter: nf_tables: use u32 for chain use counter Pablo Neira Ayuso
                   ` (9 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: Pablo Neira Ayuso @ 2014-06-18  9:44 UTC (permalink / raw)
  To: netfilter-devel; +Cc: davem, netdev

The patch 5e94846 ("netfilter: nf_tables: add insert operation") did
not include RCU-safe list insertion when replacing rules.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
 net/netfilter/nf_tables_api.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c
index 624e083..ba37c10 100644
--- a/net/netfilter/nf_tables_api.c
+++ b/net/netfilter/nf_tables_api.c
@@ -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;
-- 
1.7.10.4

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH 05/13] netfilter: nf_tables: use u32 for chain use counter
  2014-06-18  9:44 [PATCH 00/13] netfilter fixes for net Pablo Neira Ayuso
                   ` (3 preceding siblings ...)
  2014-06-18  9:44 ` [PATCH 04/13] netfilter: nf_tables: use RCU-safe list insertion when replacing rules Pablo Neira Ayuso
@ 2014-06-18  9:44 ` Pablo Neira Ayuso
  2014-06-18  9:44 ` [PATCH 06/13] netfilter: nf_tables: decrement chain use counter when replacing rules Pablo Neira Ayuso
                   ` (8 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: Pablo Neira Ayuso @ 2014-06-18  9:44 UTC (permalink / raw)
  To: netfilter-devel; +Cc: davem, netdev

Since 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).

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
 include/net/netfilter/nf_tables.h |    6 +++---
 net/netfilter/nf_tables_api.c     |    3 +++
 2 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/include/net/netfilter/nf_tables.h b/include/net/netfilter/nf_tables.h
index 7ee6ce6..713b0b8 100644
--- a/include/net/netfilter/nf_tables.h
+++ b/include/net/netfilter/nf_tables.h
@@ -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];
 };
 
diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c
index ba37c10..5586426 100644
--- a/net/netfilter/nf_tables_api.c
+++ b/net/netfilter/nf_tables_api.c
@@ -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]) {
-- 
1.7.10.4


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH 06/13] netfilter: nf_tables: decrement chain use counter when replacing rules
  2014-06-18  9:44 [PATCH 00/13] netfilter fixes for net Pablo Neira Ayuso
                   ` (4 preceding siblings ...)
  2014-06-18  9:44 ` [PATCH 05/13] netfilter: nf_tables: use u32 for chain use counter Pablo Neira Ayuso
@ 2014-06-18  9:44 ` Pablo Neira Ayuso
  2014-06-18  9:44 ` [PATCH 07/13] netfilter: nf_tables: fix wrong type in transaction " Pablo Neira Ayuso
                   ` (7 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: Pablo Neira Ayuso @ 2014-06-18  9:44 UTC (permalink / raw)
  To: netfilter-devel; +Cc: davem, netdev

Thus, the chain use counter remains with the same value after the
rule replacement.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
 net/netfilter/nf_tables_api.c |    2 ++
 1 file changed, 2 insertions(+)

diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c
index 5586426..19f438d 100644
--- a/net/netfilter/nf_tables_api.c
+++ b/net/netfilter/nf_tables_api.c
@@ -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);
-- 
1.7.10.4


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH 07/13] netfilter: nf_tables: fix wrong type in transaction when replacing rules
  2014-06-18  9:44 [PATCH 00/13] netfilter fixes for net Pablo Neira Ayuso
                   ` (5 preceding siblings ...)
  2014-06-18  9:44 ` [PATCH 06/13] netfilter: nf_tables: decrement chain use counter when replacing rules Pablo Neira Ayuso
@ 2014-06-18  9:44 ` Pablo Neira Ayuso
  2014-06-18  9:44 ` [PATCH 08/13] netfilter: nft_compat: call {target, match}->destroy() to cleanup entry Pablo Neira Ayuso
                   ` (6 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: Pablo Neira Ayuso @ 2014-06-18  9:44 UTC (permalink / raw)
  To: netfilter-devel; +Cc: davem, netdev

In 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.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
 net/netfilter/nf_tables_api.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c
index 19f438d..39369ea 100644
--- a/net/netfilter/nf_tables_api.c
+++ b/net/netfilter/nf_tables_api.c
@@ -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;
-- 
1.7.10.4

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH 08/13] netfilter: nft_compat: call {target, match}->destroy() to cleanup entry
  2014-06-18  9:44 [PATCH 00/13] netfilter fixes for net Pablo Neira Ayuso
                   ` (6 preceding siblings ...)
  2014-06-18  9:44 ` [PATCH 07/13] netfilter: nf_tables: fix wrong type in transaction " Pablo Neira Ayuso
@ 2014-06-18  9:44 ` Pablo Neira Ayuso
  2014-06-18  9:44 ` [PATCH 09/13] netfilter: nf_tables: indicate family when dumping set elements Pablo Neira Ayuso
                   ` (5 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: Pablo Neira Ayuso @ 2014-06-18  9:44 UTC (permalink / raw)
  To: netfilter-devel; +Cc: davem, netdev

Otherwise, the reference to external objects (eg. modules) are not
released when the rules are removed.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
 net/netfilter/nft_compat.c |   18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/net/netfilter/nft_compat.c b/net/netfilter/nft_compat.c
index 8a779be..1840989 100644
--- a/net/netfilter/nft_compat.c
+++ b/net/netfilter/nft_compat.c
@@ -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);
 }
-- 
1.7.10.4

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH 09/13] netfilter: nf_tables: indicate family when dumping set elements
  2014-06-18  9:44 [PATCH 00/13] netfilter fixes for net Pablo Neira Ayuso
                   ` (7 preceding siblings ...)
  2014-06-18  9:44 ` [PATCH 08/13] netfilter: nft_compat: call {target, match}->destroy() to cleanup entry Pablo Neira Ayuso
@ 2014-06-18  9:44 ` Pablo Neira Ayuso
  2014-06-18  9:44 ` [PATCH 10/13] netfilter: nft_nat: don't dump port information if unset Pablo Neira Ayuso
                   ` (4 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: Pablo Neira Ayuso @ 2014-06-18  9:44 UTC (permalink / raw)
  To: netfilter-devel; +Cc: davem, netdev

Set the nfnetlink header that indicates the family of this element.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
 net/netfilter/nf_tables_api.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c
index 39369ea..ab4566c 100644
--- a/net/netfilter/nf_tables_api.c
+++ b/net/netfilter/nf_tables_api.c
@@ -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;
 
-- 
1.7.10.4

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH 10/13] netfilter: nft_nat: don't dump port information if unset
  2014-06-18  9:44 [PATCH 00/13] netfilter fixes for net Pablo Neira Ayuso
                   ` (8 preceding siblings ...)
  2014-06-18  9:44 ` [PATCH 09/13] netfilter: nf_tables: indicate family when dumping set elements Pablo Neira Ayuso
@ 2014-06-18  9:44 ` Pablo Neira Ayuso
  2014-06-18  9:44 ` [PATCH 11/13] netfilter: ctnetlink: add zone size to length Pablo Neira Ayuso
                   ` (3 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: Pablo Neira Ayuso @ 2014-06-18  9:44 UTC (permalink / raw)
  To: netfilter-devel; +Cc: davem, netdev

Don't include port information attributes if they are unset.

Reported-by: Ana Rey <anarey@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
 net/netfilter/nft_nat.c |   14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/net/netfilter/nft_nat.c b/net/netfilter/nft_nat.c
index a0195d2..79ff58c 100644
--- a/net/netfilter/nft_nat.c
+++ b/net/netfilter/nft_nat.c
@@ -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:
-- 
1.7.10.4

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH 11/13] netfilter: ctnetlink: add zone size to length
  2014-06-18  9:44 [PATCH 00/13] netfilter fixes for net Pablo Neira Ayuso
                   ` (9 preceding siblings ...)
  2014-06-18  9:44 ` [PATCH 10/13] netfilter: nft_nat: don't dump port information if unset Pablo Neira Ayuso
@ 2014-06-18  9:44 ` Pablo Neira Ayuso
  2014-06-18  9:44 ` [PATCH 12/13] netfilter: nf_nat: fix oops on netns removal Pablo Neira Ayuso
                   ` (2 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: Pablo Neira Ayuso @ 2014-06-18  9:44 UTC (permalink / raw)
  To: netfilter-devel; +Cc: davem, netdev

From: Ken-ichirou MATSUZAWA <chamas@h4.dion.ne.jp>

Signed-off-by: Ken-ichirou MATSUZAWA <chamas@h4.dion.ne.jp>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
 net/netfilter/nf_conntrack_netlink.c |    6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/net/netfilter/nf_conntrack_netlink.c b/net/netfilter/nf_conntrack_netlink.c
index 70123f4..300ed1e 100644
--- a/net/netfilter/nf_conntrack_netlink.c
+++ b/net/netfilter/nf_conntrack_netlink.c
@@ -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)
 	       ;
 }
-- 
1.7.10.4

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH 12/13] netfilter: nf_nat: fix oops on netns removal
  2014-06-18  9:44 [PATCH 00/13] netfilter fixes for net Pablo Neira Ayuso
                   ` (10 preceding siblings ...)
  2014-06-18  9:44 ` [PATCH 11/13] netfilter: ctnetlink: add zone size to length Pablo Neira Ayuso
@ 2014-06-18  9:44 ` Pablo Neira Ayuso
  2014-06-18  9:44 ` [PATCH 13/13] MAINTAINERS: merge ebtables into netfilter entry Pablo Neira Ayuso
  2014-06-18 23:10 ` [PATCH 00/13] netfilter fixes for net David Miller
  13 siblings, 0 replies; 15+ messages in thread
From: Pablo Neira Ayuso @ 2014-06-18  9:44 UTC (permalink / raw)
  To: netfilter-devel; +Cc: davem, netdev

From: Florian Westphal <fw@strlen.de>

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

Fixes: c2d421e1718 ('netfilter: nf_nat: fix race when unloading protocol modules')
Reported-by: Samu Kallio <samu.kallio@aberdeencloud.com>
Debugged-by: Samu Kallio <samu.kallio@aberdeencloud.com>
Signed-off-by: Florian Westphal <fw@strlen.de>
Tested-by: Samu Kallio <samu.kallio@aberdeencloud.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
 net/netfilter/nf_nat_core.c |   35 ++++++++++++++++++++++++++++++++++-
 1 file changed, 34 insertions(+), 1 deletion(-)

diff --git a/net/netfilter/nf_nat_core.c b/net/netfilter/nf_nat_core.c
index 09096a6..a49907b 100644
--- a/net/netfilter/nf_nat_core.c
+++ b/net/netfilter/nf_nat_core.c
@@ -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);
 }
-- 
1.7.10.4

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH 13/13] MAINTAINERS: merge ebtables into netfilter entry
  2014-06-18  9:44 [PATCH 00/13] netfilter fixes for net Pablo Neira Ayuso
                   ` (11 preceding siblings ...)
  2014-06-18  9:44 ` [PATCH 12/13] netfilter: nf_nat: fix oops on netns removal Pablo Neira Ayuso
@ 2014-06-18  9:44 ` Pablo Neira Ayuso
  2014-06-18 23:10 ` [PATCH 00/13] netfilter fixes for net David Miller
  13 siblings, 0 replies; 15+ messages in thread
From: Pablo Neira Ayuso @ 2014-06-18  9:44 UTC (permalink / raw)
  To: netfilter-devel; +Cc: davem, netdev

Moreover, remove reference to the netfilter users mailing list,
so they don't receive patches.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
 MAINTAINERS |   11 +----------
 1 file changed, 1 insertion(+), 10 deletions(-)

diff --git a/MAINTAINERS b/MAINTAINERS
index 134483f..2d67a5d 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -3189,14 +3189,6 @@ L:	linux-scsi@vger.kernel.org
 S:	Maintained
 F:	drivers/scsi/eata_pio.*
 
-EBTABLES
-L:	netfilter-devel@vger.kernel.org
-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 <crope@iki.fi>
 L:	linux-media@vger.kernel.org
@@ -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 <pablo@netfilter.org>
 M:	Patrick McHardy <kaber@trash.net>
 M:	Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
 L:	netfilter-devel@vger.kernel.org
-L:	netfilter@vger.kernel.org
 L:	coreteam@netfilter.org
 W:	http://www.netfilter.org/
 W:	http://www.iptables.org/
-- 
1.7.10.4

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* Re: [PATCH 00/13] netfilter fixes for net
  2014-06-18  9:44 [PATCH 00/13] netfilter fixes for net Pablo Neira Ayuso
                   ` (12 preceding siblings ...)
  2014-06-18  9:44 ` [PATCH 13/13] MAINTAINERS: merge ebtables into netfilter entry Pablo Neira Ayuso
@ 2014-06-18 23:10 ` David Miller
  13 siblings, 0 replies; 15+ messages in thread
From: David Miller @ 2014-06-18 23:10 UTC (permalink / raw)
  To: pablo; +Cc: netfilter-devel, netdev

From: Pablo Neira Ayuso <pablo@netfilter.org>
Date: Wed, 18 Jun 2014 11:44:26 +0200

> The following patchset contains netfilter updates for your net tree,
> they are:
 ...
> You can pull these changes from:
> 
>   git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf.git

Pulled, thanks Pablo.

^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2014-06-18 23:10 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-06-18  9:44 [PATCH 00/13] netfilter fixes for net Pablo Neira Ayuso
2014-06-18  9:44 ` [PATCH 01/13] ipvs: stop tot_stats estimator only under CONFIG_SYSCTL Pablo Neira Ayuso
2014-06-18  9:44 ` [PATCH 02/13] netfilter: ctnetlink: fix dumping of dying/unconfirmed conntracks Pablo Neira Ayuso
2014-06-18  9:44 ` [PATCH 03/13] netfilter: ctnetlink: fix refcnt leak in dying/unconfirmed list dumper Pablo Neira Ayuso
2014-06-18  9:44 ` [PATCH 04/13] netfilter: nf_tables: use RCU-safe list insertion when replacing rules Pablo Neira Ayuso
2014-06-18  9:44 ` [PATCH 05/13] netfilter: nf_tables: use u32 for chain use counter Pablo Neira Ayuso
2014-06-18  9:44 ` [PATCH 06/13] netfilter: nf_tables: decrement chain use counter when replacing rules Pablo Neira Ayuso
2014-06-18  9:44 ` [PATCH 07/13] netfilter: nf_tables: fix wrong type in transaction " Pablo Neira Ayuso
2014-06-18  9:44 ` [PATCH 08/13] netfilter: nft_compat: call {target, match}->destroy() to cleanup entry Pablo Neira Ayuso
2014-06-18  9:44 ` [PATCH 09/13] netfilter: nf_tables: indicate family when dumping set elements Pablo Neira Ayuso
2014-06-18  9:44 ` [PATCH 10/13] netfilter: nft_nat: don't dump port information if unset Pablo Neira Ayuso
2014-06-18  9:44 ` [PATCH 11/13] netfilter: ctnetlink: add zone size to length Pablo Neira Ayuso
2014-06-18  9:44 ` [PATCH 12/13] netfilter: nf_nat: fix oops on netns removal Pablo Neira Ayuso
2014-06-18  9:44 ` [PATCH 13/13] MAINTAINERS: merge ebtables into netfilter entry Pablo Neira Ayuso
2014-06-18 23:10 ` [PATCH 00/13] netfilter fixes for net David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).