Skip to content

Commit d923782

Browse files
bea-armwilldeacon
authored andcommitted
arm64: amu: Delay allocating cpumask for AMU FIE support
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 <[email protected]> Reviewed-by: Prasanna Kumar T S M <[email protected]> Reviewed-by: Sumit Gupta <[email protected]> Reviewed-by: Sudeep Holla <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Will Deacon <[email protected]>
1 parent 875d742 commit d923782

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

arch/arm64/kernel/topology.c

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -194,12 +194,19 @@ static void amu_fie_setup(const struct cpumask *cpus)
194194
int cpu;
195195

196196
/* We are already set since the last insmod of cpufreq driver */
197-
if (unlikely(cpumask_subset(cpus, amu_fie_cpus)))
197+
if (cpumask_available(amu_fie_cpus) &&
198+
unlikely(cpumask_subset(cpus, amu_fie_cpus)))
198199
return;
199200

200-
for_each_cpu(cpu, cpus) {
201+
for_each_cpu(cpu, cpus)
201202
if (!freq_counters_valid(cpu))
202203
return;
204+
205+
if (!cpumask_available(amu_fie_cpus) &&
206+
!zalloc_cpumask_var(&amu_fie_cpus, GFP_KERNEL)) {
207+
WARN_ONCE(1, "Failed to allocate FIE cpumask for CPUs[%*pbl]\n",
208+
cpumask_pr_args(cpus));
209+
return;
203210
}
204211

205212
cpumask_or(amu_fie_cpus, amu_fie_cpus, cpus);
@@ -237,17 +244,8 @@ static struct notifier_block init_amu_fie_notifier = {
237244

238245
static int __init init_amu_fie(void)
239246
{
240-
int ret;
241-
242-
if (!zalloc_cpumask_var(&amu_fie_cpus, GFP_KERNEL))
243-
return -ENOMEM;
244-
245-
ret = cpufreq_register_notifier(&init_amu_fie_notifier,
247+
return cpufreq_register_notifier(&init_amu_fie_notifier,
246248
CPUFREQ_POLICY_NOTIFIER);
247-
if (ret)
248-
free_cpumask_var(amu_fie_cpus);
249-
250-
return ret;
251249
}
252250
core_initcall(init_amu_fie);
253251

0 commit comments

Comments
 (0)