Subject: CVE-2023-52859: perf: hisi: Fix use-after-free when register pmu fails

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

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

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

perf: hisi: Fix use-after-free when register pmu fails

When we fail to register the uncore pmu, the pmu context may not been
allocated. The error handing will call cpuhp_state_remove_instance()
to call uncore pmu offline callback, which migrate the pmu context.
Since that's liable to lead to some kind of use-after-free.

Use cpuhp_state_remove_instance_nocalls() instead of
cpuhp_state_remove_instance() so that the notifiers don't execute after
the PMU device has been failed to register.

The Linux kernel CVE team has assigned CVE-2023-52859 to this issue.

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

	Issue introduced in 5.13 with commit 3bf30882c3c7 and fixed in 5.15.139 with commit 0e1e88bba286
	Issue introduced in 5.13 with commit 3bf30882c3c7 and fixed in 6.1.63 with commit b660420f449d
	Issue introduced in 5.13 with commit 3bf30882c3c7 and fixed in 6.5.12 with commit 3405f364f82d
	Issue introduced in 5.13 with commit 3bf30882c3c7 and fixed in 6.6.2 with commit 75bab28ffd05
	Issue introduced in 5.13 with commit 3bf30882c3c7 and fixed in 6.7 with commit b805cafc604b

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-2023-52859
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:
	drivers/perf/hisilicon/hisi_uncore_pa_pmu.c
	drivers/perf/hisilicon/hisi_uncore_sllc_pmu.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/0e1e88bba286621b886218363de07b319d6208b2
	https://git.kernel.org/stable/c/b660420f449d094b1fabfa504889810b3a63cdd5
	https://git.kernel.org/stable/c/3405f364f82d4f5407a8b4c519dc15d24b847fda
	https://git.kernel.org/stable/c/75bab28ffd05ec8879c197890b1bd1dfec8d3f63
	https://git.kernel.org/stable/c/b805cafc604bfdb671fae7347a57f51154afa735