Commit 43eb8949 authored by Pablo Neira Ayuso's avatar Pablo Neira Ayuso

netfilter: nf_tables: do not leave chain stats enabled on error

Error might occur later in the nf_tables_addchain() codepath, enable
static key only after transaction has been created.

Fixes: 9f08ea84 ("netfilter: nf_tables: keep chain counters away from hot path")
Signed-off-by: default avatarPablo Neira Ayuso <pablo@netfilter.org>
parent 7044ab28
...@@ -2195,9 +2195,9 @@ static int nf_tables_addchain(struct nft_ctx *ctx, u8 family, u8 genmask, ...@@ -2195,9 +2195,9 @@ static int nf_tables_addchain(struct nft_ctx *ctx, u8 family, u8 genmask,
struct netlink_ext_ack *extack) struct netlink_ext_ack *extack)
{ {
const struct nlattr * const *nla = ctx->nla; const struct nlattr * const *nla = ctx->nla;
struct nft_stats __percpu *stats = NULL;
struct nft_table *table = ctx->table; struct nft_table *table = ctx->table;
struct nft_base_chain *basechain; struct nft_base_chain *basechain;
struct nft_stats __percpu *stats;
struct net *net = ctx->net; struct net *net = ctx->net;
char name[NFT_NAME_MAXLEN]; char name[NFT_NAME_MAXLEN];
struct nft_rule_blob *blob; struct nft_rule_blob *blob;
...@@ -2235,7 +2235,6 @@ static int nf_tables_addchain(struct nft_ctx *ctx, u8 family, u8 genmask, ...@@ -2235,7 +2235,6 @@ static int nf_tables_addchain(struct nft_ctx *ctx, u8 family, u8 genmask,
return PTR_ERR(stats); return PTR_ERR(stats);
} }
rcu_assign_pointer(basechain->stats, stats); rcu_assign_pointer(basechain->stats, stats);
static_branch_inc(&nft_counters_enabled);
} }
err = nft_basechain_init(basechain, family, &hook, flags); err = nft_basechain_init(basechain, family, &hook, flags);
...@@ -2318,6 +2317,9 @@ static int nf_tables_addchain(struct nft_ctx *ctx, u8 family, u8 genmask, ...@@ -2318,6 +2317,9 @@ static int nf_tables_addchain(struct nft_ctx *ctx, u8 family, u8 genmask,
goto err_unregister_hook; goto err_unregister_hook;
} }
if (stats)
static_branch_inc(&nft_counters_enabled);
table->use++; table->use++;
return 0; return 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment