Skip to content

Commit bf96052

Browse files
charsyamgregkh
authored andcommitted
ksmbd: reset rcount per connection in ksmbd_conn_wait_idle_sess_id()
[ Upstream commit def036e ] rcount is intended to be connection-specific: 2 for curr_conn, 1 for every other connection sharing the same session. However, it is initialised only once before the hash iteration and is never reset. After the loop visits curr_conn, later sibling connections are also checked against rcount == 2, so a sibling with req_running == 1 is incorrectly treated as idle. This makes the outcome depend on the hash iteration order: whether a given sibling is checked against the loose (< 2) or the strict (< 1) threshold is decided by whether it happens to be visited before or after curr_conn. The function's contract is "wait until every connection sharing this session is idle" so that destroy_previous_session() can safely tear the session down. The latched rcount violates that contract and reopens the teardown race window the wait logic was meant to close: destroy_previous_session() may proceed before sibling channels have actually quiesced, overlapping session teardown with in-flight work on those connections. Recompute rcount inside the loop so each connection is compared against its own threshold regardless of iteration order. This is a code-inspection fix for an iteration-order-dependent logic error; a targeted reproducer would require SMB3 multichannel with in-flight work on a sibling channel landing after curr_conn in hash order, which is not something that can be triggered reliably. Fixes: 76e98a1 ("ksmbd: fix race condition between destroy_previous_session() and smb2 operations()") 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> Signed-off-by: Sasha Levin <sashal@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent e1c24ce commit bf96052

1 file changed

Lines changed: 2 additions & 3 deletions

File tree

fs/smb/server/connection.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ int ksmbd_conn_wait_idle_sess_id(struct ksmbd_conn *curr_conn, u64 sess_id)
180180
{
181181
struct ksmbd_conn *conn;
182182
int rc, retry_count = 0, max_timeout = 120;
183-
int rcount = 1, bkt;
183+
int rcount, bkt;
184184

185185
retry_idle:
186186
if (retry_count >= max_timeout)
@@ -189,8 +189,7 @@ int ksmbd_conn_wait_idle_sess_id(struct ksmbd_conn *curr_conn, u64 sess_id)
189189
down_read(&conn_list_lock);
190190
hash_for_each(conn_list, bkt, conn, hlist) {
191191
if (conn->binding || xa_load(&conn->sessions, sess_id)) {
192-
if (conn == curr_conn)
193-
rcount = 2;
192+
rcount = (conn == curr_conn) ? 2 : 1;
194193
if (atomic_read(&conn->req_running) >= rcount) {
195194
rc = wait_event_timeout(conn->req_running_q,
196195
atomic_read(&conn->req_running) < rcount,

0 commit comments

Comments
 (0)