netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v4 net 0/3] net: Fix race of rtnl_net_lock(dev_net(dev)).
@ 2025-02-12  6:42 Kuniyuki Iwashima
  2025-02-12  6:42 ` [PATCH v4 net 1/3] net: Add net_passive_inc() and net_passive_dec() Kuniyuki Iwashima
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Kuniyuki Iwashima @ 2025-02-12  6:42 UTC (permalink / raw)
  To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Simon Horman
  Cc: Kuniyuki Iwashima, Kuniyuki Iwashima, netdev

Yael Chemla reported that commit 7fb1073300a2 ("net: Hold rtnl_net_lock()
in (un)?register_netdevice_notifier_dev_net().") started to trigger KASAN's
use-after-free splat.

The problem is that dev_net(dev) fetched before rtnl_net_lock() might be
different after rtnl_net_lock().

The patch 2 fixes the issue by checking dev_net(dev) after rtnl_net_lock(),
and the patch 3 fixes the same potential issue that would emerge once RTNL
is removed.


Changes:
  v4:
    * Add patch 1
    * Fix build failure for !CONFIG_NET_NS in patch 2

  v3:
    * Bump net->passive instead of maybe_get_net()
    * Remove msleep(1) loop
    * Use rcu_access_pointer() instead of rcu_read_lock().

  v2:
    * Use dev_net_rcu()
    * Use msleep(1) instead of cond_resched() after maybe_get_net()
    * Remove cond_resched() after net_eq() check

  v1: https://lore.kernel.org/netdev/20250130232435.43622-1-kuniyu@amazon.com/


Kuniyuki Iwashima (3):
  net: Add net_passive_inc() and net_passive_dec().
  net: Fix dev_net(dev) race in unregister_netdevice_notifier_dev_net().
  dev: Use rtnl_net_dev_lock() in unregister_netdev().

 include/net/net_namespace.h | 11 ++++++++
 net/core/dev.c              | 51 +++++++++++++++++++++++++++++++------
 net/core/net_namespace.c    |  8 +++---
 3 files changed, 58 insertions(+), 12 deletions(-)

-- 
2.39.5 (Apple Git-154)


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

end of thread, other threads:[~2025-02-15  9:30 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-12  6:42 [PATCH v4 net 0/3] net: Fix race of rtnl_net_lock(dev_net(dev)) Kuniyuki Iwashima
2025-02-12  6:42 ` [PATCH v4 net 1/3] net: Add net_passive_inc() and net_passive_dec() Kuniyuki Iwashima
2025-02-12 13:52   ` Eric Dumazet
2025-02-12  6:42 ` [PATCH v4 net 2/3] net: Fix dev_net(dev) race in unregister_netdevice_notifier_dev_net() Kuniyuki Iwashima
2025-02-12 13:54   ` Eric Dumazet
2025-02-13 16:32   ` Jakub Kicinski
2025-02-14  0:25     ` Kuniyuki Iwashima
2025-02-14 21:08       ` Jakub Kicinski
2025-02-15  9:30         ` Kuniyuki Iwashima
2025-02-12  6:42 ` [PATCH v4 net 3/3] dev: Use rtnl_net_dev_lock() in unregister_netdev() Kuniyuki Iwashima
2025-02-12 13:55   ` Eric Dumazet

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