Skip to contentSkip to conversation

MIPS: CPS: Fix potential NULL pointer dereferences in cps_prepare_cpus()

PATCH Applied Thorsten Blum 2 participants 2 messages Apr 7, 2025 – Apr 27, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 MIPS: CPS: Fix potential NULL pointer dereferences in cps_prepare_cpus()

Check the return values of kcalloc() and exit early to avoid potential NULL pointer dereferences.

Compile-tested only.

Fixes 75fa6a583882e ("MIPS: CPS: Introduce struct cluster_boot_config")
Fixes 0856c143e1cd3 ("MIPS: CPS: Boot CPUs in secondary clusters")
---
 arch/mips/kernel/smp-cps.c | 4 ++++
 1 file changed, 4 insertions(+)
arch/mips/kernel/smp-cps.c +4 -0
index e85bd087467e..cc26d56f3ab6 100644
@@ -332,6 +332,8 @@ static void __init cps_prepare_cpus(unsigned int max_cpus)
 	mips_cps_cluster_bootcfg = kcalloc(nclusters,
 					   sizeof(*mips_cps_cluster_bootcfg),
 					   GFP_KERNEL);
+	if (!mips_cps_cluster_bootcfg)
+		goto err_out;
 
 	if (nclusters > 1)
 		mips_cm_update_property();
@@ -348,6 +350,8 @@ static void __init cps_prepare_cpus(unsigned int max_cpus)
 		mips_cps_cluster_bootcfg[cl].core_power =
 			kcalloc(BITS_TO_LONGS(ncores), sizeof(unsigned long),
 				GFP_KERNEL);
+		if (!mips_cps_cluster_bootcfg[cl].core_power)
+			goto err_out;
 
 		/* Allocate VPE boot configuration structs */
 		for (c = 0; c < ncores; c++) {
Signature · 1 line
2.49.0
maintainer Applied
#1 lore raw
Quoted 37 lines · Thorsten Blum

Check the return values of kcalloc() and exit early to avoid potential NULL pointer dereferences.

Compile-tested only.

Fixes 75fa6a583882e ("MIPS: CPS: Introduce struct cluster_boot_config")
Fixes 0856c143e1cd3 ("MIPS: CPS: Boot CPUs in secondary clusters")
---
 arch/mips/kernel/smp-cps.c | 4 ++++
 1 file changed, 4 insertions(+)
arch/mips/kernel/smp-cps.c +4 -0
index e85bd087467e..cc26d56f3ab6 100644
@@ -332,6 +332,8 @@ static void __init cps_prepare_cpus(unsigned int max_cpus)
 	mips_cps_cluster_bootcfg = kcalloc(nclusters,
 					   sizeof(*mips_cps_cluster_bootcfg),
 					   GFP_KERNEL);
+	if (!mips_cps_cluster_bootcfg)
+		goto err_out;
 
 	if (nclusters > 1)
 		mips_cm_update_property();
@@ -348,6 +350,8 @@ static void __init cps_prepare_cpus(unsigned int max_cpus)
 		mips_cps_cluster_bootcfg[cl].core_power =
 			kcalloc(BITS_TO_LONGS(ncores), sizeof(unsigned long),
 				GFP_KERNEL);
+		if (!mips_cps_cluster_bootcfg[cl].core_power)
+			goto err_out;
 
 		/* Allocate VPE boot configuration structs */
 		for (c = 0; c < ncores; c++) {
Signature · 1 line
2.49.0

applied to mips-fixes.

Thomas.

Signature · 2 lines
Crap can work. Given enough thrust pigs will fly, but it's not necessarily a
good idea.                                                [ RFC1925, 2.3 ]