Skip to contentSkip to conversation

netfilter: nf_tables: wait for rcu grace period on net_device removal

PATCH Superseded Pablo Neira Ayuso 1 participant 1 message Oct 29, 2024

Subsystems (2)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Pablo Neira Ayuso

author maintainer
#0 lore raw

PATCH v3 1/1 netfilter: nf_tables: wait for rcu grace period on net_device removal

8c873e219970 ("netfilter: core: free hooks with call_rcu") removed synchronize_net() call when unregistering basechain hook, however, net_device removal event handler for the NFPROTO_NETDEV was not updated to wait for RCU grace period.

Note that 835b803377f5 ("netfilter: nf_tables_netdev: unregister hooks on net_device removal") does not remove basechain rules on device removal, it was just a bit later that I was hinted to remove rules on net_device removal, see 5ebe0b0eec9d ("netfilter: nf_tables: destroy basechain and rules on netdevice removal").

Use rcu callback to release basechain but add a slow path by calling synchronize_rcu() if reference on netns cannot be taken, because basechain can be seen from this path:

cleanup_net()
default_device_exit_batch()
unregister_netdevice_many_notify()
notifier_call_chain()
nf_tables_netdev_event()
__nft_release_basechain()

nftables/tests/shell can trigger this path occasionally.

While at it, turn WARN_ON() into WARN_ON_ONCE().

Fixes 835b803377f5 ("netfilter: nf_tables_netdev: unregister hooks on net_device removal")

---
v3: slow synchronize_rcu() path for what it looks like a corner case.
I'm not particularly happy with this special case.

 include/net/netfilter/nf_tables.h |  2 ++
 net/netfilter/nf_tables_api.c     | 48 ++++++++++++++++++++++++++++---
 2 files changed, 46 insertions(+), 4 deletions(-)
include/net/netfilter/nf_tables.h +2 -0
index 91ae20cb7648..8dd8e278843d 100644
@@ -1120,6 +1120,7 @@ struct nft_chain {
 	char				*name;
 	u16				udlen;
 	u8				*udata;
+	struct rcu_head			rcu_head;
 
 	/* Only used during control plane commit phase: */
 	struct nft_rule_blob		*blob_next;
@@ -1282,6 +1283,7 @@ struct nft_table {
 	struct list_head		sets;
 	struct list_head		objects;
 	struct list_head		flowtables;
+	possible_net_t			net;
 	u64				hgenerator;
 	u64				handle;
 	u32				use;
net/netfilter/nf_tables_api.c +44 -4

70 lines not on this page · raw message

Signature · 1 line
2.30.2