Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp2672704imj; Mon, 11 Feb 2019 06:49:48 -0800 (PST) X-Google-Smtp-Source: AHgI3IYylj3oGGlVArOPs6eq9VkDl1xXM7xJwbyB0q7wrD98YfYMqyxByfh5bx+2wAo6k9jkOeth X-Received: by 2002:a63:3206:: with SMTP id y6mr33399739pgy.338.1549896588500; Mon, 11 Feb 2019 06:49:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549896588; cv=none; d=google.com; s=arc-20160816; b=oMqxV3YXvRXl3oT3QtCtM1zkoPxJ41OC971En/prmSvT2wKAmNdEvUT3VmRxsvudha CP2hffQDiF6shu2macBcxMb+3fg3Q2p4PTZN0yApzp9YgnHs966XsNF/bbW1kpEJinuT 69xWiYhYztl3pi1FgNQ257JbTCvFVyJo3Eu/njpYSlSQub2uyQS+ZwR90pHptTrfpXge mLPh4k6RK5I9LhBR2VrMnpiuhx3a3qnO19o+Y/p1RcimflS57U24Ihf8RDmedPK5PqJJ CAGpizGkPW4pcnFM80gC+DsmeNGOxz3zWjbHOyP2kgkhAqdSokI7c3F5Nw4/qEeCcudH Gikw== 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=vv5zESMKiDyjKev578eDvXM//brdyDYyKQJCugvfwHg=; b=K9iZlDYvW25u1M2hfcLE3hKJv/hkyfCTfbvP63D0V7F4Jq8KHOJPZXmIVzbM6ecXpX vgH17rQEcNVmK5VaDNA/UPROn4zOX63SBmBj6EsR/9414vOSkymZabwnHjucRRzTA1lW 9a1WLJAJRnDQG3b8c9yAwwX59AvOlQGh1X3gj1Yl5/cHE+kSa0RGBsA1jnsjMTZqUm82 3TCUkHCkFYB232EdfE9WBTU6vpmazV9kbQe+6l3UcpqxC7lHwvloldPC/BgXqJA6P/9C ymuyA7SeztI/ANaru1vBBBfJJv+7/qtmu6mj8k8evlHmKvi26CirMYVjTtONKdqDVV22 Ctaw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=vCVzpm4M; 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 w8si5046627ply.246.2019.02.11.06.49.32; Mon, 11 Feb 2019 06:49:48 -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=vCVzpm4M; 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 S2387707AbfBKOsf (ORCPT + 99 others); Mon, 11 Feb 2019 09:48:35 -0500 Received: from mail.kernel.org ([198.145.29.99]:33842 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387693AbfBKOsd (ORCPT ); Mon, 11 Feb 2019 09:48:33 -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 AC56720700; Mon, 11 Feb 2019 14:48:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1549896512; bh=AOVCN1lffdUJe4uXYA1onocQHaH73kjsgfac1L/ks+4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vCVzpm4MfRAlyfeBKwET+zNLSd/9PnhcPDh+EJrhrCn8DTiWDu365Y5ATI63cMycj MTLwu8g0iaHJ/vMmcgiA6yrwrzxpLuybiHDxpJ+WqP/F/Be/28HCHFxIxFkvzyCEql 3FqZJyDGqt4LT4qyzb5LS0N+ZQ3EpO9CDGURTxMc= 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.19 208/313] kvm: Change offset in kvm_write_guest_offset_cached to unsigned Date: Mon, 11 Feb 2019 15:18:08 +0100 Message-Id: <20190211141907.042567000@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190211141852.749630980@linuxfoundation.org> References: <20190211141852.749630980@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.19-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 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