[PATCH] PM / devfreq: hisi: Fix potential UAF in OPP handling

Pengjie Zhang posted 1 patch 2 weeks, 3 days ago
drivers/devfreq/hisi_uncore_freq.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
[PATCH] PM / devfreq: hisi: Fix potential UAF in OPP handling
Posted by Pengjie Zhang 2 weeks, 3 days ago
Ensure all required data is acquired before calling dev_pm_opp_put(opp)
to maintain correct resource acquisition and release order.

Fixes: 7da2fdaaa1e6 ("PM / devfreq: Add HiSilicon uncore frequency scaling driver")
Signed-off-by: Pengjie Zhang <zhangpengjie2@huawei.com>
---
 drivers/devfreq/hisi_uncore_freq.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/devfreq/hisi_uncore_freq.c b/drivers/devfreq/hisi_uncore_freq.c
index 96d1815059e3..c1ed70fa0a40 100644
--- a/drivers/devfreq/hisi_uncore_freq.c
+++ b/drivers/devfreq/hisi_uncore_freq.c
@@ -265,10 +265,11 @@ static int hisi_uncore_target(struct device *dev, unsigned long *freq,
 		dev_err(dev, "Failed to get opp for freq %lu hz\n", *freq);
 		return PTR_ERR(opp);
 	}
-	dev_pm_opp_put(opp);
 
 	data = (u32)(dev_pm_opp_get_freq(opp) / HZ_PER_MHZ);
 
+	dev_pm_opp_put(opp);
+
 	return hisi_uncore_cmd_send(uncore, HUCF_PCC_CMD_SET_FREQ, &data);
 }
 
-- 
2.33.0
Re: [PATCH] PM / devfreq: hisi: Fix potential UAF in OPP handling
Posted by Jie Zhan 2 weeks, 2 days ago

On 9/15/2025 2:21 PM, Pengjie Zhang wrote:
> Ensure all required data is acquired before calling dev_pm_opp_put(opp)
> to maintain correct resource acquisition and release order.
> 
> Fixes: 7da2fdaaa1e6 ("PM / devfreq: Add HiSilicon uncore frequency scaling driver")
> Signed-off-by: Pengjie Zhang <zhangpengjie2@huawei.com>
> ---
>  drivers/devfreq/hisi_uncore_freq.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
Hi Pengjie,

Yeah dev_pm_opp_put() should be after dev_pm_opp_get_freq().
Thanks for spotting this.

Reviewed-by: Jie Zhan <zhanjie9@hisilicon.com>
> 
> diff --git a/drivers/devfreq/hisi_uncore_freq.c b/drivers/devfreq/hisi_uncore_freq.c
> index 96d1815059e3..c1ed70fa0a40 100644
> --- a/drivers/devfreq/hisi_uncore_freq.c
> +++ b/drivers/devfreq/hisi_uncore_freq.c
> @@ -265,10 +265,11 @@ static int hisi_uncore_target(struct device *dev, unsigned long *freq,
>  		dev_err(dev, "Failed to get opp for freq %lu hz\n", *freq);
>  		return PTR_ERR(opp);
>  	}
> -	dev_pm_opp_put(opp);
>  
>  	data = (u32)(dev_pm_opp_get_freq(opp) / HZ_PER_MHZ);
>  
> +	dev_pm_opp_put(opp);
> +
>  	return hisi_uncore_cmd_send(uncore, HUCF_PCC_CMD_SET_FREQ, &data);
>  }
>