Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp2750870imj; Mon, 11 Feb 2019 07:57:44 -0800 (PST) X-Google-Smtp-Source: AHgI3IZ3qBZMWav/4PmD94bHw9lmWoHQl5IrtkQ5bGtrM5QGlixh+TM3VRB3zgSfOEdi/Gt+3/G2 X-Received: by 2002:a63:5207:: with SMTP id g7mr34418041pgb.253.1549900664292; Mon, 11 Feb 2019 07:57:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549900664; cv=none; d=google.com; s=arc-20160816; b=MisXamvoHLiFrQcm4RQCrmQaDhdDW8PBIUTHpMKJd2GuMp7LZmTKbY5svI0BVyIpJI lYOOmI8scsj7aBntv8IAa355aA+QEpBrN+ITgoMu737KgPPZj1Fo8cGVKyXKjWfQP5AO EMFo1n6K2rNYrsn37Ndbp0NMTdVSsMcE0nbppreqOmG763b0zqITqd4tTH2o3dPYcyM8 7oJz7P7ttatFH2K/obd8LsYZTaoZpEUNwI88LPWOPQXtJCm+T9+VInZsXRJlSJ9YzAch hKYi02Nt3KfDROcyj9CM8gR9/Uz8pngWazOe7vf4hAjjMSCey8IFo18rhPc0YbyQSVbd HesQ== 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=N0UVx0Ppi/JPwQ5C15HKATdu0v1aDohKgbvh7dLBiU0=; b=NYhkba5FKPCDwzDL/LUv+WlkZNL3lxyV8lKQnkCuUbNEpSozCNOqVo/ytlYKkbaiZf eiM05za3BG+/P7VwFXTFRZhOqFl+6ivxjArKx5y9zsGx3nh16vqt7P5SehSI+aDftZbM C/iWf0WuItDKIcb0lhSmngC5XRBVQ02YEcezjckR5y0OpAXwtfi1+RQ0ii+fzemd6MWH bsQK0zHpXNaHGK2SXxQzHwcJoeg93timGNNEP3Ooe6efLfy5kUyKec1qAoMy4y8aS0UA 1gQZAOCYjkQBIkCiyi7rbBZ+rq6U2bIpYAx1KilZ+DXuehal40R/CDLCJh3/jKvs/rLj PMVA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=cJ06OSFQ; 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 v7si9211305pgs.304.2019.02.11.07.57.28; Mon, 11 Feb 2019 07:57:44 -0800 (PST) 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=cJ06OSFQ; 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 S1730818AbfBKOeT (ORCPT + 99 others); Mon, 11 Feb 2019 09:34:19 -0500 Received: from mail.kernel.org ([198.145.29.99]:42460 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730806AbfBKOeR (ORCPT ); Mon, 11 Feb 2019 09:34:17 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.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 A48EF204EC; Mon, 11 Feb 2019 14:34:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1549895656; bh=kFi2/JZpQSaYq/fAbyFCu0cZqUCHqBMqtoY0V0ukxpM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cJ06OSFQtKGzZ2bW9qNjOwrv865xeFqjzAC7RgqNmajnx8V+c4GdhddPUSuqdtXVC 7mGpetbfwFonSvOLOy5RF4HqYOtwzOvbogIxYqmTGnqy+GFfods31ekCt3ouyZMva0 zn5EmjoCrP9h2GiPSA22K+70Gc+C7sR88JdTz+g0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Cfir Cohen , Jim Mattson , Peter Shier , Krish Sadhukhan , Sean Christopherson , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= , Sasha Levin Subject: [PATCH 4.20 248/352] kvm: Change offset in kvm_write_guest_offset_cached to unsigned Date: Mon, 11 Feb 2019 15:17:55 +0100 Message-Id: <20190211141902.901779005@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190211141846.543045703@linuxfoundation.org> References: <20190211141846.543045703@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.20-stable review patch. If anyone has any objections, please let me know. ------------------ [ Upstream commit 7a86dab8cf2f0fdf508f3555dddfc236623bff60 ] Since the offset is added directly to the hva from the gfn_to_hva_cache, a negative offset could result in an out of bounds write. The existing BUG_ON only checks for addresses beyond the end of the gfn_to_hva_cache, not for addresses before the start of the gfn_to_hva_cache. Note that all current call sites have non-negative offsets. Fixes: 4ec6e8636256 ("kvm: Introduce kvm_write_guest_offset_cached()") Reported-by: Cfir Cohen Signed-off-by: Jim Mattson Reviewed-by: Cfir Cohen Reviewed-by: Peter Shier Reviewed-by: Krish Sadhukhan Reviewed-by: Sean Christopherson Signed-off-by: Radim Krčmář Signed-off-by: Sasha Levin --- include/linux/kvm_host.h | 3 ++- virt/kvm/kvm_main.c | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index c926698040e0..a03d5e264e5e 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -694,7 +694,8 @@ int kvm_write_guest(struct kvm *kvm, gpa_t gpa, const void *data, int kvm_write_guest_cached(struct kvm *kvm, struct gfn_to_hva_cache *ghc, void *data, unsigned long len); int kvm_write_guest_offset_cached(struct kvm *kvm, struct gfn_to_hva_cache *ghc, - void *data, int offset, unsigned long len); + void *data, unsigned int offset, + unsigned long len); int kvm_gfn_to_hva_cache_init(struct kvm *kvm, struct gfn_to_hva_cache *ghc, gpa_t gpa, unsigned long len); int kvm_clear_guest_page(struct kvm *kvm, gfn_t gfn, int offset, int len); diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 2679e476b6c3..065ee2fb4034 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -1965,7 +1965,8 @@ int kvm_gfn_to_hva_cache_init(struct kvm *kvm, struct gfn_to_hva_cache *ghc, EXPORT_SYMBOL_GPL(kvm_gfn_to_hva_cache_init); int kvm_write_guest_offset_cached(struct kvm *kvm, struct gfn_to_hva_cache *ghc, - void *data, int offset, unsigned long len) + void *data, unsigned int offset, + unsigned long len) { struct kvm_memslots *slots = kvm_memslots(kvm); int r; -- 2.19.1