cpufreq: scmi: Fix null-ptr-deref in scmi_cpufreq_get_rate()
Subsystems (2)
PATCH 1/1 cpufreq: scmi: Fix null-ptr-deref in scmi_cpufreq_get_rate()
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.
--- drivers/cpufreq/scmi-cpufreq.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/cpufreq/scmi-cpufreq.c +8 -2
@@ -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 (!policy) +return 0 ; + + priv = policy->driver_data; + ret = perf_ops->freq_get (ph, priv->domain_id, &rate, false);if (ret)return 0 ;
Signature · 1 line
2.34.1
…
Quoted 1 line
Add NULL check after
cpufreq_cpu_get_raw()to prevent this issue.
Can any other summary phrase variant become more desirable accordingly?
Regards,
Markus
Quoted 19 lines · Henry Martin
cpufreq_cpu_get_raw()can return NULL when the target CPU is not present in thepolicy->cpusmask.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 <[email protected]>--- drivers/cpufreq/scmi-cpufreq.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)drivers/cpufreq/scmi-cpufreq.c +0
-0@@ -37,11 +37,17 @@ static struct cpufreq_driver scmi_cpufreq_driver;static unsigned int scmi_cpufreq_get_rate (unsigned int cpu)
drivers/cpufreq/scmi-cpufreq.c static struct cpufreq_driver scmi_cpufreq_driver; · line 46
Quoted 10 lines
drivers/cpufreq/scmi-cpufreq.c +4
-2{ -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 (!policy)
How about if (unlikely(!policy)) instead ?
With that you can add :
Both comment and review applies for scpi-cpufreq.c
Signature · 2 lines
Regards, Sudeep
Viresh Kumar
maintainerQuoted 28 lines · Sudeep Holla
Quoted 27 lines · Henry Martin
cpufreq_cpu_get_raw()can return NULL when the target CPU is not present in thepolicy->cpusmask.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 <[email protected]>--- drivers/cpufreq/scmi-cpufreq.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)drivers/cpufreq/scmi-cpufreq.c +2
-2@@ -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;
Quoted 4 lines
drivers/cpufreq/scmi-cpufreq.c static struct cpufreq_driver scmi_cpufreq_driver; · line 46
Quoted 2 lines
drivers/cpufreq/scmi-cpufreq.c +2
-0+ policy =cpufreq_cpu_get_raw (cpu); +if (!policy)How about
if (unlikely(!policy))instead ?
Henry, this change applies to all the patches you have sent. Also please send them as a single series, as they are related changes.
Signature · 1 line
viresh
Quoted 1 line
How about
if (unlikely(!policy))instead ?
Agreed, unlikely() makes sense here since the NULL check is for an exceptional case.
I'll update all relevant patches accordingly.
Quoted 2 lines
Henry, this change applies to all the patches you have sent. Also please send them as a single series, as they are related changes.
Noted. I’ll consolidate the patches into a single series with a proper cover letter and
resend them shortly.
Quoted 40 lines · Viresh Kumar <[email protected]> 于2025年4月8日周二 13:55写道:
Quoted 28 lines · Sudeep Holla
Quoted 27 lines · Henry Martin
cpufreq_cpu_get_raw()can return NULL when the target CPU is not present in thepolicy->cpusmask.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 <[email protected]>--- drivers/cpufreq/scmi-cpufreq.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)drivers/cpufreq/scmi-cpufreq.c +2
-2@@ -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;Quoted 4 lines
drivers/cpufreq/scmi-cpufreq.c static struct cpufreq_driver scmi_cpufreq_driver; · line 46
Quoted 2 lines
drivers/cpufreq/scmi-cpufreq.c +2
-0+ policy =cpufreq_cpu_get_raw (cpu); +if (!policy)How about
if (unlikely(!policy))instead ?Henry, this change applies to all the patches you have sent. Also please send them as a single series, as they are related changes.
--
viresh