Skip to content

Commit

Permalink
netfilter: nft_ct: fix unpaired nf_connlabels_get/put call
Browse files Browse the repository at this point in the history
We only get nf_connlabels if the user add ct label set expr successfully,
but we will also put nf_connlabels if the user delete ct lable get expr.
This is mismathced, and will cause ct label expr cannot work properly.

Also, if we init something fail, we should put nf_connlabels back.
Otherwise, we may waste to alloc the memory that will never be used.

Signed-off-by: Liping Zhang <liping.zhang@spreadtrum.com>
Acked-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
  • Loading branch information
Liping Zhang authored and Pablo Neira Ayuso committed Jul 19, 2016
1 parent f4dc777 commit 590025a
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions net/netfilter/nft_ct.c
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,7 @@ static int nft_ct_set_init(const struct nft_ctx *ctx,
const struct nlattr * const tb[])
{
struct nft_ct *priv = nft_expr_priv(expr);
bool label_got = false;
unsigned int len;
int err;

Expand All @@ -384,6 +385,7 @@ static int nft_ct_set_init(const struct nft_ctx *ctx,
err = nf_connlabels_get(ctx->net, (len * BITS_PER_BYTE) - 1);
if (err)
return err;
label_got = true;
break;
#endif
default:
Expand All @@ -393,17 +395,28 @@ static int nft_ct_set_init(const struct nft_ctx *ctx,
priv->sreg = nft_parse_register(tb[NFTA_CT_SREG]);
err = nft_validate_register_load(priv->sreg, len);
if (err < 0)
return err;
goto err1;

err = nft_ct_l3proto_try_module_get(ctx->afi->family);
if (err < 0)
return err;
goto err1;

return 0;

err1:
if (label_got)
nf_connlabels_put(ctx->net);
return err;
}

static void nft_ct_get_destroy(const struct nft_ctx *ctx,
const struct nft_expr *expr)
{
nft_ct_l3proto_module_put(ctx->afi->family);
}

static void nft_ct_destroy(const struct nft_ctx *ctx,
const struct nft_expr *expr)
static void nft_ct_set_destroy(const struct nft_ctx *ctx,
const struct nft_expr *expr)
{
struct nft_ct *priv = nft_expr_priv(expr);

Expand Down Expand Up @@ -475,7 +488,7 @@ static const struct nft_expr_ops nft_ct_get_ops = {
.size = NFT_EXPR_SIZE(sizeof(struct nft_ct)),
.eval = nft_ct_get_eval,
.init = nft_ct_get_init,
.destroy = nft_ct_destroy,
.destroy = nft_ct_get_destroy,
.dump = nft_ct_get_dump,
};

Expand All @@ -484,7 +497,7 @@ static const struct nft_expr_ops nft_ct_set_ops = {
.size = NFT_EXPR_SIZE(sizeof(struct nft_ct)),
.eval = nft_ct_set_eval,
.init = nft_ct_set_init,
.destroy = nft_ct_destroy,
.destroy = nft_ct_set_destroy,
.dump = nft_ct_set_dump,
};

Expand Down

0 comments on commit 590025a

Please sign in to comment.