From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7E0DDC76186 for ; Mon, 29 Jul 2019 19:51:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 47AC021773 for ; Mon, 29 Jul 2019 19:51:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1564429877; bh=NsoPu58zxg5mOz4AdudLBqmyOCfw0J7PXrOe8GjMLfc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=BTnDx9RhNsHqn6Xxe6eFGDh3DNnda4YIKLbqGFIHxjKcv4kZQO1cADJw/2y0qgQO5 LV8oqPGRoh9h5wW3ociRC160NurYsAy4ZXsrmcm0hJbsCcLJt4suaY3lLy/KCKXgvW sizjjED5e8gCUihCe7ye4jP4QZYfMZoXvwYezc/g= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390520AbfG2TvQ (ORCPT ); Mon, 29 Jul 2019 15:51:16 -0400 Received: from mail.kernel.org ([198.145.29.99]:42366 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390746AbfG2TvK (ORCPT ); Mon, 29 Jul 2019 15:51:10 -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 EC3B2205F4; Mon, 29 Jul 2019 19:51:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1564429869; bh=NsoPu58zxg5mOz4AdudLBqmyOCfw0J7PXrOe8GjMLfc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HoFW1FMK8O/n8XmBBDTtgsEGvSPmjD+azA+sI3DIuorwN6LCsEpC5x7hMXK/NQchH V9iT4mE4kEs7IFxt28qzyHOStktu1hIxbZ2M5DDGTMRm9LA5q3+l0FYUn/4vc1QdZB MP+gaCAMgG20RExmJyQj/XV77h7ruw4hW3wQcDTM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Eugene Korenevsky , Paolo Bonzini , Sasha Levin Subject: [PATCH 5.2 072/215] kvm: vmx: fix limit checking in get_vmx_mem_address() Date: Mon, 29 Jul 2019 21:21:08 +0200 Message-Id: <20190729190752.688030281@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190729190739.971253303@linuxfoundation.org> References: <20190729190739.971253303@linuxfoundation.org> User-Agent: quilt/0.66 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 [ 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 b101127e13b6..543d7d82479b 100644 --- a/arch/x86/kvm/vmx/nested.c +++ b/arch/x86/kvm/vmx/nested.c @@ -4120,7 +4120,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