netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next 1/2] netfilter: nfnetlink: add netns refcount tracker to struct nfulnl_instance
@ 2021-12-13 16:39 Eric Dumazet
  2021-12-13 16:40 ` [PATCH net-next 2/2] netfilter: nf_nat_masquerade: add netns refcount tracker to masq_dev_work Eric Dumazet
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Eric Dumazet @ 2021-12-13 16:39 UTC (permalink / raw)
  To: Pablo Neira Ayuso, Jozsef Kadlecsik, Florian Westphal
  Cc: netfilter-devel, netdev, Eric Dumazet, Eric Dumazet

From: Eric Dumazet <edumazet@google.com>

If compiled with CONFIG_NET_NS_REFCNT_TRACKER=y,
using put_net_track() in nfulnl_instance_free_rcu()
and get_net_track() in instance_create()
might help us finding netns refcount imbalances.

Signed-off-by: Eric Dumazet <edumazet@google.com>
---
 net/netfilter/nfnetlink_log.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
index 691ef4cffdd907cf09d3a7e680ebe83ea5562ee0..7a3a91fc7ffaaf7c632692949a990f5867173e5c 100644
--- a/net/netfilter/nfnetlink_log.c
+++ b/net/netfilter/nfnetlink_log.c
@@ -66,6 +66,7 @@ struct nfulnl_instance {
 	struct sk_buff *skb;		/* pre-allocatd skb */
 	struct timer_list timer;
 	struct net *net;
+	netns_tracker ns_tracker;
 	struct user_namespace *peer_user_ns;	/* User namespace of the peer process */
 	u32 peer_portid;		/* PORTID of the peer process */
 
@@ -140,7 +141,7 @@ static void nfulnl_instance_free_rcu(struct rcu_head *head)
 	struct nfulnl_instance *inst =
 		container_of(head, struct nfulnl_instance, rcu);
 
-	put_net(inst->net);
+	put_net_track(inst->net, &inst->ns_tracker);
 	kfree(inst);
 	module_put(THIS_MODULE);
 }
@@ -187,7 +188,7 @@ instance_create(struct net *net, u_int16_t group_num,
 
 	timer_setup(&inst->timer, nfulnl_timer, 0);
 
-	inst->net = get_net(net);
+	inst->net = get_net_track(net, &inst->ns_tracker, GFP_ATOMIC);
 	inst->peer_user_ns = user_ns;
 	inst->peer_portid = portid;
 	inst->group_num = group_num;
-- 
2.34.1.173.g76aa8bc2d0-goog


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

* [PATCH net-next 2/2] netfilter: nf_nat_masquerade: add netns refcount tracker to masq_dev_work
  2021-12-13 16:39 [PATCH net-next 1/2] netfilter: nfnetlink: add netns refcount tracker to struct nfulnl_instance Eric Dumazet
@ 2021-12-13 16:40 ` Eric Dumazet
  2021-12-16 11:50   ` Pablo Neira Ayuso
  2021-12-15 23:03 ` [PATCH net-next 1/2] netfilter: nfnetlink: add netns refcount tracker to struct nfulnl_instance Pablo Neira Ayuso
  2021-12-16 11:50 ` Pablo Neira Ayuso
  2 siblings, 1 reply; 6+ messages in thread
From: Eric Dumazet @ 2021-12-13 16:40 UTC (permalink / raw)
  To: Pablo Neira Ayuso, Jozsef Kadlecsik, Florian Westphal
  Cc: netfilter-devel, netdev, Eric Dumazet, Eric Dumazet

From: Eric Dumazet <edumazet@google.com>

If compiled with CONFIG_NET_NS_REFCNT_TRACKER=y,
using put_net_track() in iterate_cleanup_work()
and netns_tracker_alloc() in nf_nat_masq_schedule()
might help us finding netns refcount imbalances.

Signed-off-by: Eric Dumazet <edumazet@google.com>
---
 net/netfilter/nf_nat_masquerade.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/net/netfilter/nf_nat_masquerade.c b/net/netfilter/nf_nat_masquerade.c
index acd73f717a0883d791fc351851a98bac4144705f..e32fac374608576d6237f80b1bff558e9453585a 100644
--- a/net/netfilter/nf_nat_masquerade.c
+++ b/net/netfilter/nf_nat_masquerade.c
@@ -12,6 +12,7 @@
 struct masq_dev_work {
 	struct work_struct work;
 	struct net *net;
+	netns_tracker ns_tracker;
 	union nf_inet_addr addr;
 	int ifindex;
 	int (*iter)(struct nf_conn *i, void *data);
@@ -82,7 +83,7 @@ static void iterate_cleanup_work(struct work_struct *work)
 
 	nf_ct_iterate_cleanup_net(w->net, w->iter, (void *)w, 0, 0);
 
-	put_net(w->net);
+	put_net_track(w->net, &w->ns_tracker);
 	kfree(w);
 	atomic_dec(&masq_worker_count);
 	module_put(THIS_MODULE);
@@ -119,6 +120,7 @@ static void nf_nat_masq_schedule(struct net *net, union nf_inet_addr *addr,
 		INIT_WORK(&w->work, iterate_cleanup_work);
 		w->ifindex = ifindex;
 		w->net = net;
+		netns_tracker_alloc(net, &w->ns_tracker, gfp_flags);
 		w->iter = iter;
 		if (addr)
 			w->addr = *addr;
-- 
2.34.1.173.g76aa8bc2d0-goog


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

* Re: [PATCH net-next 1/2] netfilter: nfnetlink: add netns refcount tracker to struct nfulnl_instance
  2021-12-13 16:39 [PATCH net-next 1/2] netfilter: nfnetlink: add netns refcount tracker to struct nfulnl_instance Eric Dumazet
  2021-12-13 16:40 ` [PATCH net-next 2/2] netfilter: nf_nat_masquerade: add netns refcount tracker to masq_dev_work Eric Dumazet
