Subject: CVE-2024-50038: netfilter: xtables: avoid NFPROTO_UNSPEC where needed

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

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

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

netfilter: xtables: avoid NFPROTO_UNSPEC where needed

syzbot managed to call xt_cluster match via ebtables:

 WARNING: CPU: 0 PID: 11 at net/netfilter/xt_cluster.c:72 xt_cluster_mt+0x196/0x780
 [..]
 ebt_do_table+0x174b/0x2a40

Module registers to NFPROTO_UNSPEC, but it assumes ipv4/ipv6 packet
processing.  As this is only useful to restrict locally terminating
TCP/UDP traffic, register this for ipv4 and ipv6 family only.

Pablo points out that this is a general issue, direct users of the
set/getsockopt interface can call into targets/matches that were only
intended for use with ip(6)tables.

Check all UNSPEC matches and targets for similar issues:

- matches and targets are fine except if they assume skb_network_header()
  is valid -- this is only true when called from inet layer: ip(6) stack
  pulls the ip/ipv6 header into linear data area.
- targets that return XT_CONTINUE or other xtables verdicts must be
  restricted too, they are incompatbile with the ebtables traverser, e.g.
  EBT_CONTINUE is a completely different value than XT_CONTINUE.

Most matches/targets are changed to register for NFPROTO_IPV4/IPV6, as
they are provided for use by ip(6)tables.

The MARK target is also used by arptables, so register for NFPROTO_ARP too.

While at it, bail out if connbytes fails to enable the corresponding
conntrack family.

This change passes the selftests in iptables.git.

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

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

	Issue introduced in 2.6.30 with commit 0269ea493734 and fixed in 5.15.168 with commit 85ff9a0f793c
	Issue introduced in 2.6.30 with commit 0269ea493734 and fixed in 6.1.113 with commit 8f482bb7e27b
	Issue introduced in 2.6.30 with commit 0269ea493734 and fixed in 6.6.57 with commit 997f67d813ce
	Issue introduced in 2.6.30 with commit 0269ea493734 and fixed in 6.11.4 with commit 4cdc55ec6222
	Issue introduced in 2.6.30 with commit 0269ea493734 and fixed in 6.12-rc3 with commit 0bfcb7b71e73

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-50038
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/xt_CHECKSUM.c
	net/netfilter/xt_CLASSIFY.c
	net/netfilter/xt_CONNSECMARK.c
	net/netfilter/xt_CT.c
	net/netfilter/xt_IDLETIMER.c
	net/netfilter/xt_LED.c
	net/netfilter/xt_NFLOG.c
	net/netfilter/xt_RATEEST.c
	net/netfilter/xt_SECMARK.c
	net/netfilter/xt_TRACE.c
	net/netfilter/xt_addrtype.c
	net/netfilter/xt_cluster.c
	net/netfilter/xt_connbytes.c
	net/netfilter/xt_connlimit.c
	net/netfilter/xt_connmark.c
	net/netfilter/xt_mark.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/85ff9a0f793ca52c527e75cd40a69c948627ebde
	https://git.kernel.org/stable/c/8f482bb7e27b37f1f734bb9a8eeb28b23d59d189
	https://git.kernel.org/stable/c/997f67d813ce0cf5eb3cdb8f124da68141e91b6c
	https://git.kernel.org/stable/c/4cdc55ec6222bb195995cc58f7cb46e4d8907056
	https://git.kernel.org/stable/c/0bfcb7b71e735560077a42847f69597ec7dcc326