Linux Power Management development
 help / color / mirror / Atom feed
From: Henry Martin <bsdhenrymartin@gmail.com>
To: sudeep.holla@arm.com, cristian.marussi@arm.com,
	rafael@kernel.org, viresh.kumar@linaro.org
Cc: arm-scmi@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
	linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org,
	Henry Martin <bsdhenrymartin@gmail.com>
Subject: [PATCH v2 2/2] cpufreq: scpi: Fix null-ptr-deref in scpi_cpufreq_get_rate()
Date: Tue,  8 Apr 2025 23:03:54 +0800	[thread overview]
Message-ID: <20250408150354.104532-3-bsdhenrymartin@gmail.com> (raw)
In-Reply-To: <20250408150354.104532-1-bsdhenrymartin@gmail.com>

cpufreq_cpu_get_raw() can return NULL when the target CPU is not present
in the policy->cpus mask. scpi_cpufreq_get_rate() does not check for
this case, which results in a NULL pointer dereference.

Fixes: 343a8d17fa8d ("cpufreq: scpi: remove arm_big_little dependency")
Signed-off-by: Henry Martin <bsdhenrymartin@gmail.com>
---
V1 -> V2: Use `if (unlikely(!policy))` instead of `if (!policy)`

 drivers/cpufreq/scpi-cpufreq.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/drivers/cpufreq/scpi-cpufreq.c b/drivers/cpufreq/scpi-cpufreq.c
index 17cda84f00df..dcbb0ae7dd47 100644
--- a/drivers/cpufreq/scpi-cpufreq.c
+++ b/drivers/cpufreq/scpi-cpufreq.c
@@ -29,9 +29,16 @@ 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);
-	struct scpi_data *priv = policy->driver_data;
-	unsigned long rate = clk_get_rate(priv->clk);
+	struct cpufreq_policy *policy;
+	struct scpi_data *priv;
+	unsigned long rate;
+
+	policy = cpufreq_cpu_get_raw(cpu);
+	if (unlikely(!policy))
+		return 0;
+
+	priv = policy->driver_data;
+	rate = clk_get_rate(priv->clk);
 
 	return rate / 1000;
 }
-- 
2.34.1


  parent reply	other threads:[~2025-04-08 15:04 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-08 15:03 [PATCH v2 0/2] cpufreq: scmi/scpi: Fix NULL pointer dereference in get_rate() Henry Martin
2025-04-08 15:03 ` [PATCH v2 1/2] cpufreq: scmi: Fix null-ptr-deref in scmi_cpufreq_get_rate() Henry Martin
2025-04-08 15:03 ` Henry Martin [this message]
2025-04-08 19:23 ` [PATCH v2 0/2] cpufreq: scmi/scpi: Fix NULL pointer dereference in get_rate() Markus Elfring
2025-04-09 11:20   ` Sudeep Holla
2025-04-09 11:48     ` Markus Elfring
2025-04-09 12:01       ` Cristian Marussi
2025-04-09 12:25         ` [v2 " Markus Elfring
2025-04-09 13:21           ` Sudeep Holla
2025-04-09 14:24             ` Markus Elfring
2025-04-09 11:30 ` [PATCH v2 " Sudeep Holla
2025-04-09 12:40   ` henry martin
2025-04-10  4:40 ` Viresh Kumar
  -- strict thread matches above, loose matches on Subject: below --
2025-04-09 12:45 [PATCH v2 2/2] cpufreq: scpi: Fix null-ptr-deref in scpi_cpufreq_get_rate() Henry Martin
2025-04-09 12:52 ` henry martin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250408150354.104532-3-bsdhenrymartin@gmail.com \
    --to=bsdhenrymartin@gmail.com \
    --cc=arm-scmi@vger.kernel.org \
    --cc=cristian.marussi@arm.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=rafael@kernel.org \
    --cc=sudeep.holla@arm.com \
    --cc=viresh.kumar@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox