Subject: CVE-2024-41049: filelock: fix potential use-after-free in posix_lock_inode

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

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

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

filelock: fix potential use-after-free in posix_lock_inode

Light Hsieh reported a KASAN UAF warning in trace_posix_lock_inode().
The request pointer had been changed earlier to point to a lock entry
that was added to the inode's list. However, before the tracepoint could
fire, another task raced in and freed that lock.

Fix this by moving the tracepoint inside the spinlock, which should
ensure that this doesn't happen.

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

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

	Issue introduced in 5.4.257 with commit 117fb80cd1e6 and fixed in 5.4.280 with commit 1cbbb3d9475c
	Issue introduced in 5.10.197 with commit a6f4129378ca and fixed in 5.10.222 with commit 7d4c14f4b511
	Issue introduced in 5.15.133 with commit 766e56faddbe and fixed in 5.15.163 with commit 02a896426075
	Issue introduced in 6.1.55 with commit 34bff6d85001 and fixed in 6.1.100 with commit 5cb36e35bc10
	Issue introduced in 6.6 with commit 74f6f5912693 and fixed in 6.6.41 with commit 432b06b69d1d
	Issue introduced in 6.6 with commit 74f6f5912693 and fixed in 6.9.10 with commit 116599f6a269
	Issue introduced in 6.6 with commit 74f6f5912693 and fixed in 6.10 with commit 1b3ec4f7c03d
	Issue introduced in 6.5.5 with commit e75396988bb9

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-41049
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/locks.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/1cbbb3d9475c403ebedc327490c7c2b991398197
	https://git.kernel.org/stable/c/7d4c14f4b511fd4c0dc788084ae59b4656ace58b
	https://git.kernel.org/stable/c/02a8964260756c70b20393ad4006948510ac9967
	https://git.kernel.org/stable/c/5cb36e35bc10ea334810937990c2b9023dacb1b0
	https://git.kernel.org/stable/c/432b06b69d1d354a171f7499141116536579eb6a
	https://git.kernel.org/stable/c/116599f6a26906cf33f67975c59f0692ecf7e9b2
	https://git.kernel.org/stable/c/1b3ec4f7c03d4b07bad70697d7e2f4088d2cfe92