@ 2021-12-15 23:03 ` Pablo Neira Ayuso
  2021-12-15 23:04   ` Pablo Neira Ayuso
  2021-12-16 11:50 ` Pablo Neira Ayuso
  2 siblings, 1 reply; 6+ messages in thread
From: Pablo Neira Ayuso @ 2021-12-15 23:03 UTC (permalink / raw)
  To: Eric Dumazet
  Cc: Jozsef Kadlecsik, Florian Westphal, netfilter-devel, netdev,
	Eric Dumazet

On Mon, Dec 13, 2021 at 08:39:59AM -0800, Eric Dumazet wrote:
> From: Eric Dumazet <edumazet@google.com>
> 
> If compiled with CONFIG_NET_NS_REFCNT_TRACKER=y,
> using put_net_track() in nfulnl_instance_free_rcu()
> and get_net_track() in instance_create()
> might help us finding netns refcount imbalances.

Applied to nf-next, thanks

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

* Re: [PATCH net-next 1/2] netfilter: nfnetlink: add netns refcount tracker to struct nfulnl_instance
  2021-12-15 23:03 ` [PATCH net-next 1/2] netfilter: nfnetlink: add netns refcount tracker to struct nfulnl_instance Pablo Neira Ayuso
@ 2021-12-15 23:04   ` Pablo Neira Ayuso
  0 siblings, 0 replies; 6+ messages in thread
From: Pablo Neira Ayuso @ 2021-12-15 23:04 UTC (permalink / raw)
  To: Eric Dumazet
  Cc: Jozsef Kadlecsik, Florian Westphal, netfilter-devel, netdev,
	Eric Dumazet

On Thu, Dec 16, 2021 at 12:03:27AM +0100, Pablo Neira Ayuso wrote:
> On Mon, Dec 13, 2021 at 08:39:59AM -0800, Eric Dumazet wrote:
> > From: Eric Dumazet <edumazet@google.com>
> > 
> > If compiled with CONFIG_NET_NS_REFCNT_TRACKER=y,
> > using put_net_track() in nfulnl_instance_free_rcu()
> > and get_net_track() in instance_create()
> > might help us finding netns refcount imbalances.
> 
> Applied to nf-next, thanks

Hm, actually I cannot, nf-next is still behing net-next and it does
not have this symbols.

I'll send a pull request and pick up these patches asap.

Thanks.

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

* Re: [PATCH net-next 1/2] netfilter: nfnetlink: add netns refcount tracker to struct nfulnl_instance
  2021-12-13 16:39 [PATCH net-next 1/2] netfilter: nfnetlink: add netns refcount tracker to struct nfulnl_instance Eric Dumazet
  2021-12-13 16:40 ` [PATCH net-next 2/2] netfilter: nf_nat_masquerade: add netns refcount tracker to masq_dev_work Eric Dumazet
  2021-12-15 23:03 ` [PATCH net-next 1/2] netfilter: nfnetlink: add netns refcount tracker to struct nfulnl_instance Pablo Neira Ayuso
@ 2021-12-16 11:50 ` Pablo Neira Ayuso
  2 siblings, 0 replies; 6+ messages in thread
