From: Simon Horman <horms@kernel.org>
To: Zilin Guan <zilin@seu.edu.cn>
Cc: chuck.lever@oracle.com, davem@davemloft.net, edumazet@google.com,
kuba@kernel.org, pabeni@redhat.com,
kernel-tls-handshake@lists.linux.dev, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org, jianhao.xu@seu.edu.cn
Subject: Re: [PATCH] net/handshake: Fix memory leak in tls_handshake_accept()
Date: Fri, 7 Nov 2025 10:17:09 +0000 [thread overview]
Message-ID: <aQ3HJRwkz6j512o7@horms.kernel.org> (raw)
In-Reply-To: <20251106144511.3859535-1-zilin@seu.edu.cn>
On Thu, Nov 06, 2025 at 02:45:11PM +0000, Zilin Guan wrote:
> In tls_handshake_accept(), a netlink message is allocated using
> genlmsg_new(). In the error handling path, genlmsg_cancel() is called
> to cancel the message construction, but the message itself is not freed.
> This leads to a memory leak.
>
> Fix this by calling nlmsg_free() in the error path after genlmsg_cancel()
> to release the allocated memory.
>
> Fixes: 2fd5532044a89 ("net/handshake: Add a kernel API for requesting a TLSv1.3 handshake")
> Signed-off-by: Zilin Guan <zilin@seu.edu.cn>
> ---
> net/handshake/tlshd.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/net/handshake/tlshd.c b/net/handshake/tlshd.c
> index 081093dfd553..8f9532a15f43 100644
> --- a/net/handshake/tlshd.c
> +++ b/net/handshake/tlshd.c
> @@ -259,6 +259,7 @@ static int tls_handshake_accept(struct handshake_req *req,
>
> out_cancel:
> genlmsg_cancel(msg, hdr);
Hi Zilin Guan,
I don't think genlmsg_cancel() is necessary if msg is freed on the next line.
If so, I suggest removing it, and renaming out_cancel accordingly.
> + nlmsg_free(msg);
> out:
> return ret;
> }
> --
> 2.34.1
>
next prev parent reply other threads:[~2025-11-07 10:17 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-06 14:45 [PATCH] net/handshake: Fix memory leak in tls_handshake_accept() Zilin Guan
2025-11-06 16:26 ` Chuck Lever
2025-11-07 10:17 ` Simon Horman [this message]
2025-11-08 4:47 ` Zilin Guan
2025-11-11 2:10 ` patchwork-bot+netdevbpf
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=aQ3HJRwkz6j512o7@horms.kernel.org \
--to=horms@kernel.org \
--cc=chuck.lever@oracle.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=jianhao.xu@seu.edu.cn \
--cc=kernel-tls-handshake@lists.linux.dev \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--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).