netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Kuniyuki Iwashima <kuniyu@amazon.com>
To: <ychemla@nvidia.com>
Cc: <davem@davemloft.net>, <edumazet@google.com>, <horms@kernel.org>,
	<kuba@kernel.org>, <kuni1840@gmail.com>, <kuniyu@amazon.com>,
	<netdev@vger.kernel.org>, <pabeni@redhat.com>
Subject: Re: [PATCH v1 net-next 4/4] net: Hold rtnl_net_lock() in (un)?register_netdevice_notifier_dev_net().
Date: Wed, 29 Jan 2025 16:32:18 -0800	[thread overview]
Message-ID: <20250130003218.69951-1-kuniyu@amazon.com> (raw)
In-Reply-To: <049d3a80-1b51-4796-83df-efb80f3b3107@nvidia.com>

From: Yael Chemla <ychemla@nvidia.com>
Date: Wed, 29 Jan 2025 18:21:23 +0200
> On 28/01/2025 1:26, Kuniyuki Iwashima wrote:
> > From: Yael Chemla <ychemla@nvidia.com>
> > Date: Mon, 20 Jan 2025 20:55:07 +0200
> >>>>> diff --git a/net/core/dev.c b/net/core/dev.c
> >>>>> index f6c6559e2548..a0dd34463901 100644
> >>>>> --- a/net/core/dev.c
> >>>>> +++ b/net/core/dev.c
> >>>>> @@ -1943,15 +1943,17 @@ int register_netdevice_notifier_dev_net(struct net_device *dev,
> >>>>>     					struct notifier_block *nb,
> >>>>>     					struct netdev_net_notifier *nn)
> >>>>>     {
> >>>>> +	struct net *net = dev_net(dev);
> >>>>
> >>>> it seems to happen since the net pointer is acquired here without a lock.
> >>>> Note that KASAN issue is not triggered when executing with rtnl_lock()
> >>>> taken before this line. and our kernel .config expands
> >>>> rtnl_net_lock(net) to rtnl_lock() (CONFIG_DEBUG_NET_SMALL_RTNL is not set).
> >>>
> >>> It sounds like the device was being moved to another netns while
> >>> unregister_netdevice_notifier_dev_net() was called.
> >>>
> >>> Could you check if dev_net() is changed before/after rtnl_lock() in
> >>>
> >>>     * register_netdevice_notifier_dev_net()
> >>>     * unregister_netdevice_notifier_dev_net()
> >>>
> >>> ?
> >>
> >> When checking dev_net before and after taking the lock the issue won’t
> >> reproduce.
> >> note that when issue reproduce we arrive to
> >> unregister_netdevice_notifier_dev_net with an invalid net pointer
> >> (verified it with prints of its value, and it's not the same consistent
> >> value as is throughout rest of the test).
> > 
> > Does an invalid net pointer means a dead netns pointer ?
> > dev_net() and dev_net_set() use rcu_dereference() and rcu_assign_pointer(),
> > so I guess it should not be an invalid address at least.
> > 
> I logged several values at the entrance of 
> unregister_netdevice_notifier_dev_net when issue reproduced:
> 1) fields of net->ns (struct ns_common):
> count: the namespace refcount is 0 (i.e. net->ns.count, used 
> refcount_read to read it).

This indicates here we race with cleanup_net().

> 
> inum: the value doesn't appear to be garbage but differ from its 
> constant value throughout the test.
> 
> 2) net pointer (struct net): value differ from its constant value 
> observed during the rest of the test.
> 
> hope this helps and please let me know if more info is needed.
> 
> > 
> >> we suspect the issue related to the async ns deletion.
> > 
> > I think async netns change would trigger the issue too.
> > 
> > Could you try this patch ?
> > 
> 
> I tested your patch and issue won't reproduce with it 
> (CONFIG_DEBUG_NET_SMALL_RTNL is not set in my config).
> 
> Tested-by: Yael Chemla <ychemla@nvidia.com>

Thanks for testing !

Will post the fix officially.

  reply	other threads:[~2025-01-30  0:32 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-04  6:37 [PATCH v1 net-next 0/4] net: Hold per-netns RTNL during netdev notifier registration Kuniyuki Iwashima
2025-01-04  6:37 ` [PATCH v1 net-next 1/4] net: Convert netdev_chain to blocking_notifier Kuniyuki Iwashima
2025-01-08  2:28   ` kernel test robot
2025-01-04  6:37 ` [PATCH v1 net-next 2/4] net: Hold __rtnl_net_lock() in (un)?register_netdevice_notifier() Kuniyuki Iwashima
2025-01-04  6:37 ` [PATCH v1 net-next 3/4] net: Hold rtnl_net_lock() in (un)?register_netdevice_notifier_net() Kuniyuki Iwashima
2025-01-04  6:37 ` [PATCH v1 net-next 4/4] net: Hold rtnl_net_lock() in (un)?register_netdevice_notifier_dev_net() Kuniyuki Iwashima
2025-01-15 22:16   ` Yael Chemla
2025-01-16  2:54     ` Kuniyuki Iwashima
2025-01-20 18:55       ` Yael Chemla
2025-01-27 17:26         ` Yael Chemla
2025-01-27 17:54           ` Kuniyuki Iwashima
2025-01-27 23:26         ` Kuniyuki Iwashima
2025-01-29 16:21           ` Yael Chemla
2025-01-30  0:32             ` Kuniyuki Iwashima [this message]
2025-01-04 15:37 ` [PATCH v1 net-next 0/4] net: Hold per-netns RTNL during netdev notifier registration Jakub Kicinski
2025-01-05  7:59   ` Kuniyuki Iwashima

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250130003218.69951-1-kuniyu@amazon.com \
    --to=kuniyu@amazon.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=kuni1840@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=ychemla@nvidia.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).