netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Stanislav Fomichev <stfomichev@gmail.com>
To: Jakub Kicinski <kuba@kernel.org>
Cc: davem@davemloft.net, netdev@vger.kernel.org, edumazet@google.com,
	pabeni@redhat.com, andrew+netdev@lunn.ch, horms@kernel.org,
	syzbot+6f588c78bf765b62b450@syzkaller.appspotmail.com,
	sdf@fomichev.me
Subject: Re: [PATCH net] net: don't mix device locking in dev_close_many() calls
Date: Sun, 13 Apr 2025 15:48:19 -0700	[thread overview]
Message-ID: <Z_w_M95kn0UFXfDm@mini-arch> (raw)
In-Reply-To: <20250412233011.309762-1-kuba@kernel.org>

On 04/12, Jakub Kicinski wrote:
> Lockdep found the following dependency:
> 
>   &dev_instance_lock_key#3 -->
>      &rdev->wiphy.mtx -->
>         &net->xdp.lock -->
> 	   &xs->mutex -->
> 	      &dev_instance_lock_key#3
> 
> The first dependency is the problem. wiphy mutex should be outside
> the instance locks. The problem happens in notifiers (as always)
> for CLOSE. We only hold the instance lock for ops locked devices
> during CLOSE, and WiFi netdevs are not ops locked. Unfortunately,
> when we dev_close_many() during netns dismantle we may be holding
> the instance lock of _another_ netdev when issuing a CLOSE for
> a WiFi device.
> 
> Lockdep's "Possible unsafe locking scenario" only prints 3 locks
> and we have 4, plus I think we'd need 3 CPUs, like this:
> 
>        CPU0                 CPU1              CPU2
>        ----                 ----              ----
>   lock(&xs->mutex);
>                        lock(&dev_instance_lock_key#3);
>                                          lock(&rdev->wiphy.mtx);
>                                          lock(&net->xdp.lock);
>                                          lock(&xs->mutex);
>                        lock(&rdev->wiphy.mtx);
>   lock(&dev_instance_lock_key#3);
> 
> Tho, I don't think that's possible as CPU1 and CPU2 would
> be under rtnl_lock. Even if we have per-netns rtnl_lock and
> wiphy can span network namespaces - CPU0 and CPU1 must be
> in the same netns to see dev_instance_lock, so CPU0 can't
> be installing a socket as CPU1 is tearing the netns down.
> 
> Regardless, our expected lock ordering is that wiphy lock
> is taken before instance locks, so let's fix this.
> 
> Go over the ops locked and non-locked devices separately.
> Note that calling dev_close_many() on an empty list is perfectly
> fine. All processing (including RCU syncs) are conditional
> on the list not being empty, already.
> 
> Fixes: 7e4d784f5810 ("net: hold netdev instance lock during rtnetlink operations")
> Reported-by: syzbot+6f588c78bf765b62b450@syzkaller.appspotmail.com
> Signed-off-by: Jakub Kicinski <kuba@kernel.org>

Acked-by: Stanislav Fomichev <sdf@fomichev.me>

  reply	other threads:[~2025-04-13 22:48 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-12 23:30 [PATCH net] net: don't mix device locking in dev_close_many() calls Jakub Kicinski
2025-04-13 22:48 ` Stanislav Fomichev [this message]
2025-04-14 20:12 ` patchwork-bot+netdevbpf

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=Z_w_M95kn0UFXfDm@mini-arch \
    --to=stfomichev@gmail.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=sdf@fomichev.me \
    --cc=syzbot+6f588c78bf765b62b450@syzkaller.appspotmail.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).