Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

ksmbd: destroy tree_conn_ida in ksmbd_session_destroy()

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: d40012a83f87 ("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>

authored by

DaeMyung Kang and committed by
Steve French
c049ee14 cc92b479

+3 -2
+3 -2
fs/smb/server/mgmt/user_session.c
··· 391 391 free_channel_list(sess); 392 392 kfree(sess->Preauth_HashValue); 393 393 ksmbd_release_id(&session_ida, sess->id); 394 + ida_destroy(&sess->tree_conn_ida); 394 395 kfree(sess); 395 396 } 396 397 ··· 666 665 if (!sess) 667 666 return NULL; 668 667 668 + ida_init(&sess->tree_conn_ida); 669 + 669 670 if (ksmbd_init_file_table(&sess->file_table)) 670 671 goto error; 671 672 ··· 686 683 ret = __init_smb2_session(sess); 687 684 if (ret) 688 685 goto error; 689 - 690 - ida_init(&sess->tree_conn_ida); 691 686 692 687 down_write(&sessions_table_lock); 693 688 hash_add(sessions_table, &sess->hlist, sess->id);