Skip to contentSkip to conversation

cpufreq: scmi/scpi: Fix NULL pointer dereference in get_rate()

PATCH Applied Henry Martin 5 participants 13 messages Apr 8, 2025 – Apr 10, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v2 cover cpufreq: scmi/scpi: Fix NULL pointer dereference in get_rate()

This series fixes potential NULL pointer dereferences in scmi_cpufreq_get_rate() and scpi_cpufreq_get_rate() when cpufreq_cpu_get_raw() returns NULL.

Henry Martin (2):
cpufreq: scmi: Fix null-ptr-deref in scmi_cpufreq_get_rate()
cpufreq: scpi: Fix null-ptr-deref in scpi_cpufreq_get_rate()

 drivers/cpufreq/scmi-cpufreq.c | 10 ++++++++--
 drivers/cpufreq/scpi-cpufreq.c | 13 ++++++++++---
 2 files changed, 18 insertions(+), 5 deletions(-)
Signature · 1 line
2.34.1
#1 lore raw

PATCH v2 1/2 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.

Fixes 99d6bdf33877 ("cpufreq: add support for CPU DVFS based on SCMI message protocol")

---
V1 -> V2: Use if (unlikely(!policy)) instead of if (!policy)

 drivers/cpufreq/scmi-cpufreq.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/cpufreq/scmi-cpufreq.c +8 -2
index c310aeebc8f3..944e899eb1be 100644
@@ -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;
Signature · 1 line
2.34.1
#2 lore raw

PATCH v2 2/2 cpufreq: scpi: Fix null-ptr-deref in scpi_cpufreq_get_rate()

In reply to Henry Martin

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")

---
V1 -> V2: Use if (unlikely(!policy)) instead of if (!policy)

 drivers/cpufreq/scpi-cpufreq.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)
drivers/cpufreq/scpi-cpufreq.c +10 -3
index 17cda84f00df..dcbb0ae7dd47 100644
@@ -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;
 }
Signature · 1 line
2.34.1
#3 lore raw
In reply to Henry Martin
Quoted 6 lines

This series fixes potential NULL pointer dereferences in scmi_cpufreq_get_rate() and scpi_cpufreq_get_rate() when cpufreq_cpu_get_raw() returns NULL.

Henry Martin (2):
cpufreq: scmi: Fix null-ptr-deref in scmi_cpufreq_get_rate()
cpufreq: scpi: Fix null-ptr-deref in scpi_cpufreq_get_rate()

Can any other summary phrase variants become more desirable accordingly?

Regards,
Markus

#4 lore raw
Quoted 9 lines · Markus Elfring
Quoted 6 lines

This series fixes potential NULL pointer dereferences in scmi_cpufreq_get_rate() and scpi_cpufreq_get_rate() when cpufreq_cpu_get_raw() returns NULL.

Henry Martin (2):
cpufreq: scmi: Fix null-ptr-deref in scmi_cpufreq_get_rate()
cpufreq: scpi: Fix null-ptr-deref in scpi_cpufreq_get_rate()

Can any other summary phrase variants become more desirable accordingly?

This is meaningless, sorry can't parse. Ignoring it as others in the community are doing already.

Signature · 2 lines
Regards,
Sudeep
#5 lore raw
Quoted 4 lines
Quoted 1 line

Can any other summary phrase variants become more desirable accordingly?

This is meaningless, sorry can't parse. Ignoring it as others in the community are doing already.

Do you care if the term “null pointer dereference” would be used in consistent ways?

Regards,
Markus

#6 lore raw
Quoted 1 line · Markus Elfring
Quoted 1 line
Quoted 1 line

Can any other summary phrase variants become more desirable accordingly?

I agree with Sudeep, the above sentence is completely incomprehensible to me

Quoted 5 lines
Quoted 3 lines

This is meaningless, sorry can't parse. Ignoring it as others in the community are doing already.

Do you care if the term “null pointer dereference” would be used in consistent ways?

...this is more comprehensible, but again I cannot grasp what's yor advice specifically on this commit message.

Thanks,
Cristian

#7 lore raw
Quoted 4 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line

Can any other summary phrase variants become more desirable accordingly?

I agree with Sudeep, the above sentence is completely incomprehensible to me

