netfilter: nf_tables: netlink notifier might race to release objects
Subsystems (2)
Pablo Neira Ayuso
maintainerPATCH 1/2 netfilter: nf_tables: netlink notifier might race to release objects
commit release path is invoked via call_rcu and it runs lockless to release the objects after rcu grace period. The netlink notifier handler might win race to remove objects that the transaction context is still referencing from the commit release path.
Call rcu_barrier() to ensure pending rcu callbacks run to completion if the list of transactions to be destroyed is not empty.
---
as a follow up to:
https://patchwork.ozlabs.org/project/netfilter-devel/patch/[email protected]/
net/netfilter/nf_tables_api.c | 2 ++ 1 file changed, 2 insertions(+)
net/netfilter/nf_tables_api.c +2 -0
@@ -10030,6 +10030,8 @@ static int nft_rcv_nl_event(struct notifier_block *this, unsigned long event, nft_net =nft_pernet (net); deleted =0 ;mutex_lock (&nft_net->commit_mutex); +if (!list_empty (&nf_tables_destroy_list)) +rcu_barrier (); again:list_for_each_entry (table, &nft_net->tables, list) { if (nft_table_has_owner(table) &&
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH 2/2 netfilter: nf_tables: release flow rule object from commit path
No need to postpone this to the commit release path, since no packets are walking over this object, this is accessed from control plane only. This helped uncovered UAF triggered by races with the netlink notifier.
--- net/netfilter/nf_tables_api.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
net/netfilter/nf_tables_api.c +3 -3
@@ -8465,9 +8465,6 @@ static void nft_commit_release(struct nft_trans *trans)nf_tables_chain_destroy (&trans->ctx);break ;case NFT_MSG_DELRULE : -if (trans->ctx.chain->flags &NFT_CHAIN_HW_OFFLOAD ) -nft_flow_rule_destroy (nft_trans_flow_rule (trans)); -nf_tables_rule_destroy (&trans->ctx,nft_trans_rule (trans));break ;case NFT_MSG_DELSET :
@@ -8973,6 +8970,9 @@ static int nf_tables_commit(struct net *net, struct sk_buff *skb)nft_rule_expr_deactivate (&trans->ctx,nft_trans_rule (trans),NFT_TRANS_COMMIT ); + +if (trans->ctx.chain->flags &NFT_CHAIN_HW_OFFLOAD ) +nft_flow_rule_destroy (nft_trans_flow_rule (trans));break ;case NFT_MSG_NEWSET :nft_clear (net,nft_trans_set (trans));
Signature · 1 line
2.30.2