From: Pablo Neira Ayuso @ 2021-12-16 11:50 UTC (permalink / raw)
  To: Eric Dumazet
  Cc: Jozsef Kadlecsik, Florian Westphal, netfilter-devel, netdev,
	Eric Dumazet

On Mon, Dec 13, 2021 at 08:39:59AM -0800, Eric Dumazet wrote:
> From: Eric Dumazet <edumazet@google.com>
> 
> If compiled with CONFIG_NET_NS_REFCNT_TRACKER=y,
> using put_net_track() in nfulnl_instance_free_rcu()
> and get_net_track() in instance_create()
> might help us finding netns refcount imbalances.

Now applied to nf-next, thanks

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

* Re: [PATCH net-next 2/2] netfilter: nf_nat_masquerade: add netns refcount tracker to masq_dev_work
  2021-12-13 16:40 ` [PATCH net-next 2/2] netfilter: nf_nat_masquerade: add netns refcount tracker to masq_dev_work Eric Dumazet
@ 2021-12-16 11:50   ` Pablo Neira Ayuso
  0 siblings, 0 replies; 6+ messages in thread
From: Pablo Neira Ayuso @ 2021-12-16 11:50 UTC (permalink / raw)
  To: Eric Dumazet
  Cc: Jozsef Kadlecsik, Florian Westphal, netfilter-devel, netdev,
	Eric Dumazet

On Mon, Dec 13, 2021 at 08:40:00AM -0800, Eric Dumazet wrote:
> From: Eric Dumazet <edumazet@google.com>
> 
> If compiled with CONFIG_NET_NS_REFCNT_TRACKER=y,
> using put_net_track() in iterate_cleanup_work()
> and netns_tracker_alloc() in nf_nat_masq_schedule()
> might help us finding netns refcount imbalances.

Also applied, thanks

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

end of thread, other threads:[~2021-12-16 11:50 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-13 16:39 [PATCH net-next 1/2] netfilter: nfnetlink: add netns refcount tracker to struct nfulnl_instance Eric Dumazet
2021-12-13 16:40 ` [PATCH net-next 2/2] netfilter: nf_nat_masquerade: add netns refcount tracker to masq_dev_work Eric Dumazet
2021-12-16 11:50   ` Pablo Neira Ayuso
2021-12-15 23:03 ` [PATCH net-next 1/2] netfilter: nfnetlink: add netns refcount tracker to struct nfulnl_instance Pablo Neira Ayuso
2021-12-15 23:04   ` Pablo Neira Ayuso
2021-12-16 11:50 ` Pablo Neira Ayuso

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