netfilter: nf_tables: move set_update_list to nftables per-netns
Subsystems (2)
Pablo Neira Ayuso
maintainerPATCH 1/2 netfilter: nf_tables: move set_update_list to nftables per-netns
This list is used to invoke the set .commit and .abort ops for the rbtree and pipapo to run GC on expired elements and replace the current datastructure view by the clone. For the rbtree, this also rebuild the datapath b-search array.
From abort path, remove the set from the update_list if it is already bound to rule, then the rule itself takes care of releasing the set and its elements, otherwise, memleak is possible because set ops .abort only deals with removing the set data structure, not the elements.
This is a preparation patch to call set .commit before processing the transaction list for the rbtree, no functional changes are intended.
---
v1: reset versioning since patch 2/2 in this series differs, no changes
include/net/netfilter/nf_tables.h | 1 + net/netfilter/nf_tables_api.c | 49 ++++++++++--------------------- 2 files changed, 16 insertions(+), 34 deletions(-)
include/net/netfilter/nf_tables.h +1 -0
@@ -1949,6 +1949,7 @@ struct nftables_pernet {struct list_head binding_list;struct list_head module_list;struct list_head notify_list; +struct list_head set_update_list;struct mutex commit_mutex;u64 table_handle;u64 tstamp;
net/netfilter/nf_tables_api.c +15 -34
140 lines not on this page · raw message
Signature · 1 line
2.47.3
Pablo Neira Ayuso
maintainerPATCH 2/2 netfilter: nf_tables: call set ops .commit when building new ruleset blob
The rbtree set only builds the b-search array after the new ruleset has been published through set ops .commit.
This exposes an empty set for a short time span which results in a bogus mismatch for the following batch:
destroy table ip x
table ip x {
...}
The same problem also affects the pipapo set backend which also provides a set ops .commit interface too.
This patch moves the set ops .commit call right before building and publishing the chain blob. The commit path now performs an early handling of the DELSETELEM command to remove stale elements from the clone before it is published via rcu. Note that DELSETELEM notifications are still delivered in order. NEWSETELEM commands are handled after the set is published, since this clears the previous genbit to 1 to prepare the element for the next control plane transaction. This comes at the cost of one extra iteration over the transaction list.
---
v1: new in this series
net/netfilter/nf_tables_api.c | 45 +++++++++++++++++++++++++++++++---- 1 file changed, 41 insertions(+), 4 deletions(-)
net/netfilter/nf_tables_api.c +41 -4
@@ -7210,6 +7210,20 @@ static void nft_trans_elems_remove(const struct nft_ctx *ctx, } } +static void nft_trans_elems_remove_notify (const struct nft_ctx *ctx, +const struct nft_trans_elem *te) +{ +int i; + +for (i =0 ; i < te->nelems; i++) { +WARN_ON_ONCE (te->elems[i].update); + +nf_tables_setelem_notify (ctx, te->set, + te->elems[i].priv, + te->nft_trans.msg_type); + } +} +static bool nft_setelem_valid_key_end (const struct nft_set *set,struct nlattr **nla,u32 flags) {
@@ -10853,9 +10867,29 @@ static void nf_tables_commit_audit_log(struct list_head *adl, u32 generation) } } -static void nft_set_commit_update (struct nftables_pernet *nft_net) +static void nft_set_commit_update (struct nft_ctx *ctx, +struct nftables_pernet *nft_net) {struct nft_set *set, *next; +struct nft_trans_elem *te; +struct nft_trans *trans; + +if (list_empty (&nft_net->set_update_list)) +return ; + +list_for_each_entry (trans, &nft_net->commit_list, list) { +nft_ctx_update (ctx, trans); + +switch (trans->msg_type) { +case NFT_MSG_DELSETELEM : + te =nft_trans_container_elem (trans); +if (!te->set->ops->commit) +break ; + +nft_trans_elems_remove (ctx, te); +break ; + } + }list_for_each_entry_safe (set, next, &nft_net->set_update_list, pending_update) {list_del_init (&set->pending_update);
@@ -10964,6 +10998,8 @@ static int nf_tables_commit(struct net *net, struct sk_buff *skb) }/* step 2. Make rules_gen_X visible to packet path */ +nft_set_commit_update (&ctx, nft_net); +list_for_each_entry (table, &nft_net->tables, list) {list_for_each_entry (chain, &table->chains, list)nf_tables_commit_chain (net, chain);
@@ -11101,7 +11137,10 @@ static int nf_tables_commit(struct net *net, struct sk_buff *skb)case NFT_MSG_DELSETELEM :case NFT_MSG_DESTROYSETELEM : te =nft_trans_container_elem (trans); -nft_trans_elems_remove (&ctx, te); +if (te->set->ops->commit) +nft_trans_elems_remove_notify (&ctx, te); +else +nft_trans_elems_remove (&ctx, te);break ;case NFT_MSG_NEWOBJ :if (nft_trans_obj_update (trans)) {
@@ -11170,8 +11209,6 @@ static int nf_tables_commit(struct net *net, struct sk_buff *skb) } } -nft_set_commit_update (nft_net); -nft_commit_notify (net,NETLINK_CB (skb).portid);nf_tables_gen_notify (net, skb,NFT_MSG_NEWGEN );nf_tables_commit_audit_log (&adl,nft_base_seq (net));
Signature · 1 line
2.47.3