Subject: CVE-2024-50088: btrfs: fix uninitialized pointer free in add_inode_ref()

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

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

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

btrfs: fix uninitialized pointer free in add_inode_ref()

The add_inode_ref() function does not initialize the "name" struct when
it is declared.  If any of the following calls to "read_one_inode()
returns NULL,

	dir = read_one_inode(root, parent_objectid);
	if (!dir) {
		ret = -ENOENT;
		goto out;
	}

	inode = read_one_inode(root, inode_objectid);
	if (!inode) {
		ret = -EIO;
		goto out;
	}

then "name.name" would be freed on "out" before being initialized.

out:
	...
	kfree(name.name);

This issue was reported by Coverity with CID 1526744.

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

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

	Issue introduced in 6.1.57 with commit 1cf474cd474b and fixed in 6.1.114 with commit 12cf028381aa
	Issue introduced in 6.2 with commit e43eec81c516 and fixed in 6.6.58 with commit e11ce03b5874
	Issue introduced in 6.2 with commit e43eec81c516 and fixed in 6.11.5 with commit a941f3d5b146
	Issue introduced in 6.2 with commit e43eec81c516 and fixed in 6.12-rc4 with commit 66691c6e2f18

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-50088
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/tree-log.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/12cf028381aa19bc38465341512c280256e8d82d
	https://git.kernel.org/stable/c/e11ce03b58743bf1e096c48fcaa7e6f08eb75dfa
	https://git.kernel.org/stable/c/a941f3d5b1469c60a7e70e775584f110b47e0d16
	https://git.kernel.org/stable/c/66691c6e2f18d2aa4b22ffb624b9bdc97e9979e4