Subject: CVE-2024-50086: ksmbd: fix user-after-free from session log off

From: Greg Kroah-Hartman <[email-masked]>

Description
===========

In the Linux kernel, the following vulnerability has been resolved:

ksmbd: fix user-after-free from session log off

There is racy issue between smb2 session log off and smb2 session setup.
It will cause user-after-free from session log off.
This add session_lock when setting SMB2_SESSION_EXPIRED and referece
count to session struct not to free session while it is being used.

The Linux kernel CVE team has assigned CVE-2024-50086 to this issue.

Affected and fixed versions
===========================

	Fixed in 6.1.114 with commit a9839c37fd81
	Fixed in 6.6.58 with commit 5511999e9615
	Fixed in 6.11.5 with commit ee371898b53a
	Fixed in 6.12-rc4 with commit 7aa8804c0b67

Please see https://www.kernel.org for a full list of currently supported
kernel versions by the kernel community.

Unaffected versions might change over time as fixes are backported to
older supported kernel versions.  The official CVE entry at
	https://cve.org/CVERecord/?id=CVE-2024-50086
will be updated if fixes are backported, please check that for the most
up to date information about this issue.

Affected files
==============

The file(s) affected by this issue are:
	fs/smb/server/mgmt/user_session.c
	fs/smb/server/mgmt/user_session.h
	fs/smb/server/server.c
	fs/smb/server/smb2pdu.c

Mitigation
==========

The Linux kernel CVE team recommends that you update to the latest
stable kernel version for this, and many other bugfixes.  Individual
changes are never tested alone, but rather are part of a larger kernel
release.  Cherry-picking individual commits is not recommended or
supported by the Linux kernel community at all.  If however, updating to
the latest release is impossible, the individual changes to resolve this
issue can be found at these commits:
	https://git.kernel.org/stable/c/a9839c37fd813b432988f58a9d9dd59253d3eb2c
	https://git.kernel.org/stable/c/5511999e9615e4318e9142d23b29bd1597befc08
	https://git.kernel.org/stable/c/ee371898b53a9b9b51c02d22a8c31bfb86d45f0d
	https://git.kernel.org/stable/c/7aa8804c0b67b3cb263a472d17f2cb50d7f1a930