Skip to contentSkip to conversation

riscv: hwprobe: Avoid uninitialized read in hwprobe_get_cpus()

PATCH In review Mark Harris 2 participants 2 messages Jul 14 – Jul 15 RISC-V

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 riscv: hwprobe: Avoid uninitialized read in hwprobe_get_cpus()

When cpusetsize < cpumask_size(), hwprobe_get_cpus() did not fully initialize its copy of the cpu mask, which could cause non-deterministic results from the riscv_hwprobe syscall on a system with more than 8 CPUs when the supplied cpu mask is empty. Address this by fully initializing the cpu mask.

Fixes e178bf146e4b ("RISC-V: hwprobe: Introduce which-cpus flag")

---
v2: Add Fixes: and Reviewed-by: tags

 arch/riscv/kernel/sys_hwprobe.c | 1 +
 1 file changed, 1 insertion(+)
arch/riscv/kernel/sys_hwprobe.c +1 -0
index 1659d31fd288..caf6762427c8 100644
@@ -450,6 +450,7 @@ static int hwprobe_get_cpus(struct riscv_hwprobe __user *pairs,
 	if (cpusetsize > cpumask_size())
 		cpusetsize = cpumask_size();
 
+	cpumask_clear(&cpus);
 	ret = copy_from_user(&cpus, cpus_user, cpusetsize);
 	if (ret)
 		return -EFAULT;
Signature · 1 line
2.55.0
maintainer
#1 lore raw
Quoted 10 lines · Mark Harris

When cpusetsize < cpumask_size(), hwprobe_get_cpus() did not fully initialize its copy of the cpu mask, which could cause non-deterministic results from the riscv_hwprobe syscall on a system with more than 8 CPUs when the supplied cpu mask is empty. Address this by fully initializing the cpu mask.

Fixes e178bf146e4b ("RISC-V: hwprobe: Introduce which-cpus flag")

Thanks, queued for v7.2-rc.

- Paul