Skip to content

Commit

Permalink
netfilter: nf_tables: fix memory leak if expr init fails
Browse files Browse the repository at this point in the history
If expr init fails then we need to free it.

So when the user add a nft rule as follows:

  # nft add rule filter input tcp dport 22 flow table ssh \
    { ip saddr limit rate 0/second }

memory leak will happen.

Signed-off-by: Liping Zhang <liping.zhang@spreadtrum.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
  • Loading branch information
Liping Zhang authored and Pablo Neira Ayuso committed Jun 23, 2016
1 parent acd43fe commit 6cafaf4
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion net/netfilter/nf_tables_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -1724,9 +1724,11 @@ struct nft_expr *nft_expr_init(const struct nft_ctx *ctx,

err = nf_tables_newexpr(ctx, &info, expr);
if (err < 0)
goto err2;
goto err3;

return expr;
err3:
kfree(expr);
err2:
module_put(info.ops->type->owner);
err1:
Expand Down

0 comments on commit 6cafaf4

Please sign in to comment.