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