[PATCH 0/2] ksmbd: connection accounting and session teardown fixes

From: DaeMyung Kang

Date: Sat Apr 18 2026 - 13:29:04 EST


Two independent correctness fixes in the ksmbd server.

1/2 ksmbd_tcp_new_connection() does not decrement active_num_conn on
the alloc_transport() failure path, so repeated allocation
failures monotonically inflate the counter until max_connections
is reached and new clients are refused indefinitely. This is
the remaining half of the same family of accounting bugs
addressed by 77ffbcac4e56 ("smb: server: fix leak of
active_num_conn in ksmbd_tcp_new_connection()"), which only
closed the kthread_run() failure path. Reproduced under a debug
build that forces alloc_transport() to return NULL for a bounded
number of calls; details in the commit log.

2/2 ksmbd_conn_wait_idle_sess_id() stores its per-connection
threshold (rcount) in cross-iteration state, so whether a given
sibling connection is compared against the loose (< 2) or the
strict (< 1) threshold is decided by hash iteration order
relative to curr_conn. Connections visited after curr_conn can
slip through the idle check while still processing requests
against the same session, reopening the teardown race
destroy_previous_session() was meant to close. This is a
code-inspection fix; the iteration-order dependency makes a
targeted reproducer impractical.

The two patches are independent; the series order is not significant.

DaeMyung Kang (2):
ksmbd: fix active_num_conn leak when alloc_transport() fails
ksmbd: reset rcount per connection in ksmbd_conn_wait_idle_sess_id()

fs/smb/server/connection.c | 5 ++---
fs/smb/server/transport_tcp.c | 2 ++
2 files changed, 4 insertions(+), 3 deletions(-)

--
2.43.0