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>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20240402105610.1695644-10-dawei.li@shingroup.cn>
Date: Tue,  2 Apr 2024 18:56:10 +0800
From: Dawei Li <dawei.li@...ngroup.cn>
To: will@...nel.org,
	mark.rutland@....com
Cc: xueshuai@...ux.alibaba.com,
	renyu.zj@...ux.alibaba.com,
	yangyicong@...ilicon.com,
	jonathan.cameron@...wei.com,
	andersson@...nel.org,
	konrad.dybcio@...aro.org,
	linux-arm-kernel@...ts.infradead.org,
	linux-kernel@...r.kernel.org,
	linux-arm-msm@...r.kernel.org,
	Dawei Li <dawei.li@...ngroup.cn>
Subject: [PATCH 9/9] perf/thunder_x2: Avoid explicit cpumask var allocation from stack

For CONFIG_CPUMASK_OFFSTACK=y kernel, explicit allocation of cpumask
variable on stack is not recommended since it can cause potential stack
overflow.

Instead, kernel code should always use *cpumask_var API(s) to allocate
cpumask var in config- neutral way, leaving allocation strategy to
CONFIG_CPUMASK_OFFSTACK.

Use *cpumask_var API(s) to address it.

Signed-off-by: Dawei Li <dawei.li@...ngroup.cn>
---
 drivers/perf/thunderx2_pmu.c | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/drivers/perf/thunderx2_pmu.c b/drivers/perf/thunderx2_pmu.c
index e16d10c763de..8a02a4533b32 100644
--- a/drivers/perf/thunderx2_pmu.c
+++ b/drivers/perf/thunderx2_pmu.c
@@ -932,9 +932,9 @@ static int tx2_uncore_pmu_online_cpu(unsigned int cpu,
 static int tx2_uncore_pmu_offline_cpu(unsigned int cpu,
 		struct hlist_node *hpnode)
 {
-	int new_cpu;
+	cpumask_var_t cpu_online_mask_temp;
 	struct tx2_uncore_pmu *tx2_pmu;
-	struct cpumask cpu_online_mask_temp;
+	int new_cpu;
 
 	tx2_pmu = hlist_entry_safe(hpnode,
 			struct tx2_uncore_pmu, hpnode);
@@ -945,17 +945,21 @@ static int tx2_uncore_pmu_offline_cpu(unsigned int cpu,
 	if (tx2_pmu->hrtimer_callback)
 		hrtimer_cancel(&tx2_pmu->hrtimer);
 
-	cpumask_copy(&cpu_online_mask_temp, cpu_online_mask);
-	cpumask_clear_cpu(cpu, &cpu_online_mask_temp);
-	new_cpu = cpumask_any_and(
-			cpumask_of_node(tx2_pmu->node),
-			&cpu_online_mask_temp);
+	if (!alloc_cpumask_var(&cpu_online_mask_temp, GFP_KERNEL))
+		return 0;
+
+	cpumask_copy(cpu_online_mask_temp, cpu_online_mask);
+	cpumask_clear_cpu(cpu, cpu_online_mask_temp);
+	new_cpu = cpumask_any_and(cpumask_of_node(tx2_pmu->node),
+				  cpu_online_mask_temp);
 
 	tx2_pmu->cpu = new_cpu;
 	if (new_cpu >= nr_cpu_ids)
-		return 0;
+		goto __free_cpumask;
 	perf_pmu_migrate_context(&tx2_pmu->pmu, cpu, new_cpu);
 
+__free_cpumask:
+	free_cpumask_var(cpu_online_mask_temp);
 	return 0;
 }
 
-- 
2.27.0


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