From: Adalbert Lazar Subject: [RFC PATCH 15/19] kvm: x86: Hook in kvmi_msr_event() Date: Fri, 16 Jun 2017 16:43:44 +0300 Message-ID: <20170616134348.17725-16-alazar@bitdefender.com> References: <20170616134348.17725-1-alazar@bitdefender.com> Cc: Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= , alazar@bitdefender.com, mdontu@bitdefender.com To: kvm@vger.kernel.org Return-path: Received: from mx02.bbu.dsd.mx.bitdefender.com ([91.199.104.133]:49084 "EHLO mx02.buh.bitdefender.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753555AbdFPNoG (ORCPT ); Fri, 16 Jun 2017 09:44:06 -0400 In-Reply-To: <20170616134348.17725-1-alazar@bitdefender.com> Sender: kvm-owner@vger.kernel.org List-ID: From: Mihai Dontu Inform the guest introspection tool that an MSR is going to be changed. The kvmi_msr_event() function will check a bitmap of MSR-s of interest (configured via a KVMI_EVENT_CONTROL(KVMI_MSR_CONTROL) request) and, if the new value differs from the previous one, it will generate a notification. The introspection tool can respond by allowing the guest to continue with normal execution or by discarding the change. This is meant to prevent malicious changes to MSR-s such as MSR_IA32_SYSENTER_EIP. Signed-off-by: Mihai Dontu --- arch/x86/kvm/x86.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 248fb7e99423..b7d2a9901665 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -1090,6 +1090,23 @@ EXPORT_SYMBOL_GPL(kvm_enable_efer_bits); */ int kvm_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr) { + if (!msr->host_initiated) { + struct msr_data __msr; + + memset(&__msr, 0, sizeof(__msr)); + __msr.host_initiated = true; + __msr.index = msr->index; + + if (!kvm_get_msr(vcpu, &__msr)) { + u64 data = msr->data; + + if (kvmi_msr_event(vcpu, msr->index, __msr.data, &data)) + msr->data = data; + else + return 0; + } + } + switch (msr->index) { case MSR_FS_BASE: case MSR_GS_BASE: -- 2.12.2