ARM: kernel: fix nr_cpu_ids check in DT logical map init
PATCH 1/1 ARM: 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.
---
Russell,
while refactoring the DT loop over nodes, I unfortunately missed this niggle in the parsing loop that Mark reported. Here is the fix, sorry for the additional commit, if it is ok for you I will add it to your patch system.
Apologies and thanks,
Lorenzo
arch/arm/kernel/devtree.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
arch/arm/kernel/devtree.c +7 -3
@@ -139,10 +139,14 @@ void __init arm_dt_init_cpu_maps(void) i = cpuidx++; } - tmp_map[i] = hwid; - -if (cpuidx > nr_cpu_ids) +if (WARN (cpuidx > nr_cpu_ids,"DT /cpu %u nodes greater than " +"max cores %u, capping them\n" , + cpuidx, nr_cpu_ids)) { + cpuidx = nr_cpu_ids;break ; + } + + tmp_map[i] = hwid; } if (WARN(!bootcpu_valid, "DT missing boot CPU MPIDR[23:0], "
Signature · 1 line
1.7.12
PATCH 1/1 ARM: kernel: fix nr_cpu_ids check in DT logical map init
Hi Russell,
Quoted 36 lines · Lorenzo Pieralisi
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_idsand move it before any computed index is used in the parsing code.Signed-off-by Lorenzo Pieralisi <[email protected]>Reported-by Mark Rutland <[email protected]>---
Russell,while refactoring the DT loop over nodes, I unfortunately missed this niggle in the parsing loop that Mark reported. Here is the fix, sorry for the additional commit, if it is ok for you I will add it to your patch system.
Apologies and thanks,
Lorenzoarch/arm/kernel/devtree.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)arch/arm/kernel/devtree.c +1
-3@@ -139,10 +139,14 @@ void __init arm_dt_init_cpu_maps(void) i = cpuidx++; } - tmp_map[i] = hwid; - -if (cpuidx > nr_cpu_ids) + if (WARN(cpuidx > nr_cpu_ids, "DT /cpu %u nodes greater than "
arch/arm/kernel/devtree.c void __init arm_dt_init_cpu_maps(void) · line 152
Quoted 10 lines
arch/arm/kernel/devtree.c +6
-0+ "max cores %u, capping them\n", + cpuidx, nr_cpu_ids)) { + cpuidx = nr_cpu_ids;break ; + } + + tmp_map[i] = hwid; } if (WARN(!bootcpu_valid, "DT missing boot CPU MPIDR[23:0], "
If it looks fine to you, can I queue this simple fix in your patch system please ?
Thanks and apologies for the extra commit,
Lorenzo
PATCH 1/1 ARM: kernel: fix nr_cpu_ids check in DT logical map init
Quoted 48 lines · Lorenzo Pieralisi
Hi Russell,
Quoted 45 lines · Lorenzo Pieralisi
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_idsand move it before any computed index is used in the parsing code.Signed-off-by Lorenzo Pieralisi <[email protected]>Reported-by Mark Rutland <[email protected]>---
Russell,while refactoring the DT loop over nodes, I unfortunately missed this niggle in the parsing loop that Mark reported. Here is the fix, sorry for the additional commit, if it is ok for you I will add it to your patch system.
Apologies and thanks,
Lorenzoarch/arm/kernel/devtree.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)arch/arm/kernel/devtree.c +7
-3@@ -139,10 +139,14 @@ void __init arm_dt_init_cpu_maps(void) i = cpuidx++; } - tmp_map[i] = hwid; - -if (cpuidx > nr_cpu_ids) +if (WARN (cpuidx > nr_cpu_ids,"DT /cpu %u nodes greater than " +"max cores %u, capping them\n" , + cpuidx, nr_cpu_ids)) { + cpuidx = nr_cpu_ids;break ; + } + + tmp_map[i] = hwid; }
Quoted 7 lines
arch/arm/kernel/devtree.c void __init arm_dt_init_cpu_maps(void) · line 152
Quoted 1 line
arch/arm/kernel/devtree.c +0
-0if (WARN(!bootcpu_valid, "DT missing boot CPU MPIDR[23:0], "If it looks fine to you, can I queue this simple fix in your patch system please ?
Thanks and apologies for the extra commit,
Lorenzo
PATCH 1/1 ARM: kernel: fix nr_cpu_ids check in DT logical map init
Quoted 54 lines · Grant Likely
Quoted 53 lines · Lorenzo Pieralisi
Hi Russell,
Quoted 36 lines · Lorenzo Pieralisi
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_idsand move it before any computed index is used in the parsing code.Signed-off-by Lorenzo Pieralisi <[email protected]>Reported-by Mark Rutland <[email protected]>---
Russell,while refactoring the DT loop over nodes, I unfortunately missed this niggle in the parsing loop that Mark reported. Here is the fix, sorry for the additional commit, if it is ok for you I will add it to your patch system.
Apologies and thanks,
Lorenzoarch/arm/kernel/devtree.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)arch/arm/kernel/devtree.c +1
-3@@ -139,10 +139,14 @@ void __init arm_dt_init_cpu_maps(void) i = cpuidx++; } - tmp_map[i] = hwid; - -if (cpuidx > nr_cpu_ids) + if (WARN(cpuidx > nr_cpu_ids, "DT /cpu %u nodes greater than "arch/arm/kernel/devtree.c void __init arm_dt_init_cpu_maps(void) · line 152
Quoted 10 lines
arch/arm/kernel/devtree.c +6
-0+ "max cores %u, capping them\n", + cpuidx, nr_cpu_ids)) { + cpuidx = nr_cpu_ids;break ; + } + + tmp_map[i] = hwid; } if (WARN(!bootcpu_valid, "DT missing boot CPU MPIDR[23:0], "If it looks fine to you, can I queue this simple fix in your patch system please ?
Quoted 4 lines
Quoted 2 lines
Thanks and apologies for the extra commit,
LorenzoAcked-by Grant Likely <[email protected]>
Thanks a lot Grant.
Queued with ID: 7585/1
Thanks,
Lorenzo