From: Steffen Klassert <steffen.klassert@secunet.com>
To: Sabrina Dubroca <sd@queasysnail.net>
Cc: Zilin Guan <zilin@seu.edu.cn>, <herbert@gondor.apana.org.au>,
<davem@davemloft.net>, <edumazet@google.com>, <kuba@kernel.org>,
<pabeni@redhat.com>, <horms@kernel.org>, <netdev@vger.kernel.org>,
<linux-kernel@vger.kernel.org>, <jianhao.xu@seu.edu.cn>
Subject: Re: [PATCH v2] xfrm: fix memory leak in xfrm_add_acquire()
Date: Fri, 14 Nov 2025 10:14:06 +0100 [thread overview]
Message-ID: <aRby3noCsM-TKfkZ@secunet.com> (raw)
In-Reply-To: <aRJwPMPsvMfxSj1u@krikkit>
On Tue, Nov 11, 2025 at 12:07:40AM +0100, Sabrina Dubroca wrote:
> note: the subject prefix should be [PATCH ipsec vX] for fixes to the
> ipsec tree. (sorry, I forgot to mention that in v1)
>
> 2025-11-10, 06:41:25 +0000, Zilin Guan wrote:
> > The xfrm_add_acquire() function constructs an xfrm policy by calling
> > xfrm_policy_construct(). This allocates the policy structure and
> > potentially associates a security context and a device policy with it.
> >
> > However, at the end of the function, the policy object is freed using
> > only kfree() . This skips the necessary cleanup for the security context
> > and device policy, leading to a memory leak.
> >
> > To fix this, invoke the proper cleanup functions xfrm_dev_policy_delete(),
> > xfrm_dev_policy_free(), and security_xfrm_policy_free() before freeing the
> > policy object. This approach mirrors the error handling path in
> > xfrm_add_policy(), ensuring that all associated resources are correctly
> > released.
> >
> > Fixes: 980ebd25794f ("[IPSEC]: Sync series - acquire insert")
> > Signed-off-by: Zilin Guan <zilin@seu.edu.cn>
> > ---
> > Changes in v2:
> > - Use the correct cleanup functions as per xfrm_add_policy().
> > ---
> > net/xfrm/xfrm_user.c | 3 +++
> > 1 file changed, 3 insertions(+)
>
> Reviewed-by: Sabrina Dubroca <sd@queasysnail.net>
Applied to the ipsec tree, thanks everyone!
prev parent reply other threads:[~2025-11-14 9:14 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-10 6:41 [PATCH v2] xfrm: fix memory leak in xfrm_add_acquire() Zilin Guan
2025-11-10 23:07 ` Sabrina Dubroca
2025-11-14 9:14 ` Steffen Klassert [this message]
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=aRby3noCsM-TKfkZ@secunet.com \
--to=steffen.klassert@secunet.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=herbert@gondor.apana.org.au \
--cc=horms@kernel.org \
--cc=jianhao.xu@seu.edu.cn \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=sd@queasysnail.net \
--cc=zilin@seu.edu.cn \
/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).