Subject: CVE-2024-27058: tmpfs: fix race on handling dquot rbtree

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

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

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

tmpfs: fix race on handling dquot rbtree

A syzkaller reproducer found a race while attempting to remove dquot
information from the rb tree.

Fetching the rb_tree root node must also be protected by the
dqopt->dqio_sem, otherwise, giving the right timing, shmem_release_dquot()
will trigger a warning because it couldn't find a node in the tree, when
the real reason was the root node changing before the search starts:

Thread 1				Thread 2
- shmem_release_dquot()			- shmem_{acquire,release}_dquot()

- fetch ROOT				- Fetch ROOT

					- acquire dqio_sem
- wait dqio_sem

					- do something, triger a tree rebalance
					- release dqio_sem

- acquire dqio_sem
- start searching for the node, but
  from the wrong location, missing
  the node, and triggering a warning.

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

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

	Issue introduced in 6.6 with commit eafc474e2029 and fixed in 6.6.24 with commit c7077f43f30d
	Issue introduced in 6.6 with commit eafc474e2029 and fixed in 6.7.12 with commit 617d55b90e73
	Issue introduced in 6.6 with commit eafc474e2029 and fixed in 6.8.3 with commit f82f184874d2
	Issue introduced in 6.6 with commit eafc474e2029 and fixed in 6.9 with commit 0a69b6b3a026

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-27058
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:
	mm/shmem_quota.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/c7077f43f30d817d10a9f8245e51576ac114b2f0
	https://git.kernel.org/stable/c/617d55b90e73c7b4aa2733ca6cc3f9b72d1124bb
	https://git.kernel.org/stable/c/f82f184874d2761ebaa60dccf577921a0dbb3810
	https://git.kernel.org/stable/c/0a69b6b3a026543bc215ccc866d0aea5579e6ce2