Subject: CVE-2024-27064: netfilter: nf_tables: Fix a memory leak in nf_tables_updchain

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

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

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

netfilter: nf_tables: Fix a memory leak in nf_tables_updchain

If nft_netdev_register_hooks() fails, the memory associated with
nft_stats is not freed, causing a memory leak.

This patch fixes it by moving nft_stats_alloc() down after
nft_netdev_register_hooks() succeeds.

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

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

	Issue introduced in 6.4 with commit b9703ed44ffb and fixed in 6.6.23 with commit 79846fdcc548
	Issue introduced in 6.4 with commit b9703ed44ffb and fixed in 6.7.11 with commit 4e4623a4f6e1
	Issue introduced in 6.4 with commit b9703ed44ffb and fixed in 6.8.2 with commit e77a6b53a3a5
	Issue introduced in 6.4 with commit b9703ed44ffb and fixed in 6.9 with commit 7eaf837a4eb5
	Issue introduced in 6.3.3 with commit d131ce7a319d

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-27064
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:
	net/netfilter/nf_tables_api.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/79846fdcc548d617b0b321addc6a3821d3b75b20
	https://git.kernel.org/stable/c/4e4623a4f6e133e671f65f9ac493bddaaf63e250
	https://git.kernel.org/stable/c/e77a6b53a3a547b6dedfc40c37cee4f310701090
	https://git.kernel.org/stable/c/7eaf837a4eb5f74561e2486972e7f5184b613f6e