linux-pm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] cpufreq: scpi: Prevent null pointer dereference in scpi_cpufreq_get_rate()
@ 2024-12-30  9:31 Charles Han
  2025-01-02  5:00 ` Viresh Kumar
  2025-01-02  9:48 ` Sudeep Holla
  0 siblings, 2 replies; 3+ messages in thread
From: Charles Han @ 2024-12-30  9:31 UTC (permalink / raw)
  To: sudeep.holla, cristian.marussi, rafael, viresh.kumar
  Cc: arm-scmi, linux-arm-kernel, linux-pm, linux-kernel, Charles Han

cpufreq_cpu_get_raw() may return NULL if the cpu is not in
policy->cpus cpu mask and it will cause null pointer dereference.
Prevent null pointer dereference in scpi_cpufreq_get_rate().

Fixes: 343a8d17fa8d ("cpufreq: scpi: remove arm_big_little dependency")
Signed-off-by: Charles Han <hanchunchao@inspur.com>
---
 drivers/cpufreq/scpi-cpufreq.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/cpufreq/scpi-cpufreq.c b/drivers/cpufreq/scpi-cpufreq.c
index cd89c1b9832c..c888ed3a0de9 100644
--- a/drivers/cpufreq/scpi-cpufreq.c
+++ b/drivers/cpufreq/scpi-cpufreq.c
@@ -30,6 +30,9 @@ static struct scpi_ops *scpi_ops;
 static unsigned int scpi_cpufreq_get_rate(unsigned int cpu)
 {
 	struct cpufreq_policy *policy = cpufreq_cpu_get_raw(cpu);
+	if (unlikely(!policy))
+		return 0;
+
 	struct scpi_data *priv = policy->driver_data;
 	unsigned long rate = clk_get_rate(priv->clk);
 
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] cpufreq: scpi: Prevent null pointer dereference in scpi_cpufreq_get_rate()
  2024-12-30  9:31 [PATCH] cpufreq: scpi: Prevent null pointer dereference in scpi_cpufreq_get_rate() Charles Han
@ 2025-01-02  5:00 ` Viresh Kumar
  2025-01-02  9:48 ` Sudeep Holla
  1 sibling, 0 replies; 3+ messages in thread
From: Viresh Kumar @ 2025-01-02  5:00 UTC (permalink / raw)
  To: Charles Han
  Cc: sudeep.holla, cristian.marussi, rafael, arm-scmi,
	linux-arm-kernel, linux-pm, linux-kernel

On 30-12-24, 17:31, Charles Han wrote:
> cpufreq_cpu_get_raw() may return NULL if the cpu is not in
> policy->cpus cpu mask and it will cause null pointer dereference.
> Prevent null pointer dereference in scpi_cpufreq_get_rate().
> 
> Fixes: 343a8d17fa8d ("cpufreq: scpi: remove arm_big_little dependency")
> Signed-off-by: Charles Han <hanchunchao@inspur.com>
> ---
>  drivers/cpufreq/scpi-cpufreq.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/drivers/cpufreq/scpi-cpufreq.c b/drivers/cpufreq/scpi-cpufreq.c
> index cd89c1b9832c..c888ed3a0de9 100644
> --- a/drivers/cpufreq/scpi-cpufreq.c
> +++ b/drivers/cpufreq/scpi-cpufreq.c
> @@ -30,6 +30,9 @@ static struct scpi_ops *scpi_ops;
>  static unsigned int scpi_cpufreq_get_rate(unsigned int cpu)
>  {
>  	struct cpufreq_policy *policy = cpufreq_cpu_get_raw(cpu);
> +	if (unlikely(!policy))
> +		return 0;
> +
>  	struct scpi_data *priv = policy->driver_data;
>  	unsigned long rate = clk_get_rate(priv->clk);

The check needs to be made after all the variable definitions.

-- 
viresh

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] cpufreq: scpi: Prevent null pointer dereference in scpi_cpufreq_get_rate()
  2024-12-30  9:31 [PATCH] cpufreq: scpi: Prevent null pointer dereference in scpi_cpufreq_get_rate() Charles Han
  2025-01-02  5:00 ` Viresh Kumar
@ 2025-01-02  9:48 ` Sudeep Holla
  1 sibling, 0 replies; 3+ messages in thread
From: Sudeep Holla @ 2025-01-02  9:48 UTC (permalink / raw)
  To: Charles Han
  Cc: cristian.marussi, rafael, Sudeep Holla, viresh.kumar, arm-scmi,
	linux-arm-kernel, linux-pm, linux-kernel

On Mon, Dec 30, 2024 at 05:31:59PM +0800, Charles Han wrote:
> cpufreq_cpu_get_raw() may return NULL if the cpu is not in
> policy->cpus cpu mask and it will cause null pointer dereference.
> Prevent null pointer dereference in scpi_cpufreq_get_rate().
>

Can you please fix such occurrences in other places too ?
I see it in apple-soc-cpufreq.c and scmi-cpufreq.c as well.

> Fixes: 343a8d17fa8d ("cpufreq: scpi: remove arm_big_little dependency")
> Signed-off-by: Charles Han <hanchunchao@inspur.com>
> ---
>  drivers/cpufreq/scpi-cpufreq.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/drivers/cpufreq/scpi-cpufreq.c b/drivers/cpufreq/scpi-cpufreq.c
> index cd89c1b9832c..c888ed3a0de9 100644
> --- a/drivers/cpufreq/scpi-cpufreq.c
> +++ b/drivers/cpufreq/scpi-cpufreq.c
> @@ -30,6 +30,9 @@ static struct scpi_ops *scpi_ops;
>  static unsigned int scpi_cpufreq_get_rate(unsigned int cpu)
>  {
>  	struct cpufreq_policy *policy = cpufreq_cpu_get_raw(cpu);
> +	if (unlikely(!policy))
> +		return 0;
> +
>  	struct scpi_data *priv = policy->driver_data;
>  	unsigned long rate = clk_get_rate(priv->clk);
>  

-- 
Regards,
Sudeep

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-01-02  9:48 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-12-30  9:31 [PATCH] cpufreq: scpi: Prevent null pointer dereference in scpi_cpufreq_get_rate() Charles Han
2025-01-02  5:00 ` Viresh Kumar
2025-01-02  9:48 ` Sudeep Holla

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).