netfilter: nf_tables: destroy the set if fail to add transaction
authorLiping Zhang <zlpnobody@gmail.com>
Sat, 29 Oct 2016 14:03:05 +0000 (22:03 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sun, 10 May 2020 08:26:17 +0000 (10:26 +0200)
commit c17c3cdff10b9f59ef1244a14604f10949f17117 upstream.

When the memory is exhausted, then we will fail to add the NFT_MSG_NEWSET
transaction. In such case, we should destroy the set before we free it.

Fixes: 958bee14d071 ("netfilter: nf_tables: use new transaction infrastructure to handle sets")
Signed-off-by: Liping Zhang <zlpnobody@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
net/netfilter/nf_tables_api.c

index a7967af0da82d108e6abea04bdadceb927f1e2be..6203995003a51dfc4c9beb78562830325f5e6b75 100644 (file)
@@ -2849,12 +2849,14 @@ static int nf_tables_newset(struct net *net, struct sock *nlsk,
 
        err = nft_trans_set_add(&ctx, NFT_MSG_NEWSET, set);
        if (err < 0)
-               goto err2;
+               goto err3;
 
        list_add_tail_rcu(&set->list, &table->sets);
        table->use++;
        return 0;
 
+err3:
+       ops->destroy(set);
 err2:
        kfree(set);
 err1: