* [PATCH] net/handshake: Fix memory leak in tls_handshake_accept()
@ 2025-11-06 14:45 Zilin Guan
2025-11-06 16:26 ` Chuck Lever
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Zilin Guan @ 2025-11-06 14:45 UTC (permalink / raw)
To: chuck.lever
Cc: davem, edumazet, kuba, pabeni, horms, kernel-tls-handshake,
netdev, linux-kernel, jianhao.xu, Zilin Guan
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);
+ nlmsg_free(msg);
out:
return ret;
}
--
2.34.1
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH] net/handshake: Fix memory leak in tls_handshake_accept() 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 2025-11-11 2:10 ` patchwork-bot+netdevbpf 2 siblings, 0 replies; 5+ messages in thread From: Chuck Lever @ 2025-11-06 16:26 UTC (permalink / raw) To: Zilin Guan Cc: davem, edumazet, kuba, pabeni, horms, kernel-tls-handshake, netdev, linux-kernel, jianhao.xu On 11/6/25 9:45 AM, 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); > + nlmsg_free(msg); > out: > return ret; > } Reviewed-by: Chuck Lever <chuck.lever@oracle.com> -- Chuck Lever ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] net/handshake: Fix memory leak in tls_handshake_accept() 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 2025-11-08 4:47 ` Zilin Guan 2025-11-11 2:10 ` patchwork-bot+netdevbpf 2 siblings, 1 reply; 5+ messages in thread From: Simon Horman @ 2025-11-07 10:17 UTC (permalink / raw) To: Zilin Guan Cc: chuck.lever, davem, edumazet, kuba, pabeni, kernel-tls-handshake, netdev, linux-kernel, jianhao.xu 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 > ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] net/handshake: Fix memory leak in tls_handshake_accept() 2025-11-07 10:17 ` Simon Horman @ 2025-11-08 4:47 ` Zilin Guan 0 siblings, 0 replies; 5+ messages in thread From: Zilin Guan @ 2025-11-08 4:47 UTC (permalink / raw) To: horms Cc: chuck.lever, davem, edumazet, jianhao.xu, kernel-tls-handshake, kuba, linux-kernel, netdev, pabeni, zilin On Fri, Nov 07, 2025 at 10:17:09AM +0000, Simon Horman wrote: > 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 > > Hi Simon, Thanks for your review. I followed the pattern I observed in other parts of the kernel, for example, in cifs_swn_send_register_message() in fs/smb/client/cifs_swn.c, where genlmsg_cancel() is also called before nlmsg_free() in the error path. My understanding is that this is the proper way to unwind the message construction before freeing it. If you still believe it's unnecessary, I am happy to send a v2 patch to remove it. Best regards, Zilin Guan ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] net/handshake: Fix memory leak in tls_handshake_accept() 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 @ 2025-11-11 2:10 ` patchwork-bot+netdevbpf 2 siblings, 0 replies; 5+ messages in thread From: patchwork-bot+netdevbpf @ 2025-11-11 2:10 UTC (permalink / raw) To: Zilin Guan Cc: chuck.lever, davem, edumazet, kuba, pabeni, horms, kernel-tls-handshake, netdev, linux-kernel, jianhao.xu Hello: This patch was applied to netdev/net.git (main) by Jakub Kicinski <kuba@kernel.org>: On Thu, 6 Nov 2025 14:45:11 +0000 you 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. > > [...] Here is the summary with links: - net/handshake: Fix memory leak in tls_handshake_accept() https://git.kernel.org/netdev/net/c/3072f00bba76 You are awesome, thank you! -- Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-11-11 2:10 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 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 2025-11-08 4:47 ` Zilin Guan 2025-11-11 2:10 ` patchwork-bot+netdevbpf
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).