From: Sasha Levin <sashal@kernel.org>
To: stable@vger.kernel.org
Cc: Zhongqiu Han <zhongqiu.han@oss.qualcomm.com>,
Sashiko <sashiko-bot@kernel.org>,
"Rafael J. Wysocki" <rafael.j.wysocki@intel.com>,
Sasha Levin <sashal@kernel.org>
Subject: [PATCH 6.6.y 4/4] cpufreq: Skip inactive policies in cpufreq_driver_target()
Date: Thu, 3 Dec 2026 14:30:26 -0500 [thread overview]
Message-ID: <20261203193010.628401-4-sashal@kernel.org> (raw)
In-Reply-To: <20261203193010.628401-1-sashal@kernel.org>
From: Zhongqiu Han <zhongqiu.han@oss.qualcomm.com>
[ Upstream commit c5bdb87573726d3a10c58bb3ae09daf017be2297 ]
A policy obtained with cpufreq_cpu_get() may become inactive before
cpufreq_driver_target() acquires its rwsem, which may lead to a NULL
pointer dereference:
CPU X CPU Y (last CPU in policy)
cpufreq_cpu_get()
cpufreq_offline()
__cpufreq_offline()
->exit() /* frees freq_table */
policy->freq_table = NULL
cpufreq_driver_target()
__cpufreq_driver_target()
__target_index()
policy->freq_table[index] /* NULL dereference */
Before commit 2372784542cb ("cpufreq: Drop 'freq_table' argument of
__target_index()"), __cpufreq_driver_target() returned an error if
policy->freq_table was NULL. Since the offline path clears it under the
policy rwsem, which cpufreq_driver_target() also holds, that check was
sufficient to prevent the crash.
The race has been reachable in-tree since commit c210063b40ac
("cpufreq: mediatek: Add opp notification support"), which added the
first caller of cpufreq_driver_target() that can run concurrently with
CPU offline.
Address this by making cpufreq_driver_target() return -EBUSY if the
policy is inactive after acquiring its rwsem, in analogy with the checks
in cpufreq_get(), refresh_frequency_limits() and the sysfs show() and
store() callbacks.
Reported-by: Sashiko <sashiko-bot@kernel.org>
Closes: https://sashiko.dev/#/patchset/20261104153042.3987338-1-zhongqiu.han%40oss.qualcomm.com
Fixes: 2372784542cb ("cpufreq: Drop 'freq_table' argument of __target_index()")
Fixes: c210063b40ac ("cpufreq: mediatek: Add opp notification support")
Cc: 5.19+ <stable@vger.kernel.org> # v5.19+
Signed-off-by: Zhongqiu Han <zhongqiu.han@oss.qualcomm.com>
Link: https://patch.msgid.link/20261110135814.621355-1-zhongqiu.han@oss.qualcomm.com
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
drivers/cpufreq/cpufreq.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
index 18666cdf64d29..7a8c4628b4a9c 100644
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -2454,6 +2454,14 @@ int cpufreq_driver_target(struct cpufreq_policy *policy,
{
guard(cpufreq_policy_write)(policy);
+ /*
+ * The last CPU in the policy may have gone offline after the caller
+ * obtained it, in which case the policy is inactive and must not be
+ * used for changing the frequency.
+ */
+ if (unlikely(policy_is_inactive(policy)))
+ return -EBUSY;
+
return __cpufreq_driver_target(policy, target_freq, relation);
}
EXPORT_SYMBOL_GPL(cpufreq_driver_target);
--
2.53.0
prev parent reply other threads:[~2026-12-03 19:30 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-02 12:59 FAILED: patch "[PATCH] cpufreq: Skip inactive policies in cpufreq_driver_target()" failed to apply to 6.6-stable tree gregkh
2026-12-03 19:30 ` [PATCH 6.6.y 1/4] cpufreq: Consolidate some code in cpufreq_online() Sasha Levin
2026-12-03 19:30 ` [PATCH 6.6.y 2/4] cpufreq: Split cpufreq_online() Sasha Levin
2026-12-03 19:30 ` [PATCH 6.6.y 3/4] cpufreq: Add and use cpufreq policy locking guards Sasha Levin
2026-12-03 19:30 ` Sasha Levin [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=20261203193010.628401-4-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=rafael.j.wysocki@intel.com \
--cc=sashiko-bot@kernel.org \
--cc=stable@vger.kernel.org \
--cc=zhongqiu.han@oss.qualcomm.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.