Subject: CVE-2024-42314: btrfs: fix extent map use-after-free when adding pages to compressed bio

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

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

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

btrfs: fix extent map use-after-free when adding pages to compressed bio

At add_ra_bio_pages() we are accessing the extent map to calculate
'add_size' after we dropped our reference on the extent map, resulting
in a use-after-free. Fix this by computing 'add_size' before dropping our
extent map reference.

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

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

	Issue introduced in 5.16 with commit 6a4049102055 and fixed in 6.1.108 with commit c1cc3326e27b
	Issue introduced in 5.16 with commit 6a4049102055 and fixed in 6.6.44 with commit c205565e0f2f
	Issue introduced in 5.16 with commit 6a4049102055 and fixed in 6.10.3 with commit b7859ff398b6
	Issue introduced in 5.16 with commit 6a4049102055 and fixed in 6.11 with commit 8e7860543a94

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-42314
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/btrfs/compression.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/c1cc3326e27b0bd7a2806b40bc48e49afaf951e7
	https://git.kernel.org/stable/c/c205565e0f2f439f278a4a94ee97b67ef7b56ae8
	https://git.kernel.org/stable/c/b7859ff398b6b656e1689daa860eb34837b4bb89
	https://git.kernel.org/stable/c/8e7860543a94784d744c7ce34b78a2e11beefa5c