Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp627124img; Fri, 22 Mar 2019 05:26:48 -0700 (PDT) X-Google-Smtp-Source: APXvYqxPWO9FquUsaaemovp/Xr6nLVcpuxZWHxYoXA76NIa3N+3DEnhOTiTDcd+6KrLN/3rynUlR X-Received: by 2002:a17:902:e01:: with SMTP id 1mr9476481plw.128.1553257608930; Fri, 22 Mar 2019 05:26:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553257608; cv=none; d=google.com; s=arc-20160816; b=DDnmUo0s7SvtG1t7wdsqXuhXlc0moqN2UQ5k+Xqyje4QbL3LFM7v1DdUTiemE/Ss+8 RXbM8kfu2OUd0AiKC8Y4IAoevpPG9yLUuxgPUBNE3HG7g66cf5wvt8oe2IIIrfygckXE H80Q3LPkN+3O7jr5TkFuLqWJfasZMREYtMTRzoCMCa1Fc7mwHdyfL52Z+VsN+t9F3NVa xI2K+ydNBQBX5XIImKkv0MA0qVKS/xcGA1aKIjmJkfpB7ICG55YEJBjh3dJ0204H3P7s 0bG/O/kDkxuX95ysLvEs9HYlzMpjZ86mJiUVR9avnHgDNKeqxrKaVrP69puYCVca3Peq SJwQ== 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=VdL5a+EzDSb7teHIB3g5jAwDLc9LfAzfmfQPJJB/j64=; b=f7aCDGaCBPU5zU4zrDG2sWZKZqiZEydFp+ZYdwwqbVqAq48hKd82z4Gqz9uIGrwW0D V8Xyq6rincwLLrUsQWkR8BXCTbaFUaAMqPbm0Bb2OwD8eFKTbCvatkMGZFIHCqbDdePh O0kyDA98KEaQPzdyFKPGYMRKPV6BTZy/nxGTajSI/s6K/85u38VQCvYm+GE4xQHElRh3 wggzFRnZpZQRQJcU16/xmJZOSrDB7lhE+4Jv/RYHHtnwZXXFAJnf3g9rrJ3MoE3G5+ty QxSyiEXAA+5SromC8OXQpLUsfZiykwyCHCS6kLolcGbV+c7VW9+WEdZj4VgvMBeDo8me F/gQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=BpOqIeFQ; 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 w11si6762768plq.340.2019.03.22.05.26.31; Fri, 22 Mar 2019 05:26:48 -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=BpOqIeFQ; 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 S2403793AbfCVMY3 (ORCPT + 99 others); Fri, 22 Mar 2019 08:24:29 -0400 Received: from mail.kernel.org ([198.145.29.99]:36274 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2403783AbfCVMY0 (ORCPT ); Fri, 22 Mar 2019 08:24:26 -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 CB3AF2054F; Fri, 22 Mar 2019 12:24:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553257465; bh=yiGsCWcDQ9I3eio8snQoFDZfvkha7ftCoXgMr+sc1Y4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BpOqIeFQh15IG55pXOkhYZk5OydRV7YybkdhCRZDH4sSrNuh3Wx2b/J+r4Eng19lb PbdVy+0pzFiDjDev2wOtZWNgHZIcPDVdhQemFkYQJTWjTTI5UzPp4N2slR1tnkqhPv MiwqgZ1wZzt+/2/fqwJQqxttMxtbr6LR7NUVZK0E= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Sean Christopherson , Paolo Bonzini Subject: [PATCH 5.0 231/238] KVM: nVMX: Ignore limit checks on VMX instructions using flat segments Date: Fri, 22 Mar 2019 12:17:30 +0100 Message-Id: <20190322111312.006994000@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190322111258.383569278@linuxfoundation.org> References: <20190322111258.383569278@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 5.0-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/nested.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) --- a/arch/x86/kvm/vmx/nested.c +++ b/arch/x86/kvm/vmx/nested.c @@ -4102,10 +4102,16 @@ int get_vmx_mem_address(struct kvm_vcpu /* 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,