Received: by 10.223.185.116 with SMTP id b49csp823742wrg; Sat, 10 Feb 2018 21:14:39 -0800 (PST) X-Google-Smtp-Source: AH8x224Ybw7xUpQcmK/l7TbXwWDny3hOQ3/FeJHqeG2jVz7b8E9px/c6yYPgwTB1OYdYLpG2ohFV X-Received: by 10.99.190.74 with SMTP id g10mr2902929pgo.143.1518326079253; Sat, 10 Feb 2018 21:14:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518326079; cv=none; d=google.com; s=arc-20160816; b=l7WGOfcYEuFO+YIMJs2Rs2jm+4BxtmCLfgiG1RM1A6M6HTzuxO8JEfVGx5yJ2Uo6m0 /mAIznG9pfTKAaG3FEQSLxNGkmWG+o/ZBkJK5A+O/p+CpB9dorGzxGRiNfu0dnImEB2G 6Y+Oi0uUf3yByEGgnyfN9Rsq4Ircrp162UvBG3RXGCwmH4NFPpeYnJJQcFI19Pb8XPRn lHjfBUTZiC/UOImNYkcn1JG753UxnN9gnSKFJvM+/BBMmjmJ1I5NudDsLWrYyxRscS37 JD8wRWEctoTbv28pjXtXnQ1ju3h/IkseBzw5vK3SiSGq5WFsbMNT4ZOaH0kPUTqdePnJ uaXQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition :arc-authentication-results; bh=hwzNK6kvDfH3qIYPhKl8X8KL+zgGvwnaauatBMfcDvY=; b=DrjrwD6/YVsIBLkFu+MZaRMy6Uw3hjD1Hl+3ApRbKT+M/T3mtwVmlLlEYDREqq3wnD Hr+rHO37l/f+EA48STd5Q+sj0Rh/iBIPVliPbd7/f9Pdgj0qd95Mjmnl5DIZOa945yRI RAoHVd95TBX/L1SKh3oV82AQDKGmHhB7ArNJgeDNsoCzCK1HuBdPhjPMKaAIS0ezjzwe FT0atsN9nWf0NcWCXzsOv/UFemXGGXVY3Pf0dGBvdE9zgAcdnssq9MWNl2KLd7mtTLJz ZTUZq3fSL2V1qYhga1xJmoH9urb4LjX/H1oC0C2AmK/d8LKhL4mURUGWrpHlvr/JUbfB kxig== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f126si66256pgc.541.2018.02.10.21.14.25; Sat, 10 Feb 2018 21:14:39 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753842AbeBKFM0 (ORCPT + 99 others); Sun, 11 Feb 2018 00:12:26 -0500 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:41410 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752626AbeBKEdl (ORCPT ); Sat, 10 Feb 2018 23:33:41 -0500 Received: from [2a02:8011:400e:2:6f00:88c8:c921:d332] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1ekjKd-0002hP-Tg; Sun, 11 Feb 2018 04:33:40 +0000 Received: from ben by deadeye with local (Exim 4.90) (envelope-from ) id 1ekjKY-0004V8-7u; Sun, 11 Feb 2018 04:33:34 +0000 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, "Paolo Bonzini" , "Nadav Amit" Date: Sun, 11 Feb 2018 04:20:06 +0000 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) Subject: [PATCH 3.2 46/79] KVM: vmx: Inject #GP on invalid PAT CR In-Reply-To: X-SA-Exim-Connect-IP: 2a02:8011:400e:2:6f00:88c8:c921:d332 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.2.99-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: Nadav Amit commit 4566654bb9be9e8864df417bb72ceee5136b6a6a upstream. Guest which sets the PAT CR to invalid value should get a #GP. Currently, if vmx supports loading PAT CR during entry, then the value is not checked. This patch makes the required check in that case. Signed-off-by: Nadav Amit Signed-off-by: Paolo Bonzini Signed-off-by: Ben Hutchings --- arch/x86/kvm/vmx.c | 2 ++ arch/x86/kvm/x86.c | 5 +++-- arch/x86/kvm/x86.h | 2 ++ 3 files changed, 7 insertions(+), 2 deletions(-) --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c @@ -2204,6 +2204,8 @@ static int vmx_set_msr(struct kvm_vcpu * break; case MSR_IA32_CR_PAT: if (vmcs_config.vmentry_ctrl & VM_ENTRY_LOAD_IA32_PAT) { + if (!kvm_mtrr_valid(vcpu, MSR_IA32_CR_PAT, data)) + return 1; vmcs_write64(GUEST_IA32_PAT, data); vcpu->arch.pat = data; break; --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -1274,7 +1274,7 @@ static bool valid_mtrr_type(unsigned t) return t < 8 && (1 << t) & 0x73; /* 0, 1, 4, 5, 6 */ } -static bool mtrr_valid(struct kvm_vcpu *vcpu, u32 msr, u64 data) +bool kvm_mtrr_valid(struct kvm_vcpu *vcpu, u32 msr, u64 data) { int i; @@ -1300,12 +1300,13 @@ static bool mtrr_valid(struct kvm_vcpu * /* variable MTRRs */ return valid_mtrr_type(data & 0xff); } +EXPORT_SYMBOL_GPL(kvm_mtrr_valid); static int set_msr_mtrr(struct kvm_vcpu *vcpu, u32 msr, u64 data) { u64 *p = (u64 *)&vcpu->arch.mtrr_state.fixed_ranges; - if (!mtrr_valid(vcpu, msr, data)) + if (!kvm_mtrr_valid(vcpu, msr, data)) return 1; if (msr == MSR_MTRRdefType) { --- a/arch/x86/kvm/x86.h +++ b/arch/x86/kvm/x86.h @@ -135,6 +135,8 @@ int kvm_write_guest_virt_system(struct x gva_t addr, void *val, unsigned int bytes, struct x86_exception *exception); +bool kvm_mtrr_valid(struct kvm_vcpu *vcpu, u32 msr, u64 data); + extern unsigned int min_timer_period_us; #endif