]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
ksmbd: fix use-after-free in ksmbd_sessions_deregister()
authorNamjae Jeon <linkinjeon@kernel.org>
Sat, 22 Mar 2025 00:20:19 +0000 (09:20 +0900)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 10 Apr 2025 12:37:43 +0000 (14:37 +0200)
commit 15a9605f8d69dc85005b1a00c31a050b8625e1aa upstream.

In multichannel mode, UAF issue can occur in session_deregister
when the second channel sets up a session through the connection of
the first channel. session that is freed through the global session
table can be accessed again through ->sessions of connection.

Cc: stable@vger.kernel.org
Reported-by: Norbert Szetei <norbert@doyensec.com>
Tested-by: Norbert Szetei <norbert@doyensec.com>
Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
Signed-off-by: Steve French <stfrench@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
fs/smb/server/mgmt/user_session.c

index 1ea219cbb4a1806fbbf23861c33044d58d36ab19..dc59ead4f6c3d6f7a56850ad15937e61b086af03 100644 (file)
@@ -229,6 +229,9 @@ void ksmbd_sessions_deregister(struct ksmbd_conn *conn)
                        if (!ksmbd_chann_del(conn, sess) &&
                            xa_empty(&sess->ksmbd_chann_list)) {
                                hash_del(&sess->hlist);
+                               down_write(&conn->session_lock);
+                               xa_erase(&conn->sessions, sess->id);
+                               up_write(&conn->session_lock);
                                ksmbd_session_destroy(sess);
                        }
                }