Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp3133556ybi; Thu, 18 Jul 2019 21:41:13 -0700 (PDT) X-Google-Smtp-Source: APXvYqyixKZQLQErv4rACoLh3rrrf3YUYAa/CJp0Nv0FbA+qzla0pxnbHESe5MJ9eLxujk2Q5htQ X-Received: by 2002:a17:902:2bcb:: with SMTP id l69mr54864682plb.155.1563511273007; Thu, 18 Jul 2019 21:41:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563511272; cv=none; d=google.com; s=arc-20160816; b=qoqhI1435PrZeJxamEDF3Gn0vuGdf5gUEk5pWxcLJCExebgPCkX6swDaJxVZVSG730 v0jUEZFzuBVxTGhYF/8CcOrGOb27R/Zb/a2hAzD/V9LWwYnj4OJsEnzMHDxABvsXqKBQ 8r958jYMVdTXZ/tN2P2HKaNeMiwOgKbCqMSF5JcMC7L88h561EZa4KCHbjRTWJoSqgYV lBfbCPLJbPxpv/NkHg15LV3Rg+DVJe/xFw71xbOUmqD/5RZFv3KLkqkYE0e5n35nvMcU mSmSb1hexYH+tufomH9GkeG6fXpqzHfPZYJmIXHJWHKGRjXGLl0Ij8URTqeAS4X9XpOe guPA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Vixgpld2ke2x6m2xttPRrQgb8AK0t/ZB6xGZCoTx8J8=; b=PY0YFkTt9MOUFbf2BheoQLnka28a6cDqM5iUHnx/d1h2Kvx+QwNcTMt0hPI3WSrWS4 RP40dEgXe/GLwk8M5S4Rr7LUyTv8YfTOuCU/JzvQFB2nRRj3Swb5Xy/+XLRG7VxShrFA 1/pli007WEzbVnoKYYBIIF9jOAn1P/KbztM/OmlBOi49ZbxKbiR4PsXwPjX6ZE35Ey+1 EjffwhPAKnJMobxQuFh7oZZpW9PdddqP/tAeRvvzj2Gxm82IjZrZW8brWwqf79FQkC7N Hx/WAO2kQ3cn12QDW4qKP+w3I/+XYHYRBGxuIoJqc+aR9jzZe/2x//w3FkjlmTVtHa3D 5o5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Sgias6CZ; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d7si90823plr.18.2019.07.18.21.40.57; Thu, 18 Jul 2019 21:41:12 -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=Sgias6CZ; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732538AbfGSEik (ORCPT + 99 others); Fri, 19 Jul 2019 00:38:40 -0400 Received: from mail.kernel.org ([198.145.29.99]:58702 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728556AbfGSD7N (ORCPT ); Thu, 18 Jul 2019 23:59:13 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id DFACD21855; Fri, 19 Jul 2019 03:59:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1563508752; bh=fAxcJtvc6D/lb9qHE8rxAU2u7+yhuYmnb5gHLxvVhm4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Sgias6CZr43YjcFSjkzAkV8UBpAovwYzzcapTKYdrwK62wRvR6SuMIPffs5XyjIiV MNtvP+woe0+1aXuYqY4OlvZgqX1//eZzb49tK44i6bX65qWDzIYiKE7agTkV9HXVIh oAZTH32G1hHElKVRBc2AaPV42aS6eJOtNfFovZfA= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Eugene Korenevsky , Paolo Bonzini , Sasha Levin , kvm@vger.kernel.org Subject: [PATCH AUTOSEL 5.2 071/171] kvm: vmx: fix limit checking in get_vmx_mem_address() Date: Thu, 18 Jul 2019 23:55:02 -0400 Message-Id: <20190719035643.14300-71-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190719035643.14300-1-sashal@kernel.org> References: <20190719035643.14300-1-sashal@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Eugene Korenevsky [ Upstream commit c1a9acbc5295e278d788e9f7510f543bc9864fa2 ] Intel SDM vol. 3, 5.3: The processor causes a general-protection exception (or, if the segment is SS, a stack-fault exception) any time an attempt is made to access the following addresses in a segment: - A byte at an offset greater than the effective limit - A word at an offset greater than the (effective-limit – 1) - A doubleword at an offset greater than the (effective-limit – 3) - A quadword at an offset greater than the (effective-limit – 7) Therefore, the generic limit checking error condition must be exn = (off > limit + 1 - access_len) = (off + access_len - 1 > limit) but not exn = (off + access_len > limit) as for now. Also avoid integer overflow of `off` at 32-bit KVM by casting it to u64. Note: access length is currently sizeof(u64) which is incorrect. This will be fixed in the subsequent patch. Signed-off-by: Eugene Korenevsky Signed-off-by: Paolo Bonzini Signed-off-by: Sasha Levin --- arch/x86/kvm/vmx/nested.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c index 46af3a5e9209..7958189ee702 100644 --- a/arch/x86/kvm/vmx/nested.c +++ b/arch/x86/kvm/vmx/nested.c @@ -4115,7 +4115,7 @@ int get_vmx_mem_address(struct kvm_vcpu *vcpu, unsigned long exit_qualification, */ if (!(s.base == 0 && s.limit == 0xffffffff && ((s.type & 8) || !(s.type & 4)))) - exn = exn || (off + sizeof(u64) > s.limit); + exn = exn || ((u64)off + sizeof(u64) - 1 > s.limit); } if (exn) { kvm_queue_exception_e(vcpu, -- 2.20.1