Skip to content

Commit

Permalink
kernel: Initialize cpumask before parsing
Browse files Browse the repository at this point in the history
KMSAN complains that new_value at cpumask_parse_user() from
write_irq_affinity() from irq_affinity_proc_write() is uninitialized.

  [  148.133411][ T5509] =====================================================
  [  148.135383][ T5509] BUG: KMSAN: uninit-value in find_next_bit+0x325/0x340
  [  148.137819][ T5509]
  [  148.138448][ T5509] Local variable ----new_value.i@irq_affinity_proc_write created at:
  [  148.140768][ T5509]  irq_affinity_proc_write+0xc3/0x3d0
  [  148.142298][ T5509]  irq_affinity_proc_write+0xc3/0x3d0
  [  148.143823][ T5509] =====================================================

Since bitmap_parse() from cpumask_parse_user() calls find_next_bit(),
any alloc_cpumask_var() + cpumask_parse_user() sequence has possibility
that find_next_bit() accesses uninitialized cpu mask variable. Fix this
problem by replacing alloc_cpumask_var() with zalloc_cpumask_var().

Signed-off-by: Tetsuo Handa <[email protected]>
Signed-off-by: Thomas Gleixner <[email protected]>
Acked-by: Steven Rostedt (VMware) <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
  • Loading branch information
Tetsuo Handa authored and KAGA-KOKO committed Apr 10, 2021
1 parent 883ccef commit c5e3a41
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions kernel/irq/proc.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ static ssize_t write_irq_affinity(int type, struct file *file,
if (!irq_can_set_affinity_usr(irq) || no_irq_affinity)
return -EIO;

if (!alloc_cpumask_var(&new_value, GFP_KERNEL))
if (!zalloc_cpumask_var(&new_value, GFP_KERNEL))
return -ENOMEM;

if (type)
Expand Down Expand Up @@ -238,7 +238,7 @@ static ssize_t default_affinity_write(struct file *file,
cpumask_var_t new_value;
int err;

if (!alloc_cpumask_var(&new_value, GFP_KERNEL))
if (!zalloc_cpumask_var(&new_value, GFP_KERNEL))
return -ENOMEM;

err = cpumask_parse_user(buffer, count, new_value);
Expand Down
2 changes: 1 addition & 1 deletion kernel/profile.c
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ static ssize_t prof_cpu_mask_proc_write(struct file *file,
cpumask_var_t new_value;
int err;

if (!alloc_cpumask_var(&new_value, GFP_KERNEL))
if (!zalloc_cpumask_var(&new_value, GFP_KERNEL))
return -ENOMEM;

err = cpumask_parse_user(buffer, count, new_value);
Expand Down
2 changes: 1 addition & 1 deletion kernel/trace/trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -4827,7 +4827,7 @@ tracing_cpumask_write(struct file *filp, const char __user *ubuf,
cpumask_var_t tracing_cpumask_new;
int err;

if (!alloc_cpumask_var(&tracing_cpumask_new, GFP_KERNEL))
if (!zalloc_cpumask_var(&tracing_cpumask_new, GFP_KERNEL))
return -ENOMEM;

err = cpumask_parse_user(ubuf, count, tracing_cpumask_new);
Expand Down

0 comments on commit c5e3a41

Please sign in to comment.