Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3635517imu; Mon, 28 Jan 2019 08:11:55 -0800 (PST) X-Google-Smtp-Source: ALg8bN72yFWTQNU48vRwThwo1pv8v0ARrBqCUYa9x3HyZPe88ItjA4+T2KbUBgcUc8A0yl5YzdpC X-Received: by 2002:a63:2586:: with SMTP id l128mr20700129pgl.104.1548691915769; Mon, 28 Jan 2019 08:11:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548691915; cv=none; d=google.com; s=arc-20160816; b=HaoxGY+F27yf+D9orQpnYkIJE68FDrnREkJyp7eYs5ElK5UMz6JccQi7FVtaf+zRfv StqNQnn6mV1V9OuqRdtatydo6vooSdxyKlrwJaprGJhrncHvajFbTdGfiylPp6n9z6kv DaiwGfHUzvL/+WldYVZBC+hyP1B68AJAWb7xdAc7C/mjoZReqhoMpC7rux7hmn95jgHB 0wsWekSUDqG//+kIhswyk7HKEVYUAkU/ToultepZFWMgn6DMjbjW5zluvh4IJ3EdeiG/ B7cgzHB0ugaj6krH6wKMUycba42n/Wv55oKczppET2F+6phOsFP/B5/9sl79zkxudWm4 0L/A== 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=sEIu4fUQoABrvwl/pgXBFPTr9G/YtTTsaxyOFtXO4GM=; b=EKvu5ZR/fDeVL0OBV2eUBdmwc4W37JJ+7XRGoTDyFw/D3cDeByvnMASCi4HbLQxxh/ +G/CxAzp18wIHadg63vx8xkjhiiU5QKE2bq/qJBJsD1PyjBOBbaF7+bhA4pNEp0pZcSN jZxtYi+zrPHAU09GitAUl054Fvi1QxYSp5qDWxkOp6dkXqfAdHxHl4cA+E6dDxkDIjC7 QLIUKNdkfptNXPtHmy4fjnBh3hAdJlObAczjAFE+zoxfBGsLROADPfU4+45T9kbDO2Z/ HtOV+vhmlbFsMdsf9To8nk7EqJi3qbn9cYaY+pNCTyBqOyzLKVvk3ZmaVsRPgOY7N7Bl SK7Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=nJHNQ7fT; 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 t65si33555383pfd.246.2019.01.28.08.11.40; Mon, 28 Jan 2019 08:11:55 -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=nJHNQ7fT; 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 S1732221AbfA1QJy (ORCPT + 99 others); Mon, 28 Jan 2019 11:09:54 -0500 Received: from mail.kernel.org ([198.145.29.99]:35036 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732669AbfA1QJt (ORCPT ); Mon, 28 Jan 2019 11:09:49 -0500 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 DD97E2147A; Mon, 28 Jan 2019 16:09:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1548691789; bh=D79Vhkw1wT6LAm8nJvuZhuAU68C3l222FxBIx3LGRuY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nJHNQ7fTgAwLe2ZtbslMy4cRCDAwu98RszoDIKu5ydd+HweXeFqJ/FcKg32JjjYd7 lEvysPIBZswVZfEUJ8wlhKYxeSRJdEjvCG1EBIiHJWM1/QKxY4b0rUQVNTSMR4YTHX rnY0KF7rrKO6ELVH+LjlPVETvP+whhG5FQuaO1Co= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Jim Mattson , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= , Sasha Levin , kvm@vger.kernel.org Subject: [PATCH AUTOSEL 4.19 217/258] kvm: Change offset in kvm_write_guest_offset_cached to unsigned Date: Mon, 28 Jan 2019 10:58:43 -0500 Message-Id: <20190128155924.51521-217-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190128155924.51521-1-sashal@kernel.org> References: <20190128155924.51521-1-sashal@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 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: Jim Mattson [ 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 f986e31fa68c..0ddf81dea6fd 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -1959,7 +1959,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