Linux kernel -stable discussions
 help / color / mirror / Atom feed
* [PATCH 6.6.y] ksmbd: make ksmbd thread names distinct by client IP
@ 2026-05-11 12:46 Ferry Meng
  2026-05-12  0:17 ` Sasha Levin
  0 siblings, 1 reply; 2+ messages in thread
From: Ferry Meng @ 2026-05-11 12:46 UTC (permalink / raw)
  To: stable
  Cc: Namjae Jeon, Steve French, Sergey Senozhatsky, Tom Talpey,
	Henrique Carvalho, Greg Kroah-Hartman, linux-cifs, linux-kernel,
	Ferry Meng

From: Namjae Jeon <linkinjeon@kernel.org>

commit 5da92a251e41f824d7e6b4d54d65dcdcfd69fda3 upstream.

[backport needed for 6.6-stable to close a residual
 active_num_conn leak. Commits 787769c8cc50 (upstream 77ffbcac4e56,
 "smb: server: fix leak of active_num_conn in ksmbd_tcp_new_connection()")
 and 97f8d2648ef4 (upstream 6551300dc452, "smb: server: fix
 active_num_conn leak on transport allocation failure") were
 backported to 6.6.y, but upstream 77ffbcac4e56 was built on top
 of this commit, which removes kernel_getpeername() and the
 out_error: label in ksmbd_tcp_new_connection(). Without this
 commit, the kernel_getpeername() failure path still calls
 free_transport(t) and leaks active_num_conn, eventually
 exhausting max_connections until the module is reloaded.]

This patch makes ksmbd thread names distinct by client IP address.

100943 ?        S      0:00 [ksmbd:::ffff:10.177.110.57]
 or
101752 ?        S      0:00 [ksmbd:10.177.110.57]

Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
Signed-off-by: Steve French <stfrench@microsoft.com>
Signed-off-by: Ferry Meng <mengferry@linux.alibaba.com>
---
 fs/smb/server/transport_tcp.c | 39 ++++++++++++-----------------------
 1 file changed, 13 insertions(+), 26 deletions(-)

diff --git a/fs/smb/server/transport_tcp.c b/fs/smb/server/transport_tcp.c
index e55afd0c9bf4..f04aa8c504ff 100644
--- a/fs/smb/server/transport_tcp.c
+++ b/fs/smb/server/transport_tcp.c
@@ -173,17 +173,6 @@ static struct kvec *get_conn_iovec(struct tcp_transport *t, unsigned int nr_segs
 	return new_iov;
 }
 
-static unsigned short ksmbd_tcp_get_port(const struct sockaddr *sa)
-{
-	switch (sa->sa_family) {
-	case AF_INET:
-		return ntohs(((struct sockaddr_in *)sa)->sin_port);
-	case AF_INET6:
-		return ntohs(((struct sockaddr_in6 *)sa)->sin6_port);
-	}
-	return 0;
-}
-
 /**
  * ksmbd_tcp_new_connection() - create a new tcp session on mount
  * @client_sk:	socket associated with new connection
@@ -195,7 +184,6 @@ static unsigned short ksmbd_tcp_get_port(const struct sockaddr *sa)
  */
 static int ksmbd_tcp_new_connection(struct socket *client_sk)
 {
-	struct sockaddr *csin;
 	int rc = 0;
 	struct tcp_transport *t;
 	struct task_struct *handler;
@@ -208,27 +196,26 @@ static int ksmbd_tcp_new_connection(struct socket *client_sk)
 		return -ENOMEM;
 	}
 
-	csin = KSMBD_TCP_PEER_SOCKADDR(KSMBD_TRANS(t)->conn);
-	if (kernel_getpeername(client_sk, csin) < 0) {
-		pr_err("client ip resolution failed\n");
-		rc = -EINVAL;
-		goto out_error;
-	}
-
+#if IS_ENABLED(CONFIG_IPV6)
+	if (client_sk->sk->sk_family == AF_INET6)
+		handler = kthread_run(ksmbd_conn_handler_loop,
+				KSMBD_TRANS(t)->conn, "ksmbd:%pI6c",
+				&KSMBD_TRANS(t)->conn->inet6_addr);
+	else
+		handler = kthread_run(ksmbd_conn_handler_loop,
+				KSMBD_TRANS(t)->conn, "ksmbd:%pI4",
+				&KSMBD_TRANS(t)->conn->inet_addr);
+#else
 	handler = kthread_run(ksmbd_conn_handler_loop,
-			      KSMBD_TRANS(t)->conn,
-			      "ksmbd:%u",
-			      ksmbd_tcp_get_port(csin));
+			KSMBD_TRANS(t)->conn, "ksmbd:%pI4",
+			&KSMBD_TRANS(t)->conn->inet_addr);
+#endif
 	if (IS_ERR(handler)) {
 		pr_err("cannot start conn thread\n");
 		rc = PTR_ERR(handler);
 		ksmbd_tcp_disconnect(KSMBD_TRANS(t));
 	}
 	return rc;
-
-out_error:
-	free_transport(t);
-	return rc;
 }
 
 /**
-- 
2.43.5


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH 6.6.y] ksmbd: make ksmbd thread names distinct by client IP
  2026-05-11 12:46 [PATCH 6.6.y] ksmbd: make ksmbd thread names distinct by client IP Ferry Meng
@ 2026-05-12  0:17 ` Sasha Levin
  0 siblings, 0 replies; 2+ messages in thread
From: Sasha Levin @ 2026-05-12  0:17 UTC (permalink / raw)
  To: stable
  Cc: Sasha Levin, Namjae Jeon, Steve French, Sergey Senozhatsky,
	Tom Talpey, Henrique Carvalho, Greg Kroah-Hartman, linux-cifs,
	linux-kernel, Ferry Meng

On Mon, May 11, 2026 at 08:46:25PM +0800, Ferry Meng wrote:
> [backport needed for 6.6-stable to close a residual
>  active_num_conn leak. ...]

I think its needed for 6.12 too?

-- 
Thanks,
Sasha

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-05-12  0:18 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-11 12:46 [PATCH 6.6.y] ksmbd: make ksmbd thread names distinct by client IP Ferry Meng
2026-05-12  0:17 ` Sasha Levin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox