Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp1383432ybf; Thu, 27 Feb 2020 09:56:07 -0800 (PST) X-Google-Smtp-Source: APXvYqwCt4aQk95yZkkLkmqcb7/LP1UQJ+Ag4nR6DMInMQL7o54LAhzM3Vpml6YBvMGGsOViegDg X-Received: by 2002:aca:d03:: with SMTP id 3mr160995oin.69.1582826166920; Thu, 27 Feb 2020 09:56:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582826166; cv=none; d=google.com; s=arc-20160816; b=N4QPMz7Zn1hCQ3ANQLUQtVHQjBNvZjYRIh1VJbnL7lT76worWs5Zpknut8DGa2sKoF JXR5hBEYknmqH/fwLbGlW+/aIc19Y8nhRjjpmm+74FktmhSfZU3lkN32ICHG8rvqVH/j kxFjFCKvWGwWeKgk0IK8tQyKXeTtgonimtz+1cFWKYlo2GZM6JwiBLHViiTb0D0IUZd5 3EYxxZPrDMmwDVVTZ0ytIQBfwAZQvXwPH4sO2H1kzA+Ka6ctCRelSScwlpjSZeRqDFgd EraJVADiyYuoD57pibw1PdVBcAwJLT104l4urabLGhk1XZ4dHNc9ZHNMUgS0sB3zGGvX fWLA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=NylVHJE6upVF29IVdBuSvP++A0hZb65rcSiVqx/spX0=; b=xvxa406Yx99ja9O0InkQnY8ms7PXtAfmNJNFEzXkyiBkWNZhO0HEUO20LnCzxcrd1l T5VOnLH/NNEhfaM+6m45+Mqi0/GEmapXUcSpfutqMl3msq7Ydsl1vwayZ2ye9AuF7Reh Zl0GupncTuzSNa9U1jQtgK+IA7lERipEV5fmMndx5WMWSWi19mX2EpxRHUGsStgugh54 Q6nhZW3okNP/+IVbeBFW0aiGugodf2Zmh34HCUhWNEYnGyXvk3xXR7uReMdRmKLvfvyM iTZFPq3pmQRF1QalgPErimfm5ueeKJDaUL2M5MSLNeQgMgmjGAhayjbGK6OuxihI5WZR yGqQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=eOiS86vi; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w20si265643oic.103.2020.02.27.09.55.54; Thu, 27 Feb 2020 09:56:06 -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; dkim=pass header.i=@google.com header.s=20161025 header.b=eOiS86vi; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730545AbgB0Rzp (ORCPT + 99 others); Thu, 27 Feb 2020 12:55:45 -0500 Received: from mail-io1-f65.google.com ([209.85.166.65]:43569 "EHLO mail-io1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729624AbgB0Rzp (ORCPT ); Thu, 27 Feb 2020 12:55:45 -0500 Received: by mail-io1-f65.google.com with SMTP id n21so383895ioo.10 for ; Thu, 27 Feb 2020 09:55:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=NylVHJE6upVF29IVdBuSvP++A0hZb65rcSiVqx/spX0=; b=eOiS86viM71jTaieN8tpKi/iZHr0ck18Lvx7IOIytjUhy17X68LguUFd/elbTXuZLH lM6D06RdoG36UyIH1ELD/OKP4tk2qxDf3avqVhYoVcNgtYw3AgmEXz0Av6gshpEehdP/ AO0BzoR/+HGd1J+/TYdPwercOcnCP44Om7rOZiJIJovsCbo5eT78DOyShKW9mdw8lSH/ x/QD7aSj0jOfyn4RMFjxgL48f2ZF00YY4/95eP/WgT9N0lCVpWGsHzbS6fecmWThDueV ywuDRWa2kMVvy00eIgULbTOZdthUVPjBNVtNwrwWvMIPB/BmthzIxfXLtVyUOZW9vuou 3uOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=NylVHJE6upVF29IVdBuSvP++A0hZb65rcSiVqx/spX0=; b=uKUtVbfZJ4Lmx+fmoIjEKhAp7SPW5dPO7VRk29AO9C5qNUFmLVkqNU9vsWxVl4FXqU iJSARnEXF7zduupFSehup1hdt/miRD5gh7qfhG/a0iHkgfZJV/k3ko6/LzNLLXvUTXbb t3UVTTZaLnZcPy19+Re2KExri6yAgpoBp65fnH0BxkNQbX3bGgvqj00MGZw+iB4mlnff iPXmrFTUba+NpT5ikxzBukGoizB2lAt1lXLhDRJUewfex5BLATj5zMRNi3eg5t4+LE6v tPEqftzMUh64WLVkjiWMIAQ+AWcNYrK7BrMN93+QBqe1zhcH4MpOkiOFZl1QXEy3xysu 09ww== X-Gm-Message-State: APjAAAU3YF2BYmy46w/hiP3bJYTxZvasjyA1i+17RCy+7g5uLN5dTZ5R JHO09ReWwAaIBVdQEt9iCEOXatKvqN9Igf5DrY6xzA== X-Received: by 2002:a05:6602:2c91:: with SMTP id i17mr443965iow.26.1582826143722; Thu, 27 Feb 2020 09:55:43 -0800 (PST) MIME-Version: 1.0 References: <20200227172306.21426-1-mgamal@redhat.com> <20200227172306.21426-3-mgamal@redhat.com> In-Reply-To: <20200227172306.21426-3-mgamal@redhat.com> From: Jim Mattson Date: Thu, 27 Feb 2020 09:55:32 -0800 Message-ID: Subject: Re: [PATCH 2/5] KVM: VMX: Add guest physical address check in EPT violation and misconfig To: Mohammed Gamal Cc: kvm list , Paolo Bonzini , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Joerg Roedel , LKML Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Feb 27, 2020 at 9:23 AM Mohammed Gamal wrote: > > Check guest physical address against it's maximum physical memory. If Nit: "its," without an apostrophe. > the guest's physical address exceeds the maximum (i.e. has reserved bits > set), inject a guest page fault with PFERR_RSVD_MASK. > > Signed-off-by: Mohammed Gamal > --- > arch/x86/kvm/vmx/vmx.c | 13 +++++++++++++ > 1 file changed, 13 insertions(+) > > diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c > index 63aaf44edd1f..477d196aa235 100644 > --- a/arch/x86/kvm/vmx/vmx.c > +++ b/arch/x86/kvm/vmx/vmx.c > @@ -5162,6 +5162,12 @@ static int handle_ept_violation(struct kvm_vcpu *vcpu) > gpa = vmcs_read64(GUEST_PHYSICAL_ADDRESS); > trace_kvm_page_fault(gpa, exit_qualification); > > + /* Check if guest gpa doesn't exceed physical memory limits */ > + if (gpa >= (1ull << cpuid_maxphyaddr(vcpu))) { > + kvm_inject_rsvd_bits_pf(vcpu, gpa); Even if PFERR_RSVD_MASK is set in the page fault error code, shouldn't we set still conditionally set: PFERR_WRITE_MASK - for an attempted write PFERR_USER_MASK - for a usermode access PFERR_FETCH_MASK - for an instruction fetch > + return 1; > + } > + > /* Is it a read fault? */ > error_code = (exit_qualification & EPT_VIOLATION_ACC_READ) > ? PFERR_USER_MASK : 0; > @@ -5193,6 +5199,13 @@ static int handle_ept_misconfig(struct kvm_vcpu *vcpu) > * nGPA here instead of the required GPA. > */ > gpa = vmcs_read64(GUEST_PHYSICAL_ADDRESS); > + > + /* Check if guest gpa doesn't exceed physical memory limits */ > + if (gpa >= (1ull << cpuid_maxphyaddr(vcpu))) { > + kvm_inject_rsvd_bits_pf(vcpu, gpa); And here as well? > + return 1; > + } > + > if (!is_guest_mode(vcpu) && > !kvm_io_bus_write(vcpu, KVM_FAST_MMIO_BUS, gpa, 0, NULL)) { > trace_kvm_fast_mmio(gpa); > -- > 2.21.1 >