When an anonymous set is bound to a rule, __nft_set_trans_bind() marks the NEWSET and NEWSETELEM transactions of that set as bound. It walks the whole commit list to do so, so a batch adding N rules that each use an anonymous set takes time quadratic in N. The walk was introduced in commit f6ac85858976 ("netfilter: nf_tables: unbind set in rule from commit path") to stop at the NEWSET transaction of the set, which is likely close to the tail of the list. Commit 6a0a8d10a366 ("netfilter: nf_tables: use-after-free in failing rule with bound set") turned the condition into a switch statement to also mark NEWSETELEM transactions, so the break statement only leaves the switch and the loop runs to the head of the list. Stopping at the NEWSET transaction is still sufficient. Anonymous sets cannot be updated, so there is only one NEWSET transaction per set, and elements can only be added after the set was created. Since the list is walked starting from the newest transaction, all transactions referring to the set have been seen once its NEWSET transaction is found. Signed-off-by: Stefan Hanreich --- net/netfilter/nf_tables_api.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c index 9fe234e329df..c9b0070846b7 100644 --- a/net/netfilter/nf_tables_api.c +++ b/net/netfilter/nf_tables_api.c @@ -248,8 +248,10 @@ static void __nft_set_trans_bind(const struct nft_ctx *ctx, struct nft_set *set, list_for_each_entry_reverse(trans, &nft_net->commit_list, list) { switch (trans->msg_type) { case NFT_MSG_NEWSET: - if (nft_trans_set(trans) == set) + if (nft_trans_set(trans) == set) { nft_trans_set_bound(trans) = bind; + return; + } break; case NFT_MSG_NEWSETELEM: if (nft_trans_elem_set(trans) == set) -- 2.47.3