perf: hisi: Fix use-after-free when register pmu fails
Subsystems (2)
PATCH 1/1 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.
--- 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(-)
drivers/perf/hisilicon/hisi_uncore_pa_pmu.c +2 -2
@@ -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; }
drivers/perf/hisilicon/hisi_uncore_sllc_pmu.c +2 -2
@@ -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; }
Signature · 1 line
2.33.0
Quoted 10 lines · Junhao He
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 ofcpuhp_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,
Signature · 5 lines
Will https://fixes.arm64.dev https://next.arm64.dev https://will.arm64.dev