Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp3799992ybi; Mon, 29 Jul 2019 12:52:41 -0700 (PDT) X-Google-Smtp-Source: APXvYqz+/xVP+g2MPFvrpueAIXBvPWWSouJptVlH4AXCbef0rj88glx4gS+0TErjKOlS8DxWIsEP X-Received: by 2002:a65:5c4b:: with SMTP id v11mr63142209pgr.62.1564429961784; Mon, 29 Jul 2019 12:52:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564429961; cv=none; d=google.com; s=arc-20160816; b=wJRuZr/tMjlnaSmCpZO23iCL5Ugwi951YFbGZsOjEEJhZrdVF/nIlrkqSgGgwU5Uwi Jzkj7gMVnrPpODgXq3OUM552PyIRQ6M1AJybQTfyHIUIOX1LZ9WwyM8WsWcwCOb5XCRF zSBamvK/e4UfJqPARrdlHiwv62ZThjBkquaWu0vfmFcHNb/mk41RkTdvECMoQWyQA3cX 6FRSmJrAhEEMuD+tJhIW2E7CYPLn/OErDRUzx81ck9IOQeJn2Uw4gxztuPsN/P+ELpjI e9r5UOZoAl7pF8Uzfqkowg8A0mp4AgBCQnVoGZtlVCEOnAEYfBZH2DGaulOL5pHMEcNU w1ew== 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=GYjn2p2hoAD60tacaSsiG5BuZ3Mm8xlAW7saQs0m9Dg=; b=n4FMOG2yqo3T6T4p15Agga2sP5OY2d7JpjpJ+Z8RheOoAK1z7b4LAA0r/JHknCX3P0 NDFbHGszYQc7lALDSB+eFFLxjWCBx7y7uCi9fqc5OYcmWr9ywkNyUFHSByFPHpbd7vNe TtWXswL/hRttryR6G0fzPaJpnXa3GI9oMiTNqp/5AvZ95MLka96jsU2Es/VofnPRAuhx f76hhdMx41YHezT3HwsuE0hL1aJ9Rynbxzfjjk5Bbjf4uPv/mFaFDkhpka4DJPQ3wSrT px0zrnKvtQexSwo8iojN9oUTNod0Fa4rB9O/AHH21XLQ6ga1owVCdHULL0Lq6SnoYWaO EbjA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=HoFW1FMK; 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 w21si24069750plq.91.2019.07.29.12.52.27; Mon, 29 Jul 2019 12:52:41 -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=HoFW1FMK; 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 S2390485AbfG2TvP (ORCPT + 99 others); Mon, 29 Jul 2019 15:51:15 -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