Netdev List
 help / color / mirror / Atom feed
From: Yuyang Huang <yuyanghuang@google.com>
To: Yuyang Huang <yuyanghuang@google.com>
Cc: "David S. Miller" <davem@davemloft.net>,
	 Aleksandr Loktionov <aleksandr.loktionov@intel.com>,
	Eric Dumazet <edumazet@kernel.org>,
	 Jakub Kicinski <kuba@kernel.org>,
	Paolo Abeni <pabeni@redhat.com>, Simon Horman <horms@kernel.org>,
	 Stanislav Fomichev <sdf.kernel@gmail.com>,
	netdev@vger.kernel.org
Subject: [PATCH net-next] net: use dev_net_rcu() in __hw_addr_changed()
Date: Sat, 28 Nov 2026 17:36:39 +0900	[thread overview]
Message-ID: <20261128083639.1404522-1-yuyanghuang@google.com> (raw)

Commit 646cb8868bd2 ("net: add a generation counter for dev->mc
changes") bumps a per netns counter on every dev->mc change, and finds
the netns with dev_net(). Not all callers hold RTNL, so this read can
race with __dev_change_net_namespace() updating dev->nd_net. At worst
the old netns gets the bump, which is harmless, but the read is still
lockless and should be marked as such.

Use dev_net_rcu() under rcu_read_lock() instead. The address list lock
alone does not satisfy the RCU lockdep check.

Found by Sashiko AI review. Theoretical, not seen at runtime.

Link: https://lore.kernel.org/netdev/179185709988.434549.15422498299449004512@kernel.org/
Signed-off-by: Yuyang Huang <yuyanghuang@google.com>
---
 net/core/dev_addr_lists.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/net/core/dev_addr_lists.c b/net/core/dev_addr_lists.c
index b6f25e487984..700d9247ac0c 100644
--- a/net/core/dev_addr_lists.c
+++ b/net/core/dev_addr_lists.c
@@ -30,7 +30,9 @@ static void __hw_addr_changed(struct netdev_hw_addr_list *list)
 	if (!list->is_dev_mc)
 		return;
 	dev = container_of(list, struct net_device, mc);
-	atomic_inc(&dev_net(dev)->dev_mc_genid);
+	rcu_read_lock();
+	atomic_inc(&dev_net_rcu(dev)->dev_mc_genid);
+	rcu_read_unlock();
 }
 
 static void __hw_addr_count_add(struct netdev_hw_addr_list *list, int value)
-- 
2.56.1.839.g22a8290db9-goog


             reply	other threads:[~2026-11-28  8:36 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-28  8:36 Yuyang Huang [this message]
2026-12-04  5:00 ` [PATCH net-next] net: use dev_net_rcu() in __hw_addr_changed() 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=20261128083639.1404522-1-yuyanghuang@google.com \
    --to=yuyanghuang@google.com \
    --cc=aleksandr.loktionov@intel.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=sdf.kernel@gmail.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