Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp646006img; Fri, 22 Mar 2019 05:51:00 -0700 (PDT) X-Google-Smtp-Source: APXvYqzEFMif9wiGY3PGcDdgFhhknETWr7XGh5HfoecrsQbdLv9wbUGb2lwzdYZTcpwnADM5jX1c X-Received: by 2002:a17:902:9f83:: with SMTP id g3mr9581245plq.296.1553259060502; Fri, 22 Mar 2019 05:51:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553259060; cv=none; d=google.com; s=arc-20160816; b=xix34+BFyz5tVuGd7vTtnz7cD+R6pDL9xqPU10GlEzlwL7swCWCA8d0e2CUzv3jwyk RjqowaJTkNsaHnHF4HwHQDNBUbELM0enkw1uqKydqs0JNqfAzJbis7Jb5J/e/KfggQto WHqL99d4o9wMVI928yR914nCEtxbmQtPqZDNkbEeZTQgtGsIK8rwWqt0lMq7PXHkt7St pjmH9QlEoVsXkUx+x9sW4Pz6BkbkrXIfgpQsoqt3Jd5kc69vSS0xXuhJ/OmxBoes0lvg kvLG9uy4Km4Zs7URQAVYHBIkUZD+zlAIWYE9ap5ij8AWFZ1GmTitpZulMbv+8bUAvjhs Gabw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=ykYKucEGGU/3UDneTZHfezfiszoiK+E7vIinCkoUKDQ=; b=uuIB09my2xi2FBxNmjHBhG85C0VEiSHbUBOluLMylSZCRaTrSCdQtaY4nDjtb4ipLq yVxZyFN1pHfOhEN91GHWL7rPRTN6SHPA39GkiEXSNTC4BzbDBb7ezOVNQz41kAldBhMv FyYbZSTlZdTM8MYXyB2MfH+JaNNmS4s+wCYq3p+HJJve3AjG66PNU3kL8+GnQ7CB9o/S Cg0h7lzIWhPn7XDZFTpAinoLKONGC7gtqTaW3c15pDUq84vQfvIAfvCTpYsSRbJNOVrr VbVmKSjF8WPf3HcJkSYPN07I9js6uy/HZRkYFPl0chI4wKO6dPq8Rj9WR+hcgIWmUq3n Po5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=gk0EXD+4; 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 g19si6587913pgg.235.2019.03.22.05.50.45; Fri, 22 Mar 2019 05:51:00 -0700 (PDT) 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=@kernel.org header.s=default header.b=gk0EXD+4; 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 S2387483AbfCVL4F (ORCPT + 99 others); Fri, 22 Mar 2019 07:56:05 -0400 Received: from mail.kernel.org ([198.145.29.99]:60610 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732549AbfCVLz6 (ORCPT ); Fri, 22 Mar 2019 07:55:58 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 503F920850; Fri, 22 Mar 2019 11:55:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553255757; bh=kgI9TsUw57pvrSLM/LtQTbUgP5jRV5QNx967GbcwMtA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gk0EXD+4MzDVIQcH2J++1bX3jpYSu4qabSqAa9AbetlCsKX9eOCqbxLhhpKkeoPDU IUQB0lcxvFpx5pK6nPyKOY/BZbvgPOzplFp10/ZV0/Li2xtEq8MA+ea6SVhdY6NJmf Kgd7VQsSMZ4LRA3IvYK87TeX1erSyptc8ZqSs4ug= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Sean Christopherson , Paolo Bonzini Subject: [PATCH 4.14 182/183] KVM: nVMX: Ignore limit checks on VMX instructions using flat segments Date: Fri, 22 Mar 2019 12:16:50 +0100 Message-Id: <20190322111255.066141222@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190322111241.819468003@linuxfoundation.org> References: <20190322111241.819468003@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Sean Christopherson commit 34333cc6c2cb021662fd32e24e618d1b86de95bf upstream. Regarding segments with a limit==0xffffffff, the SDM officially states: When the effective limit is FFFFFFFFH (4 GBytes), these accesses may or may not cause the indicated exceptions. Behavior is implementation-specific and may vary from one execution to another. In practice, all CPUs that support VMX ignore limit checks for "flat segments", i.e. an expand-up data or code segment with base=0 and limit=0xffffffff. This is subtly different than wrapping the effective address calculation based on the address size, as the flat segment behavior also applies to accesses that would wrap the 4g boundary, e.g. a 4-byte access starting at 0xffffffff will access linear addresses 0xffffffff, 0x0, 0x1 and 0x2. Fixes: f9eb4af67c9d ("KVM: nVMX: VMX instructions: add checks for #GP/#SS exceptions") Cc: stable@vger.kernel.org Signed-off-by: Sean Christopherson Signed-off-by: Paolo Bonzini Signed-off-by: Greg Kroah-Hartman --- arch/x86/kvm/vmx.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c @@ -7513,10 +7513,16 @@ static int get_vmx_mem_address(struct kv /* Protected mode: #GP(0)/#SS(0) if the segment is unusable. */ exn = (s.unusable != 0); - /* Protected mode: #GP(0)/#SS(0) if the memory - * operand is outside the segment limit. + + /* + * Protected mode: #GP(0)/#SS(0) if the memory operand is + * outside the segment limit. All CPUs that support VMX ignore + * limit checks for flat segments, i.e. segments with base==0, + * limit==0xffffffff and of type expand-up data or code. */ - exn = exn || (off + sizeof(u64) > s.limit); + if (!(s.base == 0 && s.limit == 0xffffffff && + ((s.type & 8) || !(s.type & 4)))) + exn = exn || (off + sizeof(u64) > s.limit); } if (exn) { kvm_queue_exception_e(vcpu,