* [PATCH 6.1.y 0/2] ksmbd: fix residual active_num_conn leak on 6.1.y
@ 2026-05-12 2:46 Ferry Meng
2026-05-12 2:46 ` [PATCH 6.1.y 1/2] ksmbd: make ksmbd thread names distinct by client IP Ferry Meng
2026-05-12 2:46 ` [PATCH 6.1.y 2/2] smb: server: fix active_num_conn leak on transport allocation failure Ferry Meng
0 siblings, 2 replies; 3+ messages in thread
From: Ferry Meng @ 2026-05-12 2:46 UTC (permalink / raw)
To: stable; +Cc: Namjae Jeon, Steve French
This series closes a residual active_num_conn leak on the 6.1.y stable
Upstream commits 77ffbcac4e56 ("smb: server: fix leak of active_num_conn
in ksmbd_tcp_new_connection()") and 6551300dc452 ("smb: server: fix
active_num_conn leak on transport allocation failure") have already been
backported to 6.1.y, but upstream 77ffbcac4e56 was built on top of
5da92a251e41 ("ksmbd: make ksmbd thread names distinct by client IP"),
which removes kernel_getpeername() and the out_error: label in
ksmbd_tcp_new_connection().
This series picks up the missing dependency commit and the follow-up fix
so that 6.1.y has the same failure-path semantics as mainline.
Michael Bommarito (1):
smb: server: fix active_num_conn leak on transport allocation failure
Namjae Jeon (1):
ksmbd: make ksmbd thread names distinct by client IP
fs/smb/server/transport_tcp.c | 41 +++++++++++++----------------------
1 file changed, 15 insertions(+), 26 deletions(-)
--
2.43.5
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH 6.1.y 1/2] ksmbd: make ksmbd thread names distinct by client IP
2026-05-12 2:46 [PATCH 6.1.y 0/2] ksmbd: fix residual active_num_conn leak on 6.1.y Ferry Meng
@ 2026-05-12 2:46 ` Ferry Meng
2026-05-12 2:46 ` [PATCH 6.1.y 2/2] smb: server: fix active_num_conn leak on transport allocation failure Ferry Meng
1 sibling, 0 replies; 3+ messages in thread
From: Ferry Meng @ 2026-05-12 2:46 UTC (permalink / raw)
To: stable; +Cc: Namjae Jeon, Steve French
From: Namjae Jeon <linkinjeon@kernel.org>
commit 5da92a251e41f824d7e6b4d54d65dcdcfd69fda3 upstream.
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>
Stable-dep-of: 77ffbcac4e56 ("smb: server: fix leak of active_num_conn in ksmbd_tcp_new_connection()")
Stable-dep-of: 97f8d2648ef4 ("smb: server: fix active_num_conn leak on transport allocation failure")
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 8a1a61d22dac..179b0985645e 100644
--- a/fs/smb/server/transport_tcp.c
+++ b/fs/smb/server/transport_tcp.c
@@ -169,17 +169,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
@@ -191,7 +180,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;
@@ -202,27 +190,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] 3+ messages in thread
* [PATCH 6.1.y 2/2] smb: server: fix active_num_conn leak on transport allocation failure
2026-05-12 2:46 [PATCH 6.1.y 0/2] ksmbd: fix residual active_num_conn leak on 6.1.y Ferry Meng
2026-05-12 2:46 ` [PATCH 6.1.y 1/2] ksmbd: make ksmbd thread names distinct by client IP Ferry Meng
@ 2026-05-12 2:46 ` Ferry Meng
1 sibling, 0 replies; 3+ messages in thread
From: Ferry Meng @ 2026-05-12 2:46 UTC (permalink / raw)
To: stable; +Cc: Namjae Jeon, Steve French, Michael Bommarito, Greg Kroah-Hartman
From: Michael Bommarito <michael.bommarito@gmail.com>
commit 6551300dc452ac16a855a83dbd1e74899542d3b3 upstream.
Commit 77ffbcac4e56 ("smb: server: fix leak of active_num_conn in
ksmbd_tcp_new_connection()") addressed the kthread_run() failure
path. The earlier alloc_transport() == NULL path in the same
function has the same leak, is reachable pre-authentication via any
TCP connect to port 445, and was empirically reproduced on UML
(ARCH=um, v7.0-rc7): a small number of forced allocation failures
were sufficient to put ksmbd into a state where every subsequent
connection attempt was rejected for the remainder of the boot.
ksmbd_kthread_fn() increments active_num_conn before calling
ksmbd_tcp_new_connection() and discards the return value, so when
alloc_transport() returns NULL the socket is released and -ENOMEM
returned without decrementing the counter. Each such failure
permanently consumes one slot from the max_connections pool; once
cumulative failures reach the cap, atomic_inc_return() hits the
threshold on every subsequent accept and every new connection is
rejected. The counter is only reset by module reload.
An unauthenticated remote attacker can drive the server toward the
memory pressure that makes alloc_transport() fail by holding open
connections with large RFC1002 lengths up to MAX_STREAM_PROT_LEN
(0x00FFFFFF); natural transient allocation failures on a loaded
host produce the same drift more slowly.
Mirror the existing rollback pattern in ksmbd_kthread_fn(): on the
alloc_transport() failure path, decrement active_num_conn gated on
server_conf.max_connections.
Repro details: with the patch reverted, forced alloc_transport()
NULL returns leaked counter slots and subsequent connection
attempts -- including legitimate connects issued after the
forced-fail window had closed -- were all rejected with "Limit the
maximum number of connections". With this patch applied, the same
connect sequence produces no rejections and the counter cycles
cleanly between zero and one on every accept.
Fixes: 0d0d4680db22 ("ksmbd: add max connections parameter")
Cc: stable@vger.kernel.org
Assisted-by: Claude:claude-opus-4-6
Assisted-by: Codex:gpt-5-4
Signed-off-by: Michael Bommarito <michael.bommarito@gmail.com>
Acked-by: Namjae Jeon <linkinjeon@kernel.org>
Signed-off-by: Steve French <stfrench@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Ferry Meng <mengferry@linux.alibaba.com>
---
fs/smb/server/transport_tcp.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/fs/smb/server/transport_tcp.c b/fs/smb/server/transport_tcp.c
index 179b0985645e..f9961df03339 100644
--- a/fs/smb/server/transport_tcp.c
+++ b/fs/smb/server/transport_tcp.c
@@ -187,6 +187,8 @@ static int ksmbd_tcp_new_connection(struct socket *client_sk)
t = alloc_transport(client_sk);
if (!t) {
sock_release(client_sk);
+ if (server_conf.max_connections)
+ atomic_dec(&active_num_conn);
return -ENOMEM;
}
--
2.43.5
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-05-12 2:46 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-12 2:46 [PATCH 6.1.y 0/2] ksmbd: fix residual active_num_conn leak on 6.1.y Ferry Meng
2026-05-12 2:46 ` [PATCH 6.1.y 1/2] ksmbd: make ksmbd thread names distinct by client IP Ferry Meng
2026-05-12 2:46 ` [PATCH 6.1.y 2/2] smb: server: fix active_num_conn leak on transport allocation failure Ferry Meng
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox