lkml.org 
[lkml]   [2020]   [Oct]   [5]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH v2 2/2] x86/hyperv: add a bounds check to hv_cpu_number_to_vp_number()
Date
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@kernel.org>
---
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
\
 
 \ /
  Last update: 2020-10-06 01:38    [W:0.044 / U:2.188 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site