Skip to content

Commit 9d58ac0

Browse files
charsyamgregkh
authored andcommitted
ksmbd: destroy tree_conn_ida in ksmbd_session_destroy()
[ Upstream commit c049ee1 ] When per-session tree_conn_ida was converted from a dynamically allocated ksmbd_ida to an embedded struct ida, ksmbd_ida_free() was removed from ksmbd_session_destroy() but no matching ida_destroy() was added. The session is therefore freed with the IDA's backing xarray still intact. The kernel IDA API expects ida_init() and ida_destroy() to be paired over an object's lifetime, so add the missing cleanup before the enclosing session is freed. Also move ida_init() to right after the session is allocated so that it is always paired with the destroy call even on the early error paths of __session_create() (ksmbd_init_file_table() or __init_smb2_session() failures), both of which jump to the error label and invoke ksmbd_session_destroy() on a partially initialised session. No leak has been observed in testing; this is a pairing fix to match the IDA lifetime rules, not a response to a reproduced regression. Fixes: d40012a ("cifsd: declare ida statically") 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>
1 parent dd60f26 commit 9d58ac0

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

fs/smb/server/mgmt/user_session.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ void ksmbd_session_destroy(struct ksmbd_session *sess)
171171
free_channel_list(sess);
172172
kfree(sess->Preauth_HashValue);
173173
ksmbd_release_id(&session_ida, sess->id);
174+
ida_destroy(&sess->tree_conn_ida);
174175
kfree(sess);
175176
}
176177

@@ -445,6 +446,8 @@ static struct ksmbd_session *__session_create(int protocol)
445446
if (!sess)
446447
return NULL;
447448

449+
ida_init(&sess->tree_conn_ida);
450+
448451
if (ksmbd_init_file_table(&sess->file_table))
449452
goto error;
450453

@@ -464,8 +467,6 @@ static struct ksmbd_session *__session_create(int protocol)
464467
if (ret)
465468
goto error;
466469

467-
ida_init(&sess->tree_conn_ida);
468-
469470
down_write(&sessions_table_lock);
470471
hash_add(sessions_table, &sess->hlist, sess->id);
471472
up_write(&sessions_table_lock);

0 commit comments

Comments
 (0)