From: Pablo Neira Ayuso <pablo@netfilter.org>
To: netfilter-devel@vger.kernel.org
Subject: [PATCH nf 2/3] netfilter: nf_tables: memleak in nft_expr_init() path
Date: Thu, 2 Jun 2022 09:43:56 +0200 [thread overview]
Message-ID: <20220602074357.332409-2-pablo@netfilter.org> (raw)
In-Reply-To: <20220602074357.332409-1-pablo@netfilter.org>
Since ed0a0c60f0e5 ("netfilter: nft_quota: move stateful fields out of
expression data"), stateful expressions allocate stateful area via
kmalloc().
Call ->ops->destroy() to release expression stateful information before
releasing the expression.
->ops->deactivate() is also called for safety reasons, no stateful
expressions support for this function.
Fixes: 6cafaf4764a3 ("netfilter: nf_tables: fix memory leak if expr init fails")
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
net/netfilter/nf_tables_api.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c
index 5ee4e7b28b61..017b77067852 100644
--- a/net/netfilter/nf_tables_api.c
+++ b/net/netfilter/nf_tables_api.c
@@ -2904,6 +2904,11 @@ static struct nft_expr *nft_expr_init(const struct nft_ctx *ctx,
return expr;
err_expr_new:
+ if (expr->ops->deactivate)
+ expr->ops->deactivate(ctx, expr, NFT_TRANS_RELEASE);
+ if (expr_info.ops->destroy)
+ expr_info.ops->destroy(ctx, expr);
+
kfree(expr);
err_expr_stateful:
owner = expr_info.ops->type->owner;
--
2.30.2
next prev parent reply other threads:[~2022-06-02 7:44 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-02 7:43 [PATCH nf 1/3,v3] netfilter: nf_tables: delete flowtable hooks via transaction list Pablo Neira Ayuso
2022-06-02 7:43 ` Pablo Neira Ayuso [this message]
2022-06-02 21:30 ` [PATCH nf 2/3] netfilter: nf_tables: memleak in nft_expr_init() path Pablo Neira Ayuso
2022-06-02 7:43 ` [PATCH nf 3/3] netfilter: nf_tables: always initialize flowtable hook list in transaction Pablo Neira Ayuso
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220602074357.332409-2-pablo@netfilter.org \
--to=pablo@netfilter.org \
--cc=netfilter-devel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).