Skip to content

Commit ee8d0bb

Browse files
committed
net/iucv: Avoid explicit cpumask var allocation on stack
jira VULN-44434 jira VULN-44433 cve CVE-2024-42094 commit-author Dawei Li <[email protected]> commit be4e130 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 <[email protected]> Reviewed-by: Alexandra Winter <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]> (cherry picked from commit be4e130) Signed-off-by: Jonathan Maple <[email protected]>
1 parent a8d1842 commit ee8d0bb

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

net/iucv/iucv.c

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ static void iucv_setmask_mp(void)
578578
*/
579579
static void iucv_setmask_up(void)
580580
{
581-
cpumask_t cpumask;
581+
static cpumask_t cpumask;
582582
int cpu;
583583

584584
/* Disable all cpu but the first in cpu_irq_cpumask. */
@@ -686,23 +686,33 @@ static int iucv_cpu_online(unsigned int cpu)
686686

687687
static int iucv_cpu_down_prep(unsigned int cpu)
688688
{
689-
cpumask_t cpumask;
689+
cpumask_var_t cpumask;
690+
int ret = 0;
690691

691692
if (!iucv_path_table)
692693
return 0;
693694

694-
cpumask_copy(&cpumask, &iucv_buffer_cpumask);
695-
cpumask_clear_cpu(cpu, &cpumask);
696-
if (cpumask_empty(&cpumask))
695+
if (!alloc_cpumask_var(&cpumask, GFP_KERNEL))
696+
return -ENOMEM;
697+
698+
cpumask_copy(cpumask, &iucv_buffer_cpumask);
699+
cpumask_clear_cpu(cpu, cpumask);
700+
if (cpumask_empty(cpumask)) {
697701
/* Can't offline last IUCV enabled cpu. */
698-
return -EINVAL;
702+
ret = -EINVAL;
703+
goto __free_cpumask;
704+
}
699705

700706
iucv_retrieve_cpu(NULL);
701707
if (!cpumask_empty(&iucv_irq_cpumask))
702-
return 0;
708+
goto __free_cpumask;
709+
703710
smp_call_function_single(cpumask_first(&iucv_buffer_cpumask),
704711
iucv_allow_cpu, NULL, 1);
705-
return 0;
712+
713+
__free_cpumask:
714+
free_cpumask_var(cpumask);
715+
return ret;
706716
}
707717

708718
/**

0 commit comments

Comments
 (0)