Skip to contentSkip to conversation

FAILED: patch "[PATCH] smb: server: fix max_connections off-by-one in tcp accept" failed to apply to 5.15-stable tree

PATCH New [email protected] 2 participants 2 messages Apr 24

Subsystems (2)
lore
Share & tools
lore

[email protected]

author maintainer
#0 lore raw

The patch below does not apply to the 5.15-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.

To reproduce the conflict and resubmit, you may use the following commands:

git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-5.15.y
git checkout FETCH_HEAD
git cherry-pick -x ce23158bfe584bd90d1918f279fdf9de57802012
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026042408-reshuffle-engraved-f843@gregkh' --subject-prefix 'PATCH 5.15.y' HEAD^..

Possible dependencies:

thanks,

greg k-h

------------------ original commit in Linus's tree ------------------

From ce23158bfe584bd90d1918f279fdf9de57802012 Mon Sep 17 00:00:00 2001
From: DaeMyung Kang <[email protected]>
Date: Fri, 17 Apr 2026 06:17:35 +0900
Subject: [PATCH] smb: server: fix max_connections off-by-one in tcp accept
path

The global max_connections check in ksmbd's TCP accept path counts the newly accepted connection with atomic_inc_return(), but then rejects the connection when the result is greater than or equal to server_conf.max_connections.

That makes the effective limit one smaller than configured. For example:

- max_connections=1 rejects the first connection
- max_connections=2 allows only one connection

The per-IP limit in the same function uses <= correctly because it counts only pre-existing connections. The global limit instead checks the post-increment total, so it should reject only when that total exceeds the configured maximum.

Fix this by changing the comparison from >= to >, so exactly max_connections simultaneous connections are allowed and the next one is rejected. This matches the documented meaning of max_connections in fs/smb/server/ksmbd_netlink.h as the "Number of maximum simultaneous connections".

Fixes 0d0d4680db22 ("ksmbd: add max connections parameter")
fs/smb/server/transport_tcp.c +1 -1
index 8d7fe71f525c..13b711ea575d 100644
@@ -281,7 +281,7 @@ static int ksmbd_kthread_fn(void *p)
 
 skip_max_ip_conns_limit:
 		if (server_conf.max_connections &&
-		    atomic_inc_return(&active_num_conn) >= server_conf.max_connections) {
+		    atomic_inc_return(&active_num_conn) > server_conf.max_connections) {
 			pr_info_ratelimited("Limit the maximum number of connections(%u)\n",
 					    atomic_read(&active_num_conn));
 			atomic_dec(&active_num_conn);
maintainer
#1 lore raw

PATCH 1/1 smb: server: fix max_connections off-by-one in tcp accept path

From: DaeMyung Kang <[email protected]>

[ Upstream commit ce23158bfe584bd90d1918f279fdf9de57802012 ]

The global max_connections check in ksmbd's TCP accept path counts the newly accepted connection with atomic_inc_return(), but then rejects the connection when the result is greater than or equal to server_conf.max_connections.

That makes the effective limit one smaller than configured. For example:

- max_connections=1 rejects the first connection
- max_connections=2 allows only one connection

The per-IP limit in the same function uses <= correctly because it counts only pre-existing connections. The global limit instead checks the post-increment total, so it should reject only when that total exceeds the configured maximum.

Fix this by changing the comparison from >= to >, so exactly max_connections simultaneous connections are allowed and the next one is rejected. This matches the documented meaning of max_connections in fs/smb/server/ksmbd_netlink.h as the "Number of maximum simultaneous connections".

Fixes 0d0d4680db22 ("ksmbd: add max connections parameter")
---
 fs/ksmbd/transport_tcp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/ksmbd/transport_tcp.c +1 -1
index 7ef201b7ddb57..e18bb05972aa6 100644
@@ -246,7 +246,7 @@ static int ksmbd_kthread_fn(void *p)
 		}
 
 		if (server_conf.max_connections &&
-		    atomic_inc_return(&active_num_conn) >= server_conf.max_connections) {
+		    atomic_inc_return(&active_num_conn) > server_conf.max_connections) {
 			pr_info_ratelimited("Limit the maximum number of connections(%u)\n",
 					    atomic_read(&active_num_conn));
 			atomic_dec(&active_num_conn);
Signature · 1 line
2.53.0