From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4CDC41B2194; Wed, 19 Mar 2025 14:34:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742394894; cv=none; b=O0+LFboUM4YlCad8Swv7s/yfl4v+DKx85VoGbMzsVxp9attJ4JD5hLy4bM6/J5icV2GgMFi3y/Kwungr6tb2e+jKJ5pxW82FUKJ5c/4+/WL3VcjbFHcmRrTFjFzHk+7eZ/Q+7edjkys/QZsyKCnUuOpYrygZLVXMyF3hO0aTj34= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742394894; c=relaxed/simple; bh=Z8zjYVaks+3Reg6ND101Tk7ndRKyUM1TRPhKuKWrTy8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bxiEEELhP9PFD1ysgEXL6HRDgb9YtEanmCho5Mfn/u0KqaKp68KzYthV58OA0DEPlJ1QXBVcGR1G/QCMBKXiCxg8hdH2V7J0gspRclaW4RscdyTlXyDYBVcN+Y/oa30yUf6xgyS+m2pKGFarBBWhNTYtegB/fnxOmxp18B6aTCk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=djr2SCyM; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="djr2SCyM" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 190EEC4CEE4; Wed, 19 Mar 2025 14:34:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1742394894; bh=Z8zjYVaks+3Reg6ND101Tk7ndRKyUM1TRPhKuKWrTy8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=djr2SCyMc/WwlkpaLEQpiS7i98KFVf/1stUSP0ea+1942HqF3y8wvcJ/kyLfJvDme 3fKjPQ9u39kJBD5+g+N5+ZqNrhoPGkBsB7rq7zoSG78gVyqY5ihLzi2W+1cv2o5K0I oMIkebKXyEprt3+ctF95uE4PxY7dAXdHY5VrIECw= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Beata Michalska , Prasanna Kumar T S M , Sumit Gupta , Sudeep Holla , Will Deacon , Sasha Levin Subject: [PATCH 6.13 098/241] arm64: amu: Delay allocating cpumask for AMU FIE support Date: Wed, 19 Mar 2025 07:29:28 -0700 Message-ID: <20250319143030.144745804@linuxfoundation.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250319143027.685727358@linuxfoundation.org> References: <20250319143027.685727358@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.13-stable review patch. If anyone has any objections, please let me know. ------------------ From: Beata Michalska [ Upstream commit d923782b041218ef3804b2fed87619b5b1a497f3 ] For the time being, the amu_fie_cpus cpumask is being exclusively used by the AMU-related internals of FIE support and is guaranteed to be valid on every access currently made. Still the mask is not being invalidated on one of the error handling code paths, which leaves a soft spot with theoretical risk of UAF for CPUMASK_OFFSTACK cases. To make things sound, delay allocating said cpumask (for CPUMASK_OFFSTACK) avoiding otherwise nasty sanitising case failing to register the cpufreq policy notifications. Signed-off-by: Beata Michalska Reviewed-by: Prasanna Kumar T S M Reviewed-by: Sumit Gupta Reviewed-by: Sudeep Holla Link: https://lore.kernel.org/r/20250131155842.3839098-1-beata.michalska@arm.com Signed-off-by: Will Deacon Signed-off-by: Sasha Levin --- arch/arm64/kernel/topology.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/arch/arm64/kernel/topology.c b/arch/arm64/kernel/topology.c index 1a2c72f3e7f80..cb180684d10d5 100644 --- a/arch/arm64/kernel/topology.c +++ b/arch/arm64/kernel/topology.c @@ -194,12 +194,19 @@ static void amu_fie_setup(const struct cpumask *cpus) int cpu; /* We are already set since the last insmod of cpufreq driver */ - if (unlikely(cpumask_subset(cpus, amu_fie_cpus))) + if (cpumask_available(amu_fie_cpus) && + unlikely(cpumask_subset(cpus, amu_fie_cpus))) return; - for_each_cpu(cpu, cpus) { + for_each_cpu(cpu, cpus) if (!freq_counters_valid(cpu)) return; + + if (!cpumask_available(amu_fie_cpus) && + !zalloc_cpumask_var(&amu_fie_cpus, GFP_KERNEL)) { + WARN_ONCE(1, "Failed to allocate FIE cpumask for CPUs[%*pbl]\n", + cpumask_pr_args(cpus)); + return; } cpumask_or(amu_fie_cpus, amu_fie_cpus, cpus); @@ -237,17 +244,8 @@ static struct notifier_block init_amu_fie_notifier = { static int __init init_amu_fie(void) { - int ret; - - if (!zalloc_cpumask_var(&amu_fie_cpus, GFP_KERNEL)) - return -ENOMEM; - - ret = cpufreq_register_notifier(&init_amu_fie_notifier, + return cpufreq_register_notifier(&init_amu_fie_notifier, CPUFREQ_POLICY_NOTIFIER); - if (ret) - free_cpumask_var(amu_fie_cpus); - - return ret; } core_initcall(init_amu_fie); -- 2.39.5