From nobody Sun Feb 8 17:47:42 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 528611D0E2B for ; Fri, 31 Jan 2025 15:59:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738339143; cv=none; b=fhD8m1Ep+6ezEaLX0rSf/TdkMC+cpj1NHKFUC/4cfOBL1KrEY18YRwpgo7NFJSGfHEWBwATR2nuu4uRBtmAJBVUofiexeWFdEOVyaDaZUlbzD4tA55HvX1tLc1ahoo/6y4PLe2zVQHjYnq0SiJIABEATFWKjAI4xoalqIaTj5OY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738339143; c=relaxed/simple; bh=njkPhXpWnLyqQ4ncATus4+/1+OmM0lmQM6djDahL+QY=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=LYDKlJjgL/+4DLkjOZqcyrXivb60HzDFS3aOPldGlMHAgxLoeO27fZ/gqkHqEoKllNpltqrR342NyVUqdI6od7mB68GLi9F+iJhzGc/UUx/upRRvveEB0oPHGeqDHa3RlbY/bK3HncQ9thW9RVGR1DIZ+JGu7yFy9unkiWUBlec= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 1317F497; Fri, 31 Jan 2025 07:59:26 -0800 (PST) Received: from e125905.cambridge.arm.com (e125905.cambridge.arm.com [10.1.194.73]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 64A843F694; Fri, 31 Jan 2025 07:58:59 -0800 (PST) From: Beata Michalska To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, ionela.voinescu@arm.com, sudeep.holla@arm.com, will@kernel.org, catalin.marinas@arm.com Cc: sumitg@nvidia.com, ptsm@linux.microsoft.com Subject: [PATCH] arm64: amu: Delay allocating cpumask for AMU FIE support Date: Fri, 31 Jan 2025 15:58:42 +0000 Message-Id: <20250131155842.3839098-1-beata.michalska@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 --- Hi All, This change has been previously sent out as a part of a series at [1],=20 still though, this one is more of a dependency for those changes, and other= wise can be safely merged separately, thus excluding it from the above mentioned patch-set. [1] https://lore.kernel.org/all/20250121084435.2839280-1-beata.michalska@ar= m.com/ BR Beata 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 1a2c72f3e7f8..cb180684d10d 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; =20 /* 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; =20 - 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; } =20 cpumask_or(amu_fie_cpus, amu_fie_cpus, cpus); @@ -237,17 +244,8 @@ static struct notifier_block init_amu_fie_notifier =3D= { =20 static int __init init_amu_fie(void) { - int ret; - - if (!zalloc_cpumask_var(&amu_fie_cpus, GFP_KERNEL)) - return -ENOMEM; - - ret =3D 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); =20 --=20 2.25.1