]> git.itanic.dy.fi Git - linux-stable/blobdiff - net/netfilter/nf_tables_api.c
netfilter: nf_tables: fix nft_counters_enabled underflow at nf_tables_addchain()
[linux-stable] / net / netfilter / nf_tables_api.c
index 848cc81d69926c7ba8a9a176f5e889ea9e03811a..3aaf36df69d4676c62dda1c5026de61f7965f4ac 100644 (file)
@@ -2197,7 +2197,6 @@ static int nf_tables_addchain(struct nft_ctx *ctx, u8 family, u8 genmask,
                              struct netlink_ext_ack *extack)
 {
        const struct nlattr * const *nla = ctx->nla;
-       struct nft_stats __percpu *stats = NULL;
        struct nft_table *table = ctx->table;
        struct nft_base_chain *basechain;
        struct net *net = ctx->net;
@@ -2212,6 +2211,7 @@ static int nf_tables_addchain(struct nft_ctx *ctx, u8 family, u8 genmask,
                return -EOVERFLOW;
 
        if (nla[NFTA_CHAIN_HOOK]) {
+               struct nft_stats __percpu *stats = NULL;
                struct nft_chain_hook hook;
 
                if (flags & NFT_CHAIN_BINDING)
@@ -2245,6 +2245,8 @@ static int nf_tables_addchain(struct nft_ctx *ctx, u8 family, u8 genmask,
                        kfree(basechain);
                        return err;
                }
+               if (stats)
+                       static_branch_inc(&nft_counters_enabled);
        } else {
                if (flags & NFT_CHAIN_BASE)
                        return -EINVAL;
@@ -2319,9 +2321,6 @@ static int nf_tables_addchain(struct nft_ctx *ctx, u8 family, u8 genmask,
                goto err_unregister_hook;
        }
 
-       if (stats)
-               static_branch_inc(&nft_counters_enabled);
-
        table->use++;
 
        return 0;