[PATCH v2 2/2] x86/hyperv: add a bounds check to hv_cpu_number_to_vp_number()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



We have code that calls into hv_cpu_number_to_vp_number() without
checking that the cpu number is valid, which would cause
hv_cpu_number_to_vp_number() to dereference invalid memory.

Instead, have hv_cpu_number_to_vp_number() fail gracefully and add a
warning to make sure we catch these issues quickly.

Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>
---
 include/asm-generic/mshyperv.h | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/include/asm-generic/mshyperv.h b/include/asm-generic/mshyperv.h
index c5edc5e08b94f..c7d22cb8340ff 100644
--- a/include/asm-generic/mshyperv.h
+++ b/include/asm-generic/mshyperv.h
@@ -125,6 +125,9 @@ extern u32 hv_max_vp_index;
  */
 static inline int hv_cpu_number_to_vp_number(int cpu_number)
 {
+	if (WARN_ON_ONCE(cpu_number < 0 || cpu_number >= num_possible_cpus()))
+		return VP_INVAL;
+
 	return hv_vp_index[cpu_number];
 }
 
-- 
2.25.1




[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux