From: Elazar Leibovich <elazarl@gmail.com>
To: linux-pm@vger.kernel.org
Cc: "Rafael J . Wysocki" <rafael@kernel.org>,
Daniel Lezcano <daniel.lezcano@kernel.org>,
Lukasz Luba <lukasz.luba@arm.com>,
linux-kernel@vger.kernel.org,
Sivan Zohar-Kotzer <sivany32@gmail.com>,
Elazar Leibovich <elazarl@gmail.com>
Subject: [PATCH 2/2] powercap: dtpm_devfreq: Fix out-of-bounds read in set_pd_power_limit()
Date: Fri, 12 Jun 2026 09:25:36 +0300 [thread overview]
Message-ID: <20260612062536.9147-3-elazarl@gmail.com> (raw)
In-Reply-To: <20260612062536.9147-1-elazarl@gmail.com>
From: Sivan Zohar-Kotzer <sivany32@gmail.com>
The loop in set_pd_power_limit() looks for the first perf state whose
power exceeds the requested limit, then uses table[i - 1]. If the very
first perf state already exceeds the limit, the loop breaks at i == 0
and table[-1] is read out of bounds.
The powercap core clamps the requested limit to dtpm->power_min, but
power_min is only captured by update_pd_power_uw() at setup time. If
the energy model table is updated at runtime via
em_dev_update_perf_domain() and the power of the lowest perf state
grows past the stale power_min, the clamped limit can still be below
table[0].power, making the underflow reachable.
Start the scan at index 1 so the lowest perf state is used as the
fallback when even it exceeds the requested limit.
Fixes: e44655617317 ("powercap/drivers/dtpm: Add dtpm devfreq with energy model support")
Signed-off-by: Sivan Zohar-Kotzer <sivany32@gmail.com>
Co-developed-by: Elazar Leibovich <elazarl@gmail.com>
Signed-off-by: Elazar Leibovich <elazarl@gmail.com>
---
drivers/powercap/dtpm_devfreq.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/powercap/dtpm_devfreq.c b/drivers/powercap/dtpm_devfreq.c
index cf16e2756481..1afaae234c01 100644
--- a/drivers/powercap/dtpm_devfreq.c
+++ b/drivers/powercap/dtpm_devfreq.c
@@ -68,7 +68,7 @@ static u64 set_pd_power_limit(struct dtpm *dtpm, u64 power_limit)
rcu_read_lock();
table = em_perf_state_from_pd(pd);
- for (i = 0; i < pd->nr_perf_states; i++) {
+ for (i = 1; i < pd->nr_perf_states; i++) {
if (table[i].power > power_limit)
break;
}
--
2.50.1 (Apple Git-155)
prev parent reply other threads:[~2026-06-12 6:25 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-12 6:25 [PATCH 0/2] powercap: dtpm: Fix out-of-bounds read in the set_pd_power_limit() callbacks Elazar Leibovich
2026-06-12 6:25 ` [PATCH 1/2] powercap: dtpm_cpu: Fix out-of-bounds read in set_pd_power_limit() Elazar Leibovich
2026-06-12 6:25 ` Elazar Leibovich [this message]
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=20260612062536.9147-3-elazarl@gmail.com \
--to=elazarl@gmail.com \
--cc=daniel.lezcano@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=lukasz.luba@arm.com \
--cc=rafael@kernel.org \
--cc=sivany32@gmail.com \
/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