* [PATCH] cpufreq: apple-soc: Fix possible null-ptr-deref for cpufreq_cpu_get_raw()
@ 2024-12-30 3:57 Charles Han
2024-12-30 7:25 ` Markus Elfring
2024-12-30 9:30 ` Marc Zyngier
0 siblings, 2 replies; 3+ messages in thread
From: Charles Han @ 2024-12-30 3:57 UTC (permalink / raw)
To: marcan, sven, alyssa, rafael, viresh.kumar, maz
Cc: asahi, 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.
But this returned value in apple_soc_cpufreq_get_rate() is not
checked. Add NULL check in apple_soc_cpufreq_get_rate(), to handle
kernel NULL pointer dereference error.
Fixes: 6286bbb40576 ("cpufreq: apple-soc: Add new driver to control Apple SoC CPU P-states")
Signed-off-by: Charles Han <hanchunchao@inspur.com>
---
drivers/cpufreq/apple-soc-cpufreq.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/cpufreq/apple-soc-cpufreq.c b/drivers/cpufreq/apple-soc-cpufreq.c
index 4dcacab9b4bf..1c6d81355b41 100644
--- a/drivers/cpufreq/apple-soc-cpufreq.c
+++ b/drivers/cpufreq/apple-soc-cpufreq.c
@@ -104,6 +104,9 @@ static const struct of_device_id apple_soc_cpufreq_of_match[] __maybe_unused = {
static unsigned int apple_soc_cpufreq_get_rate(unsigned int cpu)
{
struct cpufreq_policy *policy = cpufreq_cpu_get_raw(cpu);
+ if (unlikely(!policy))
+ return 0;
+
struct apple_cpu_priv *priv = policy->driver_data;
struct cpufreq_frequency_table *p;
unsigned int pstate;
--
2.31.1
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH] cpufreq: apple-soc: Fix possible null-ptr-deref for cpufreq_cpu_get_raw()
2024-12-30 3:57 [PATCH] cpufreq: apple-soc: Fix possible null-ptr-deref for cpufreq_cpu_get_raw() Charles Han
@ 2024-12-30 7:25 ` Markus Elfring
2024-12-30 9:30 ` Marc Zyngier
1 sibling, 0 replies; 3+ messages in thread
From: Markus Elfring @ 2024-12-30 7:25 UTC (permalink / raw)
To: Charles Han, linux-pm, linux-arm-kernel, Alyssa Rosenzweig,
Hector Martin, Marc Zyngier, Rafael J. Wysocki, Sven Peter,
Viresh Kumar
Cc: LKML, asahi
> cpufreq_cpu_get_raw() may return NULL if the cpu is not in
CPU?
> policy->cpus cpu mask and it will cause null pointer dereference.
…
Would the summary phrase “Prevent null pointer dereference in apple_soc_cpufreq_get_rate()”
be a bit nicer here?
Regards,
Markus
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] cpufreq: apple-soc: Fix possible null-ptr-deref for cpufreq_cpu_get_raw()
2024-12-30 3:57 [PATCH] cpufreq: apple-soc: Fix possible null-ptr-deref for cpufreq_cpu_get_raw() Charles Han
2024-12-30 7:25 ` Markus Elfring
@ 2024-12-30 9:30 ` Marc Zyngier
1 sibling, 0 replies; 3+ messages in thread
From: Marc Zyngier @ 2024-12-30 9:30 UTC (permalink / raw)
To: Charles Han
Cc: marcan, sven, alyssa, rafael, viresh.kumar, asahi,
linux-arm-kernel, linux-pm, linux-kernel
On Mon, 30 Dec 2024 03:57:14 +0000,
Charles Han <hanchunchao@inspur.com> 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.
> But this returned value in apple_soc_cpufreq_get_rate() is not
> checked. Add NULL check in apple_soc_cpufreq_get_rate(), to handle
> kernel NULL pointer dereference error.
The only way I can see a CPU not having an assigned policy is when the
DT is incomplete. And even then, reaching this code path doesn't look
obvious to me.
Can you describe how you get into this situation?
Thanks,
M.
--
Without deviation from the norm, progress is not possible.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-12-30 9:34 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-12-30 3:57 [PATCH] cpufreq: apple-soc: Fix possible null-ptr-deref for cpufreq_cpu_get_raw() Charles Han
2024-12-30 7:25 ` Markus Elfring
2024-12-30 9:30 ` Marc Zyngier
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).