Skip to content

Commit ce7b175

Browse files
Lorenzo PieralisiRussell King
authored andcommitted
ARM: 7585/1: kernel: fix nr_cpu_ids check in DT logical map init
If a kernel is configured with a DT containing more /cpu nodes than nr_cpu_ids, the number of cpus must be capped in the DT parsing code. Current code carries out the check, but fails to cap the value and the check is executed after the cpu logical index is used, which can lead to memory corruption due to index overflow. This patch refactors the check against nr_cpu_ids and move it before any computed index is used in the parsing code. Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com> Acked-by: Grant Likely <grant.likely@secretlab.ca> Reported-by: Mark Rutland <mark.rutland@arm.com> Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
1 parent c7cc504 commit ce7b175

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

‎arch/arm/kernel/devtree.c‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,14 @@ void __init arm_dt_init_cpu_maps(void)
139139
i = cpuidx++;
140140
}
141141

142-
tmp_map[i] = hwid;
143-
144-
if (cpuidx > nr_cpu_ids)
142+
if (WARN(cpuidx > nr_cpu_ids, "DT /cpu %u nodes greater than "
143+
"max cores %u, capping them\n",
144+
cpuidx, nr_cpu_ids)) {
145+
cpuidx = nr_cpu_ids;
145146
break;
147+
}
148+
149+
tmp_map[i] = hwid;
146150
}
147151

148152
if (WARN(!bootcpu_valid, "DT missing boot CPU MPIDR[23:0], "

0 commit comments

Comments
 (0)