Subject: CVE-2024-50036: net: do not delay dst_entries_add() in dst_release()

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

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

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

net: do not delay dst_entries_add() in dst_release()

dst_entries_add() uses per-cpu data that might be freed at netns
dismantle from ip6_route_net_exit() calling dst_entries_destroy()

Before ip6_route_net_exit() can be called, we release all
the dsts associated with this netns, via calls to dst_release(),
which waits an rcu grace period before calling dst_destroy()

dst_entries_add() use in dst_destroy() is racy, because
dst_entries_destroy() could have been called already.

Decrementing the number of dsts must happen sooner.

Notes:

1) in CONFIG_XFRM case, dst_destroy() can call
   dst_release_immediate(child), this might also cause UAF
   if the child does not have DST_NOCOUNT set.
   IPSEC maintainers might take a look and see how to address this.

2) There is also discussion about removing this count of dst,
   which might happen in future kernels.

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

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

	Issue introduced in 3.16 with commit f88649721268 and fixed in 6.6.57 with commit eae7435b48ff
	Issue introduced in 3.16 with commit f88649721268 and fixed in 6.11.4 with commit 3c7c918ec0aa
	Issue introduced in 3.16 with commit f88649721268 and fixed in 6.12-rc3 with commit ac888d58869b
	Issue introduced in 3.10.50 with commit 86e48c03d774
	Issue introduced in 3.12.26 with commit 591b1e1bb401
	Issue introduced in 3.14.14 with commit df90819dafcd
	Issue introduced in 3.15.7 with commit 9a4fe697023d

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-50036
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/core/dst.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/eae7435b48ffc8e9be0ff9cfeae40af479a609dd
	https://git.kernel.org/stable/c/3c7c918ec0aa3555372c5a57f18780b7a96c5cfc
	https://git.kernel.org/stable/c/ac888d58869bb99753e7652be19a151df9ecb35d