From: Sivan Zohar-Kotzer <sivany32@gmail.com>
To: Daniel Lezcano <daniel.lezcano@kernel.org>,
"Rafael J . Wysocki" <rafael@kernel.org>
Cc: elazarl@gmail.com, linux-pm@vger.kernel.org,
linux-kernel@vger.kernel.org,
Sivan Zohar-Kotzer <sivany32@gmail.com>
Subject: [PATCH] powercap: dtpm_cpu: Fix NULL pointer dereference race during CPU offlining
Date: Thu, 19 Jun 2025 02:16:31 +0300 [thread overview]
Message-ID: <20250618231632.113471-1-sivany32@gmail.com> (raw)
The get_pd_power_uw() function contains a race condition during CPU
offlining:
* DTPM power calculations are triggered (e.g., via sysfs reads) while CPU is online
* The CPU goes offline during the calculation, before em_cpu_get() is called
* em_cpu_get() now returns NULL since the energy model was unregistered
* em_span_cpus() dereferences the NULL pointer, causing a crash
Commit eb82bace8931 introduced the call to em_span_cpus(pd) without
checking if pd is NULL.
Add a NULL check after em_cpu_get() and return 0 power if no energy model
is available, matching the existing fallback behavior.
Fixes: eb82bace8931 ("powercap/drivers/dtpm: Scale the power with the load")
Signed-off-by: Sivan Zohar-Kotzer <sivany32@gmail.com>
---
drivers/powercap/dtpm_cpu.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/drivers/powercap/dtpm_cpu.c b/drivers/powercap/dtpm_cpu.c
index 6b6f51b21550..80d93ab4dc54 100644
--- a/drivers/powercap/dtpm_cpu.c
+++ b/drivers/powercap/dtpm_cpu.c
@@ -97,6 +97,11 @@ static u64 get_pd_power_uw(struct dtpm *dtpm)
pd = em_cpu_get(dtpm_cpu->cpu);
+ if (!pd) {
+ pr_warn("DTPM: No energy model available for CPU%d\n", dtpm_cpu->cpu);
+ return 0;
+ }
+
pd_mask = em_span_cpus(pd);
freq = cpufreq_quick_get(dtpm_cpu->cpu);
@@ -207,6 +212,7 @@ static int __dtpm_cpu_setup(int cpu, struct dtpm *parent)
pd = em_cpu_get(cpu);
if (!pd || em_is_artificial(pd)) {
ret = -EINVAL;
+
goto release_policy;
}
--
2.45.2
next reply other threads:[~2025-06-18 23:16 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-18 23:16 Sivan Zohar-Kotzer [this message]
2025-06-27 20:06 ` [PATCH] powercap: dtpm_cpu: Fix NULL pointer dereference race during CPU offlining Rafael J. Wysocki
2025-06-28 22:12 ` Elazar Leibovich
2025-06-30 20:16 ` Rafael J. Wysocki
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=20250618231632.113471-1-sivany32@gmail.com \
--to=sivany32@gmail.com \
--cc=daniel.lezcano@kernel.org \
--cc=elazarl@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=rafael@kernel.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;
as well as URLs for NNTP newsgroup(s).