Re: [syzbot] [netfilter?] KASAN: slab-use-after-free Read in nf_tables_trans_destroy_work
From: Edward Adam Davis
Date: Tue Jul 02 2024 - 11:04:14 EST
Unbalanced increase and decrease of use in the table
#syz test: net-next 1c5fc27bc48a
diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c
index 70d0bad029fd..33139e1b6d46 100644
--- a/net/netfilter/nf_tables_api.c
+++ b/net/netfilter/nf_tables_api.c
@@ -1498,6 +1498,7 @@ static int nf_tables_newtable(struct sk_buff *skb, const struct nfnl_info *info,
if (err < 0)
goto err_trans;
+ nft_use_inc_restore(&table->use);
list_add_tail_rcu(&table->list, &nft_net->tables);
return 0;
err_trans:
@@ -9529,6 +9530,9 @@ static void nft_commit_release(struct nft_trans *trans)
nft_ctx_update(&ctx, trans);
+ if (trans->table)
+ nft_use_dec(&trans->table->use);
+
switch (trans->msg_type) {
case NFT_MSG_DELTABLE:
case NFT_MSG_DESTROYTABLE: