Skip to content

Commit b805caf

Browse files
Junhao Hewilldeacon
authored andcommitted
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. Fixes: a0ab25c ("drivers/perf: hisi: Add support for HiSilicon PA PMU driver") FIxes: 3bf3088 ("drivers/perf: hisi: Add support for HiSilicon SLLC PMU driver") Signed-off-by: Junhao He <hejunhao3@huawei.com> Link: https://lore.kernel.org/r/20231024113630.13472-1-hejunhao3@huawei.com Signed-off-by: Will Deacon <will@kernel.org>
1 parent 868f8a7 commit b805caf

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

drivers/perf/hisilicon/hisi_uncore_pa_pmu.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -505,8 +505,8 @@ static int hisi_pa_pmu_probe(struct platform_device *pdev)
505505
ret = perf_pmu_register(&pa_pmu->pmu, name, -1);
506506
if (ret) {
507507
dev_err(pa_pmu->dev, "PMU register failed, ret = %d\n", ret);
508-
cpuhp_state_remove_instance(CPUHP_AP_PERF_ARM_HISI_PA_ONLINE,
509-
&pa_pmu->node);
508+
cpuhp_state_remove_instance_nocalls(CPUHP_AP_PERF_ARM_HISI_PA_ONLINE,
509+
&pa_pmu->node);
510510
return ret;
511511
}
512512

drivers/perf/hisilicon/hisi_uncore_sllc_pmu.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -450,8 +450,8 @@ static int hisi_sllc_pmu_probe(struct platform_device *pdev)
450450
ret = perf_pmu_register(&sllc_pmu->pmu, name, -1);
451451
if (ret) {
452452
dev_err(sllc_pmu->dev, "PMU register failed, ret = %d\n", ret);
453-
cpuhp_state_remove_instance(CPUHP_AP_PERF_ARM_HISI_SLLC_ONLINE,
454-
&sllc_pmu->node);
453+
cpuhp_state_remove_instance_nocalls(CPUHP_AP_PERF_ARM_HISI_SLLC_ONLINE,
454+
&sllc_pmu->node);
455455
return ret;
456456
}
457457

0 commit comments

Comments
 (0)