netfilter: nf_tables: join hook list via splice_list_rcu() in commit phase
Subsystems (2)
Pablo Neira Ayuso
maintainerPATCH 2/3 netfilter: nf_tables: join hook list via splice_list_rcu() in commit phase
Publish new hooks in the list into the basechain/flowtable using splice_list_rcu() to ensure netlink dump list traversal via rcu is safe while concurrent ruleset update is going on.
--- net/netfilter/nf_tables_api.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
net/netfilter/nf_tables_api.c +4 -4
@@ -10912,8 +10912,8 @@ static int nf_tables_commit(struct net *net, struct sk_buff *skb)nft_chain_commit_update (nft_trans_container_chain (trans));nf_tables_chain_notify (&ctx,NFT_MSG_NEWCHAIN , &nft_trans_chain_hooks (trans)); -list_splice (&nft_trans_chain_hooks (trans), - &nft_trans_basechain (trans)->hook_list); +list_splice_rcu (&nft_trans_chain_hooks (trans), + &nft_trans_basechain (trans)->hook_list);/* trans destroyed after rcu grace period */ }else {nft_chain_commit_drop_policy (nft_trans_container_chain (trans));
@@ -11042,8 +11042,8 @@ static int nf_tables_commit(struct net *net, struct sk_buff *skb)nft_trans_flowtable (trans), &nft_trans_flowtable_hooks (trans), NFT_MSG_NEWFLOWTABLE); -list_splice (&nft_trans_flowtable_hooks (trans), - &nft_trans_flowtable (trans)->hook_list); +list_splice_rcu (&nft_trans_flowtable_hooks (trans), + &nft_trans_flowtable (trans)->hook_list); }else {nft_clear (net,nft_trans_flowtable (trans)); nf_tables_flowtable_notify(&ctx,
Signature · 1 line
2.47.3
Pablo Neira Ayuso
maintainerPATCH 3/3 netfilter: nf_tables: add hook transactions for device deletions
Restore the flag that indicates that the hook is going away, ie. NFT_HOOK_INACTIVE, but add a new transaction object to track deletion of hooks without altering the basechain/flowtable hook_list during the preparation phase.
The existing approach that moves the hook from the basechain/flowtable hook_list to transaction hook_list breaks netlink dump path readers of this RCU-protected list.
It should be possible use an array for nft_trans_hook to store the deleted hooks to compact the representation but I am not expecting many hook object, specially now that wildcard support for devices is in place.
Note that the nft_trans_chain_hooks() list contains a list of struct nft_trans_hook objects for DELCHAIN and DELFLOWTABLE commands, while this list stores struct nft_hook objects for NEWCHAIN and NEWFLOWTABLE. Note that new commands can be updated to use nft_trans_hook for consistency.
--- include/net/netfilter/nf_tables.h | 13 ++++ net/netfilter/nf_tables_api.c | 124 ++++++++++++++++++++++++++---- 2 files changed, 120 insertions(+), 17 deletions(-)
include/net/netfilter/nf_tables.h +13 -0
@@ -1216,12 +1216,15 @@ struct nft_stats {struct u64_stats_sync syncp; }; +#define NFT_HOOK_REMOVE (1 << 0) +struct nft_hook {struct list_head list;struct list_head ops_list;struct rcu_head rcu;char ifname[IFNAMSIZ ];u8 ifnamelen; +u8 flags; }; struct nf_hook_ops *nft_hook_find_ops(const struct nft_hook *hook,
@@ -1676,6 +1679,16 @@ struct nft_trans { u8 put_net:1; }; +/** +* struct nft_trans_hook - nf_tables hook update in transaction +* @list: used internally +* @hook: struct nft_hook with the device hook +*/ +struct nft_trans_hook { +struct list_head list; +struct nft_hook *hook; +}; +/** * struct nft_trans_binding - nf_tables object with binding support in transaction * @nft_trans: base structure, MUST be first member
net/netfilter/nf_tables_api.c +107 -17
227 lines not on this page · raw message
Signature · 1 line
2.47.3