From: Dmitriy Okunev <dokunevdmitriy@gmail.com>
To: Namjae Jeon <linkinjeon@kernel.org>
Cc: lvc-project@linuxtesting.org,
Sergey Senozhatsky <senozhatsky@chromium.org>,
Tom Talpey <tom@talpey.com>,
ChenXiaoSong <chenxiaosong@chenxiaosong.com>,
Steve French <stfrench@microsoft.com>, Ze Tan <tanze@kylinos.cn>,
linux-kernel@vger.kernel.org, linux-cifs@vger.kernel.org
Subject: [PATCH 3/3] ksmbd: do not release session id 0 on init failure
Date: Tue, 20 Oct 2026 17:35:53 +0300 [thread overview]
Message-ID: <20261020143553.105014-3-dokunevdmitriy@gmail.com> (raw)
In-Reply-To: <20261020143553.105014-1-dokunevdmitriy@gmail.com>
When __session_create() fails before __init_smb2_session() assigns an
id, sess->id remains 0 because the session was allocated with kzalloc.
ksmbd_session_destroy() then calls ksmbd_release_id(&session_ida,
sess->id), and since ida_alloc_min() has not yet been called,
ida_free(ida, 0) triggers:
ida_free called for id=0 which is not allocated.
WARNING: lib/idr.c:594 at ida_free+0x18c/0x250
...
ksmbd_release_id+0xd/0x10
ksmbd_session_destroy+0x2d5/0x380
ksmbd_smb2_session_create+0x131/0x160
...
Add a check for sess->id > 0 before the release,
since ids are allocated starting from 1
(ida_alloc_min(ida,1,...)).
Found by Linux Verification Center (linuxtesting.org).
Fixes: e2f34481b24d ("cifsd: add server-side procedures for SMB3")
Signed-off-by: Dmitriy Okunev <dokunevdmitriy@gmail.com>
---
fs/smb/server/mgmt/user_session.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/fs/smb/server/mgmt/user_session.c b/fs/smb/server/mgmt/user_session.c
index 386c8629e134..d46dc7b2c562 100644
--- a/fs/smb/server/mgmt/user_session.c
+++ b/fs/smb/server/mgmt/user_session.c
@@ -409,7 +409,8 @@ void ksmbd_session_destroy(struct ksmbd_session *sess)
ksmbd_session_rpc_clear_list(sess);
free_channel_list(sess);
kfree_sensitive(sess->Preauth_HashValue);
- ksmbd_release_id(&session_ida, sess->id);
+ if (sess->id > 0)
+ ksmbd_release_id(&session_ida, sess->id);
ida_destroy(&sess->tree_conn_ida);
kfree_sensitive(sess);
}
--
2.53.0
prev parent reply other threads:[~2026-10-20 14:36 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-20 14:35 [PATCH 1/3] ksmbd: fix uninitialized locks in __session_create() error path Dmitriy Okunev
2026-10-20 14:35 ` [PATCH 2/3] ksmbd: fix uninitialized xarrays " Dmitriy Okunev
2026-10-20 14:35 ` Dmitriy Okunev [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261020143553.105014-3-dokunevdmitriy@gmail.com \
--to=dokunevdmitriy@gmail.com \
--cc=chenxiaosong@chenxiaosong.com \
--cc=linkinjeon@kernel.org \
--cc=linux-cifs@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lvc-project@linuxtesting.org \
--cc=senozhatsky@chromium.org \
--cc=stfrench@microsoft.com \
--cc=tanze@kylinos.cn \
--cc=tom@talpey.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.