[PATCH AUTOSEL for 4.14 090/161] x86/hyperv: Check for required priviliges in hyperv_init()

Sasha Levin Alexander.Levin at microsoft.com
Mon Apr 9 00:21:01 UTC 2018


From: Vitaly Kuznetsov <vkuznets at redhat.com>

[ Upstream commit 89a8f6d4904c8cf3ff8fee9fdaff392a6bbb8bf6 ]

In hyperv_init() its presumed that it always has access to VP index and
hypercall MSRs while according to the specification it should be checked if
it's allowed to access the corresponding MSRs before accessing them.

Signed-off-by: Vitaly Kuznetsov <vkuznets at redhat.com>
Signed-off-by: Thomas Gleixner <tglx at linutronix.de>
Reviewed-by: Thomas Gleixner <tglx at linutronix.de>
Cc: Stephen Hemminger <sthemmin at microsoft.com>
Cc: kvm at vger.kernel.org
Cc: Radim Krčmář <rkrcmar at redhat.com>
Cc: Haiyang Zhang <haiyangz at microsoft.com>
Cc: "Michael Kelley (EOSG)" <Michael.H.Kelley at microsoft.com>
Cc: Roman Kagan <rkagan at virtuozzo.com>
Cc: Andy Lutomirski <luto at kernel.org>
Cc: devel at linuxdriverproject.org
Cc: Paolo Bonzini <pbonzini at redhat.com>
Cc: "K. Y. Srinivasan" <kys at microsoft.com>
Cc: Cathy Avery <cavery at redhat.com>
Cc: Mohammed Gamal <mmorsy at redhat.com>
Link: https://lkml.kernel.org/r/20180124132337.30138-2-vkuznets@redhat.com
Signed-off-by: Sasha Levin <alexander.levin at microsoft.com>
---
 arch/x86/hyperv/hv_init.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/arch/x86/hyperv/hv_init.c b/arch/x86/hyperv/hv_init.c
index a0b86cf486e0..2e9d58cc371e 100644
--- a/arch/x86/hyperv/hv_init.c
+++ b/arch/x86/hyperv/hv_init.c
@@ -110,12 +110,19 @@ static int hv_cpu_init(unsigned int cpu)
  */
 void hyperv_init(void)
 {
-	u64 guest_id;
+	u64 guest_id, required_msrs;
 	union hv_x64_msr_hypercall_contents hypercall_msr;
 
 	if (x86_hyper_type != X86_HYPER_MS_HYPERV)
 		return;
 
+	/* Absolutely required MSRs */
+	required_msrs = HV_X64_MSR_HYPERCALL_AVAILABLE |
+		HV_X64_MSR_VP_INDEX_AVAILABLE;
+
+	if ((ms_hyperv.features & required_msrs) != required_msrs)
+		return;
+
 	/* Allocate percpu VP index */
 	hv_vp_index = kmalloc_array(num_possible_cpus(), sizeof(*hv_vp_index),
 				    GFP_KERNEL);
-- 
2.15.1


More information about the devel mailing list