* [PATCH] arm64: amu: Delay allocating cpumask for AMU FIE support
@ 2025-01-31 15:58 Beata Michalska
2025-01-31 16:34 ` Sudeep Holla
2025-02-13 13:59 ` Will Deacon
0 siblings, 2 replies; 3+ messages in thread
From: Beata Michalska @ 2025-01-31 15:58 UTC (permalink / raw)
To: linux-kernel, linux-arm-kernel, ionela.voinescu, sudeep.holla,
will, catalin.marinas
Cc: sumitg, ptsm
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 <beata.michalska@arm.com>
Reviewed-by: Prasanna Kumar T S M <ptsm@linux.microsoft.com>
Reviewed-by: Sumit Gupta <sumitg@nvidia.com>
---
Hi All,
This change has been previously sent out as a part of a series at [1],
still though, this one is more of a dependency for those changes, and otherwise
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@arm.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;
/* 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.25.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] arm64: amu: Delay allocating cpumask for AMU FIE support
2025-01-31 15:58 [PATCH] arm64: amu: Delay allocating cpumask for AMU FIE support Beata Michalska
@ 2025-01-31 16:34 ` Sudeep Holla
2025-02-13 13:59 ` Will Deacon
1 sibling, 0 replies; 3+ messages in thread
From: Sudeep Holla @ 2025-01-31 16:34 UTC (permalink / raw)
To: Beata Michalska
Cc: linux-kernel, linux-arm-kernel, ionela.voinescu, will,
catalin.marinas, sumitg, ptsm
On Fri, Jan 31, 2025 at 03:58:42PM +0000, Beata Michalska wrote:
> 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.
>
I thought I had provided my tag, sorry for that. FWIW,
Reviewed-by: Sudeep Holla <sudeep.holla@arm.com>
--
Regards,
Sudeep
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] arm64: amu: Delay allocating cpumask for AMU FIE support
2025-01-31 15:58 [PATCH] arm64: amu: Delay allocating cpumask for AMU FIE support Beata Michalska
2025-01-31 16:34 ` Sudeep Holla
@ 2025-02-13 13:59 ` Will Deacon
1 sibling, 0 replies; 3+ messages in thread
From: Will Deacon @ 2025-02-13 13:59 UTC (permalink / raw)
To: linux-kernel, linux-arm-kernel, ionela.voinescu, sudeep.holla,
catalin.marinas, Beata Michalska
Cc: kernel-team, Will Deacon, sumitg, ptsm
On Fri, 31 Jan 2025 15:58:42 +0000, Beata Michalska wrote:
> 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.
>
> [...]
Applied to arm64 (for-next/fixes), thanks!
[1/1] arm64: amu: Delay allocating cpumask for AMU FIE support
https://git.kernel.org/arm64/c/d923782b0412
Cheers,
--
Will
https://fixes.arm64.dev
https://next.arm64.dev
https://will.arm64.dev
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-02-13 14:01 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-01-31 15:58 [PATCH] arm64: amu: Delay allocating cpumask for AMU FIE support Beata Michalska
2025-01-31 16:34 ` Sudeep Holla
2025-02-13 13:59 ` Will Deacon
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).