Can any suggestions gain acceptance also for better summary phrases?

Quoted 5 lines
Quoted 3 lines
Quoted 2 lines

This is meaningless, sorry can't parse. Ignoring it as others in the community are doing already.

Do you care if the term “null pointer dereference” would be used in consistent ways?

...this is more comprehensible,

Thanks for another bit of constructive information.

Quoted 2 lines

but again I cannot grasp what's yor advice
specifically on this commit message.

May the usage of abbreviations be reconsidered once more also for such messages (in presented update steps)?

Regards,
Markus

#8 lore raw
Quoted 15 lines · Markus Elfring
Quoted 4 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line

Can any other summary phrase variants become more desirable accordingly?

I agree with Sudeep, the above sentence is completely incomprehensible to me

Can any suggestions gain acceptance also for better summary phrases?

Quoted 5 lines
Quoted 3 lines
Quoted 2 lines

This is meaningless, sorry can't parse. Ignoring it as others in the community are doing already.

Do you care if the term “null pointer dereference” would be used in consistent ways?

...this is more comprehensible,

Quoted 8 lines

Thanks for another bit of constructive information.

Quoted 2 lines

but again I cannot grasp what's yor advice
specifically on this commit message.

May the usage of abbreviations be reconsidered once more also for such messages (in presented update steps)?

Still can't understand you. Sorry for that. Alternatively, you can do what I sometimes do: just write the whole commit log as you would expect and see if that helps. I am sure that helps, so please do that.

Signature · 2 lines
Regards,
Sudeep
#9 lore raw
Quoted 4 lines
Quoted 2 lines

May the usage of abbreviations be reconsidered once more also for such messages (in presented update steps)?

Still can't understand you. Sorry for that. …

Will any communication challenges need further clarifications also according to wordings like the following?
* null-ptr-deref
* null pointer dereference

Regards,
Markus

Acked-by on the v2 series
#10 lore raw
In reply to Henry Martin
Quoted 3 lines · Henry Martin

This series fixes potential NULL pointer dereferences in scmi_cpufreq_get_rate() and scpi_cpufreq_get_rate() when cpufreq_cpu_get_raw() returns NULL.

I think unlikely is needed even in this patch[1] and thats what Viresh meant when he mention all similar changes under one series and consistent change.

Also I just happened to notice similar patches posted while ago[2][3]. Not sure how to handle the situation though.

Signature · 6 lines
Regards,
Sudeep

[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/all/[email protected]
[3] https://lore.kernel.org/all/[email protected]
#11 lore raw
Quoted 3 lines

I think unlikely is needed even in this patch[1] and thats what Viresh meant when he mention all similar changes under one series and consistent change.

Thanks for reviewing. I'll send v2 of patch[1] soon.

Quoted 22 lines · Sudeep Holla <[email protected]> 于2025年4月9日周三 19:30写道:
Quoted 3 lines · Henry Martin

This series fixes potential NULL pointer dereferences in scmi_cpufreq_get_rate() and scpi_cpufreq_get_rate() when cpufreq_cpu_get_raw() returns NULL.

I think unlikely is needed even in this patch[1] and thats what Viresh meant when he mention all similar changes under one series and consistent change.

Also I just happened to notice similar patches posted while ago[2][3]. Not sure how to handle the situation though.

--
Regards,
Sudeep

[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/all/[email protected]
[3] https://lore.kernel.org/all/[email protected]

maintainer Applied
#12 lore raw
In reply to Henry Martin
Quoted 10 lines · Henry Martin

This series fixes potential NULL pointer dereferences in scmi_cpufreq_get_rate() and scpi_cpufreq_get_rate() when cpufreq_cpu_get_raw() returns NULL.

Henry Martin (2):
cpufreq: scmi: Fix null-ptr-deref in scmi_cpufreq_get_rate()
cpufreq: scpi: Fix null-ptr-deref in scpi_cpufreq_get_rate()

 drivers/cpufreq/scmi-cpufreq.c | 10 ++++++++--
 drivers/cpufreq/scpi-cpufreq.c | 13 ++++++++++---
 2 files changed, 18 insertions(+), 5 deletions(-)

Applied. Thanks.

Signature · 1 line
viresh