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 1/2] cpufreq: scmi: Fix null-ptr-deref in scmi_cpufreq_get_rate()
Date: Tue, 8 Apr 2025 23:03:53 +0800 [thread overview]
Message-ID: <20250408150354.104532-2-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. scmi_cpufreq_get_rate() does not check for
this case, which results in a NULL pointer dereference.
Add NULL check after cpufreq_cpu_get_raw() to prevent this issue.
Fixes: 99d6bdf33877 ("cpufreq: add support for CPU DVFS based on SCMI message protocol")
Signed-off-by: Henry Martin <bsdhenrymartin@gmail.com>
---
V1 -> V2: Use `if (unlikely(!policy))` instead of `if (!policy)`
drivers/cpufreq/scmi-cpufreq.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/drivers/cpufreq/scmi-cpufreq.c b/drivers/cpufreq/scmi-cpufreq.c
index c310aeebc8f3..944e899eb1be 100644
--- a/drivers/cpufreq/scmi-cpufreq.c
+++ b/drivers/cpufreq/scmi-cpufreq.c
@@ -37,11 +37,17 @@ static struct cpufreq_driver scmi_cpufreq_driver;
static unsigned int scmi_cpufreq_get_rate(unsigned int cpu)
{
- struct cpufreq_policy *policy = cpufreq_cpu_get_raw(cpu);
- struct scmi_data *priv = policy->driver_data;
+ struct cpufreq_policy *policy;
+ struct scmi_data *priv;
unsigned long rate;
int ret;
+ policy = cpufreq_cpu_get_raw(cpu);
+ if (unlikely(!policy))
+ return 0;
+
+ priv = policy->driver_data;
+
ret = perf_ops->freq_get(ph, priv->domain_id, &rate, false);
if (ret)
return 0;
--
2.34.1
next prev parent reply other threads:[~2025-04-08 15:04 UTC|newest]
Thread overview: 13+ 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 ` Henry Martin [this message]
2025-04-08 15:03 ` [PATCH v2 2/2] cpufreq: scpi: Fix null-ptr-deref in scpi_cpufreq_get_rate() Henry Martin
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
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-2-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