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=1796325072; b=TT/bAgyuIa5w4+nEZDQ1q8IwB7mt0h+oJRB9UkaR5157Z5F2D5C+LkU2qeRMl3CUQsAM wwPW4DaiN7Rlk9IqPjIet5HFLhAXA0JzV+jscvQQ2NYmW/UJ/r+6ZOk5FL2Voq1zb5OpC ZUPOrJVpvX/7KWxfQRfk1XVDCoA1gZZBHrH/eWDSGxW/cC3tCuMZ23gK3Oxcu3zyZ41rS 7jX4TmABHKVK19fqb+s+NU5TMXORm3DooMje1liEA8w2FVSyjE3dN9VjJwwpKmzT3hLsG U9+1VIQ8Q3eLIlsevezCyDWrfLPQwTzmXRs3vxtplthvWK2YMaB3u6NggP5Pph//PuA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796325072; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=JcfZA9msOFvMFC2HoLYtNNuKFTC+YqC3IXBfdF8/UGk=; b=aFOs+VkXP7sYNgnaaQai7J0Cy2BgCQRrxdQ+OE5bDkSfa5AoGDtxYRPoilN9jcaKbVle 6s4C/mtoUDL1b9HM+gmwgMC/GRY/RYojkJC6HpvtlNFU4+vXcbklIFHvWS/wXXlTJ5pM2 ndMjI02uL/VFB8ZHero5GYxI5ujldhssY27PVDruSAbBRASOyxkbRLeM6weGgVoJDTl61 iGrANncq2AisHdpJDZnZn0oFWCcI6BwCw+MdU5UAw4neYwqpR5OCW+9MK3taZxyulSbQd e66BV2N9iGKbisSNByh+WiU/c91g9iNqzpaA5PQQ+r0bVeRbnKUdMPpUqk5TMemxy+g== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=RV3RHQLZ; 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 6A38460A2604 for ; Thu, 3 Dec 2026 19:11:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=RV3RHQLZ Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5D6251F0092B; Thu, 3 Dec 2026 19:11:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796325072; bh=JcfZA9msOFvMFC2HoLYtNNuKFTC+YqC3IXBfdF8/UGk=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=RV3RHQLZc9QkQHyC69nwen+7nlRbS3QTBZZQ5SiVbpP9yxAU3PivtKKfgGrnJt7wt Bw0MN7VMVxt28WdaYGg2fh4vXD8He7ja0lNlQkBvpx7lcbZdEYyXiGXL5dVp72kAz9 KHpqjzeOCqa50TPoBuaZpiL+YcHFO4D3XlOesy4PgxOs8fN8OUOurxm69aYJHvBcRb fRqagr5Cs4WzCccXGURqDc7CiaMznlthNVq9ZMonknlRZP8APLN0mHlCDsxuMleF1e csXH6PDmurUlSC8R55nE7rZKOfV4rjjgjsvPwhldKOe27EDWaTr6fLCdUhjn1M+6QW V9gshksKzTgSQ== From: Sasha Levin To: stable@vger.kernel.org Cc: Zhongqiu Han , Sashiko , "Rafael J. Wysocki" , Sasha Levin Subject: [PATCH 6.12.y 4/4] cpufreq: Skip inactive policies in cpufreq_driver_target() Date: Thu, 3 Dec 2026 14:11:06 -0500 Message-ID: <20261203191049.594480-4-sashal@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261203191049.594480-1-sashal@kernel.org> References: <2026120246-salami-crudely-9a3f@gregkh> <20261203191049.594480-1-sashal@kernel.org> 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 From: Zhongqiu Han [ 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 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: Sasha Levin --- drivers/cpufreq/cpufreq.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index 4649c6ec541fc..8dacb922e0bb4 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -2435,6 +2435,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