Subject: CVE-2024-35962: netfilter: complete validation of user input

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

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

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

netfilter: complete validation of user input

In my recent commit, I missed that do_replace() handlers
use copy_from_sockptr() (which I fixed), followed
by unsafe copy_from_sockptr_offset() calls.

In all functions, we can perform the @optlen validation
before even calling xt_alloc_table_info() with the following
check:

if ((u64)optlen < (u64)tmp.size + sizeof(tmp))
        return -EINVAL;

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

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

	Issue introduced in 5.10.215 with commit 0f038242b77d and fixed in 5.10.216 with commit cf4bc359b761
	Issue introduced in 5.15.154 with commit 440e948cf0ef and fixed in 5.15.156 with commit 97dab36e57c6
	Issue introduced in 6.1.85 with commit 18aae2cb87e5 and fixed in 6.1.87 with commit c760089aa982
	Issue introduced in 6.6.26 with commit 81d51b9b7c95 and fixed in 6.6.28 with commit 89242d9584c3
	Issue introduced in 6.8.5 with commit 58f2bfb789e6 and fixed in 6.8.7 with commit 562b7245131f

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-35962
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/ipv4/netfilter/arp_tables.c
	net/ipv4/netfilter/ip_tables.c
	net/ipv6/netfilter/ip6_tables.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/cf4bc359b76144a3dd55d7c09464ef4c5f2b2b05
	https://git.kernel.org/stable/c/97dab36e57c64106e1c8ebd66cbf0d2d1e52d6b7
	https://git.kernel.org/stable/c/c760089aa98289b4b88a7ff5a62dd92845adf223
	https://git.kernel.org/stable/c/89242d9584c342cb83311b598d9e6b82572eadf8
	https://git.kernel.org/stable/c/562b7245131f6e9f1d280c8b5a8750f03edfc05c
	https://git.kernel.org/stable/c/65acf6e0501ac8880a4f73980d01b5d27648b956