From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796380850; b=Zm+XkIhEdtEk2vItWQVaOLEeDzHHKXUBT0++46PXfHZRR93Y+PvjFIm9mHYGOecAl3Fm hlqn92E+MbPSy6JQgFqVFrhx4gqo92ZYFwVBk93xgqmvhAcHsagPIdjWmTuy05KJGOYDH GY1a2q6xGWrWNGJ8IbdZpMsaisMkbF1RkRgzTWe5E6WJiYO64KuvgiX5gQ3ngdcnuxffl kX2MWhwz2t0Kp9mAKyw0N4FOi1SbqA+fWwHNej2aPQ9l7tLDeM5pFw/eMu3L7avZhvpNJ 2Qdur0BdAMrTX0dInP85xj4Nwxd9RbpiyPDYakCCV59QTLND5NOKScBlcI2dNtOJmhA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796380850; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=EXhlyMMzY2v9oOu8+cL0n8UgVQJAAsN2tfTEBXNS2ys=; b=gI9GqoysA+YO2nRkVXXz24rZjco50l6cIjVYRU+mNHHHsZPcP4pDr+3R4SblHLpPgh0a 01A2QPHATZVivgs3D70E5d6zWx2G8IVc48I3sxqSnBV0T0Wgf6qbwHd5oEmYHzrUNgUbm da9r5VJCydFIk/UNp9Oc29Qrhw5OlTlhQIg7es6RoxCUyv6yE8RlfciTbe3IE+m87D1l4 QCqjxkW/uNWPFzcpDU4xwnNuWYO49ok7PngPKybS8XCsCG1pHvJm3lshzr6BQ76yOzwNB vmQ4eGsP9chYaVHhhMI/udcsGovx2LnxysUaVhK1enZ5diXWoKf3X4Q9JincDgYUOeQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=ZuA7tChJ; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7651B606A322; Fri, 4 Dec 2026 10:40:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=ZuA7tChJ Received: by smtp.kernel.org (Postfix) with ESMTPSA id E2EA31F000C2; Fri, 4 Dec 2026 10:40:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796380850; bh=EXhlyMMzY2v9oOu8+cL0n8UgVQJAAsN2tfTEBXNS2ys=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=ZuA7tChJgyV5wUjN16veXff/VRPdBFE9c+zYLWwzMiXBqvYLgRtJ6foTtIEOpXiYE 7n/HPZfNN6luuHvlYyD+amYmggqD5s6HbLqhSlkAGVTn0c6n9PMLTrhoHm1tNwcTAX F7gOA44q4/aCrDl6A/dBjeM/EiRE9zIWMjGJQy8A= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Sashiko , Zhongqiu Han , "Rafael J. Wysocki" Subject: [PATCH 7.3 452/742] cpufreq: Skip inactive policies in cpufreq_driver_target() Date: Fri, 4 Dec 2026 19:05:16 +0900 Message-ID: <20261204100647.170326182@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100635.034361255@linuxfoundation.org> References: <20261204100635.034361255@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 7.3-stable review patch. If anyone has any objections, please let me know. ------------------ From: Zhongqiu Han commit c5bdb87573726d3a10c58bb3ae09daf017be2297 upstream. 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 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+ # v5.19+ Signed-off-by: Zhongqiu Han Link: https://patch.msgid.link/20261110135814.621355-1-zhongqiu.han@oss.qualcomm.com Signed-off-by: Rafael J. Wysocki Signed-off-by: Greg Kroah-Hartman --- drivers/cpufreq/cpufreq.c | 8 ++++++++ 1 file changed, 8 insertions(+) --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -2452,6 +2452,14 @@ int cpufreq_driver_target(struct cpufreq { 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);