Skip to content

net: Fix race of rtnl_net_lock(dev_net(dev)).

Kuniyuki Iwashima netdev 5 versions – Applied

Status from this message: This series was applied to netdev/net.git (main)

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v5 Latest3 patches 8 repliesApplied 3/3
  2. v43 patches 7 repliesSuperseded
  3. v32 patches 2 repliesSuperseded
Earlier versions · 2
VersionPostedPatchesRepliesStatus
v22 patches4 repliesSuperseded
v12 patches2 repliesSuperseded

Changes in v5 from the cover letter

* Use do-while loop instead of goto

Patches in v5 All 3 applied

#Subject and filesSizeRepliesApplied
1/3net: Add net_passive_inc() and net_passive_dec().include/net/net_namespace.h net/core/net_namespace.c+15 -40 repliesApplied
2/3net: Fix dev_net(dev) race in unregister_netdevice_notifier_dev_net().net/core/dev.c+44 -48 repliesApplied
3/3dev: Use rtnl_net_dev_lock() in unregister_netdev().net/core/dev.c+2 -40 repliesApplied

Reviews trailers per patch

All 3 patches have a Reviewed-by or Acked-by.

PatchEric Dumazet
1/3R-b
2/3R-b
3/3R-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v5 thread

Cover letter [PATCH v5 net 0/3] net: Fix race of rtnl_net_lock(dev_net(dev)).

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:
v5:
* Use do-while loop instead of goto

v4: https://lore.kernel.org/netdev/[email protected]/
* Add patch 1
* Fix build failure for !CONFIG_NET_NS in patch 2

v3: https://lore.kernel.org/netdev/[email protected]/
* Bump net->passive instead of maybe_get_net()
* Remove msleep(1) loop
* Use rcu_access_pointer() instead of rcu_read_lock().

v2: https://lore.kernel.org/netdev/[email protected]/
* 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/[email protected]/

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              | 54 +++++++++++++++++++++++++++++++------
 net/core/net_namespace.c    |  8 +++---
 3 files changed, 61 insertions(+), 12 deletions(-)
Signature · 1 line
2.39.5 (Apple Git-154)