Subject: CVE-2022-48799: perf: Fix list corruption in perf_cgroup_switch()

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

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

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

perf: Fix list corruption in perf_cgroup_switch()

There's list corruption on cgrp_cpuctx_list. This happens on the
following path:

  perf_cgroup_switch: list_for_each_entry(cgrp_cpuctx_list)
      cpu_ctx_sched_in
         ctx_sched_in
            ctx_pinned_sched_in
              merge_sched_in
                  perf_cgroup_event_disable: remove the event from the list

Use list_for_each_entry_safe() to allow removing an entry during
iteration.

The Linux kernel CVE team has assigned CVE-2022-48799 to this issue.

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

	Issue introduced in 4.11 with commit 058fe1c0440e and fixed in 4.14.267 with commit 5d76ed422340
	Issue introduced in 4.11 with commit 058fe1c0440e and fixed in 4.19.230 with commit 30d9f3cbe47e
	Issue introduced in 4.11 with commit 058fe1c0440e and fixed in 5.4.180 with commit a2ed7b29d067
	Issue introduced in 4.11 with commit 058fe1c0440e and fixed in 5.10.101 with commit f6b5d51976fc
	Issue introduced in 4.11 with commit 058fe1c0440e and fixed in 5.15.24 with commit 7969fe91c983
	Issue introduced in 4.11 with commit 058fe1c0440e and fixed in 5.16.10 with commit 2142bc1469a3
	Issue introduced in 4.11 with commit 058fe1c0440e and fixed in 5.17 with commit 5f4e5ce638e6

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-2022-48799
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:
	kernel/events/core.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/5d76ed4223403f90421782adb2f20a9ecbc93186
	https://git.kernel.org/stable/c/30d9f3cbe47e1018ddc8069ac5b5c9e66fbdf727
	https://git.kernel.org/stable/c/a2ed7b29d0673ba361546e2d87dbbed149456c45
	https://git.kernel.org/stable/c/f6b5d51976fcefef5732da3e3feb3ccff680f7c8
	https://git.kernel.org/stable/c/7969fe91c9830e045901970e9d755b7505881d4a
	https://git.kernel.org/stable/c/2142bc1469a316fddd10012d76428f7265258f81
	https://git.kernel.org/stable/c/5f4e5ce638e6a490b976ade4a40017b40abb2da0