* [PATCH] perf: hisi: Fix use-after-free when register pmu fails
@ 2023-10-24 11:36 Junhao He
2023-10-24 12:51 ` Will Deacon
0 siblings, 1 reply; 2+ messages in thread
From: Junhao He @ 2023-10-24 11:36 UTC (permalink / raw)
To: will, jonathan.cameron, linux-kernel, mark.rutland
Cc: linux-arm-kernel, linuxarm, yangyicong, shenyang39, prime.zeng,
hejunhao3
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.
Fixes: a0ab25cd82ee ("drivers/perf: hisi: Add support for HiSilicon PA PMU driver")
FIxes: 3bf30882c3c7 ("drivers/perf: hisi: Add support for HiSilicon SLLC PMU driver")
Signed-off-by: Junhao He <hejunhao3@huawei.com>
---
drivers/perf/hisilicon/hisi_uncore_pa_pmu.c | 4 ++--
drivers/perf/hisilicon/hisi_uncore_sllc_pmu.c | 4 ++--
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/perf/hisilicon/hisi_uncore_pa_pmu.c b/drivers/perf/hisilicon/hisi_uncore_pa_pmu.c
index d941e746b424..797cf201996a 100644
--- a/drivers/perf/hisilicon/hisi_uncore_pa_pmu.c
+++ b/drivers/perf/hisilicon/hisi_uncore_pa_pmu.c
@@ -505,8 +505,8 @@ static int hisi_pa_pmu_probe(struct platform_device *pdev)
ret = perf_pmu_register(&pa_pmu->pmu, name, -1);
if (ret) {
dev_err(pa_pmu->dev, "PMU register failed, ret = %d\n", ret);
- cpuhp_state_remove_instance(CPUHP_AP_PERF_ARM_HISI_PA_ONLINE,
- &pa_pmu->node);
+ cpuhp_state_remove_instance_nocalls(CPUHP_AP_PERF_ARM_HISI_PA_ONLINE,
+ &pa_pmu->node);
return ret;
}
diff --git a/drivers/perf/hisilicon/hisi_uncore_sllc_pmu.c b/drivers/perf/hisilicon/hisi_uncore_sllc_pmu.c
index 6fe534a665ed..e706ca567676 100644
--- a/drivers/perf/hisilicon/hisi_uncore_sllc_pmu.c
+++ b/drivers/perf/hisilicon/hisi_uncore_sllc_pmu.c
@@ -450,8 +450,8 @@ static int hisi_sllc_pmu_probe(struct platform_device *pdev)
ret = perf_pmu_register(&sllc_pmu->pmu, name, -1);
if (ret) {
dev_err(sllc_pmu->dev, "PMU register failed, ret = %d\n", ret);
- cpuhp_state_remove_instance(CPUHP_AP_PERF_ARM_HISI_SLLC_ONLINE,
- &sllc_pmu->node);
+ cpuhp_state_remove_instance_nocalls(CPUHP_AP_PERF_ARM_HISI_SLLC_ONLINE,
+ &sllc_pmu->node);
return ret;
}
--
2.33.0
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] perf: hisi: Fix use-after-free when register pmu fails
2023-10-24 11:36 [PATCH] perf: hisi: Fix use-after-free when register pmu fails Junhao He
@ 2023-10-24 12:51 ` Will Deacon
0 siblings, 0 replies; 2+ messages in thread
From: Will Deacon @ 2023-10-24 12:51 UTC (permalink / raw)
To: mark.rutland, jonathan.cameron, linux-kernel, Junhao He
Cc: catalin.marinas, kernel-team, Will Deacon, linuxarm,
linux-arm-kernel, prime.zeng, yangyicong, shenyang39
On Tue, 24 Oct 2023 19:36:30 +0800, Junhao He wrote:
> 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.
>
> [...]
Applied to will (for-next/perf), thanks!
[1/1] perf: hisi: Fix use-after-free when register pmu fails
https://git.kernel.org/will/c/b805cafc604b
Cheers,
--
Will
https://fixes.arm64.dev
https://next.arm64.dev
https://will.arm64.dev
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-10-24 12:51 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-24 11:36 [PATCH] perf: hisi: Fix use-after-free when register pmu fails Junhao He
2023-10-24 12:51 ` Will Deacon
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®