lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Date:   Wed, 13 Jul 2022 10:11:29 +0800
From:   huhai <15815827059@....com>
To:     linux@...linux.org.uk, dietmar.eggemann@....com, mingo@...nel.org
Cc:     linux-arm-kernel@...ts.infradead.org, linux-kernel@...r.kernel.org,
        huhai <huhai@...inos.cn>
Subject: [PATCH] ARM, sched/topology: fix possible memory allocation failure

From: huhai <huhai@...inos.cn>

When kcalloc in parse_dt_topology() fails and it will lead to a null
pointer access.

Considering update_cpu_capacity() also uses __cpu_capacity, and refer to
the implementation of parse_dt_topology() in drivers/base/arch_topology.c,
use global variables to store capacity in this patch.

Signed-off-by: huhai <huhai@...inos.cn>
---
 arch/arm/kernel/topology.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/arch/arm/kernel/topology.c b/arch/arm/kernel/topology.c
index ef0058de432b..383eaac1dbd2 100644
--- a/arch/arm/kernel/topology.c
+++ b/arch/arm/kernel/topology.c
@@ -68,8 +68,7 @@ static const struct cpu_efficiency table_efficiency[] = {
 	{NULL, },
 };
 
-static unsigned long *__cpu_capacity;
-#define cpu_capacity(cpu)	__cpu_capacity[cpu]
+static unsigned long cpu_capacity[NR_CPUS];
 
 static unsigned long middle_capacity = 1;
 static bool cap_from_dt = true;
@@ -91,9 +90,6 @@ static void __init parse_dt_topology(void)
 	unsigned long capacity = 0;
 	int cpu = 0;
 
-	__cpu_capacity = kcalloc(nr_cpu_ids, sizeof(*__cpu_capacity),
-				 GFP_NOWAIT);
-
 	for_each_possible_cpu(cpu) {
 		const __be32 *rate;
 		int len;
@@ -135,7 +131,7 @@ static void __init parse_dt_topology(void)
 		if (capacity > max_capacity)
 			max_capacity = capacity;
 
-		cpu_capacity(cpu) = capacity;
+		cpu_capacity[cpu] = capacity;
 	}
 
 	/* If min and max capacities are equals, we bypass the update of the
@@ -163,10 +159,10 @@ static void __init parse_dt_topology(void)
  */
 static void update_cpu_capacity(unsigned int cpu)
 {
-	if (!cpu_capacity(cpu) || cap_from_dt)
+	if (!cpu_capacity[cpu] || cap_from_dt)
 		return;
 
-	topology_set_cpu_scale(cpu, cpu_capacity(cpu) / middle_capacity);
+	topology_set_cpu_scale(cpu, cpu_capacity[cpu] / middle_capacity);
 
 	pr_info("CPU%u: update cpu_capacity %lu\n",
 		cpu, topology_get_cpu_scale(cpu));
-- 
2.27.0

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