Skip to content

net/ncsi: fix RCU list entry lifetime on package and channel removal

Tristan Madani lkml netdev stable 1 version New

Get series with b4
b4 am [email protected]

Versions newest first

  1. v2 Latest2 patches 0 repliesNew

Changes in v2 from the cover letter

- Rework as a 2-patch series fixing both reader and writer sides instead of a single patch that only fixed the writer side
- Add rcu_read_lock() on the reader side: ncsi_find_dev(), ncsi_write_package_info(), ncsi_pkg_info_all_nl() (sashiko-bot)
- Defer channel sub-allocation frees (mac_filter.addrs, vlan_filter.vids) to the RCU callback so readers cannot follow stale pointers during the grace period (sashiko-bot)
- Move disable_work_sync() before package removal in ncsi_unregister_dev() so the work function is quiesced before any structures are freed (sashiko-bot)
- Fix Fixes: tag hash from 2d283bdd5b20 to 2d283bdd079c ("net/ncsi: Resource management") (sashiko-bot)
- Include discovery method per sashiko-bot request

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/2net/ncsi: add missing rcu_read_lock to netlink and device list walksnet/ncsi/ncsi-manage.c net/ncsi/ncsi-netlink.c+29 -140 replies
2/2net/ncsi: defer free of removed list entries to an RCU grace periodnet/ncsi/internal.h net/ncsi/ncsi-manage.c+17 -120 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v2 yet.

Read the v2 thread

Cover letter [PATCH v2 net 0/2] net/ncsi: fix RCU list entry lifetime on package and channel removal

From: Tristan Madani <[email protected]>

The NCSI package/channel/device removal paths call list_del_rcu() followed by immediate kfree(). This races with concurrent readers (primarily the unprivileged NCSI_CMD_PKG_INFO netlink handler) that walk the same lists with list_for_each_entry_rcu() but never enter an RCU read-side critical section.

Patch 1 adds the missing rcu_read_lock()/rcu_read_unlock() to the reader paths so kfree_rcu() on the write side has matching readers to wait for.

Patch 2 defers the free side: channels use call_rcu() with a callback that also frees filter sub-allocations, packages and the device structure use kfree_rcu_mightsleep(), and the work is quiesced before packages are removed.

Pre-existing issues noted by sashiko-bot review -- dangling active_channel/hot_channel/preferred_channel pointers, unquiesced per-request timers, and the ftgmac100 unregister ordering -- are not addressed here. They affect the overall NCSI teardown design and are better handled in a dedicated series.

Tristan Madani (2):
net/ncsi: add missing rcu_read_lock to netlink and device list walks net/ncsi: defer free of removed list entries to an RCU grace period

 net/ncsi/internal.h     |  1 +
 net/ncsi/ncsi-manage.c  | 39 ++++++++++++++++++++++++---------------
 net/ncsi/ncsi-netlink.c | 32 +++++++++++++++++++++-----------
 3 files changed, 46 insertions(+), 26 deletions(-)

---

Changes in v2:
- Rework as a 2-patch series fixing both reader and writer sides instead of a single patch that only fixed the writer side
- Add rcu_read_lock() on the reader side: ncsi_find_dev(), ncsi_write_package_info(), ncsi_pkg_info_all_nl() (sashiko-bot)
- Defer channel sub-allocation frees (mac_filter.addrs, vlan_filter.vids) to the RCU callback so readers cannot follow stale pointers during the grace period (sashiko-bot)
- Move disable_work_sync() before package removal in ncsi_unregister_dev() so the work function is quiesced before any structures are freed (sashiko-bot)
- Fix Fixes: tag hash from 2d283bdd5b20 to 2d283bdd079c ("net/ncsi: Resource management") (sashiko-bot)
- Include discovery method per sashiko-bot request

Signature · 1 line
2.47.3