]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
smb: server: fix max_connections off-by-one in tcp accept path
authorDaeMyung Kang <charsyam@gmail.com>
Thu, 16 Apr 2026 21:17:35 +0000 (06:17 +0900)
committerSteve French <stfrench@microsoft.com>
Sat, 18 Apr 2026 17:19:59 +0000 (12:19 -0500)
commitce23158bfe584bd90d1918f279fdf9de57802012
tree9cc373cb1f14299a2678dc77ba52862402e85069
parentd07b26f39246a82399661936dd0c853983cfade7
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")
Cc: stable@vger.kernel.org
Signed-off-by: DaeMyung Kang <charsyam@gmail.com>
Acked-by: Namjae Jeon <linkinjeon@kernel.org>
Signed-off-by: Steve French <stfrench@microsoft.com>
fs/smb/server/transport_tcp.c