Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp2719756imj; Mon, 11 Feb 2019 07:28:44 -0800 (PST) X-Google-Smtp-Source: AHgI3IYa4Zg6kzn4sQ/MKiMBg48KVBKvrA3JbvWGuNAwlb9zZ1P7DkovX7QRdn8m03TPHePKwiDt X-Received: by 2002:a62:ea09:: with SMTP id t9mr38810197pfh.228.1549898924529; Mon, 11 Feb 2019 07:28:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549898924; cv=none; d=google.com; s=arc-20160816; b=ty9csumUWtqt7YzK8+MrulE+4IxKLHgqcYIRjb7dNPCppLmpigIX9Y6yrlnaSRy5gx AU3UJRvw+yK1Ke2kbmshZT7hxt3Hd3kWu9TOJ1ayvJpFnP5Xmhw0QHPNKXgqT1tJ1Cm1 tT/RNZIB7bqvV6u8dvWxIR3srd3ysyIW+LzfTYnO2ja28Zx7LsjjQc4BZ2tE1hUg8ye0 uFeWVJ2HUbSU2X+VA/RbqNDzuNtMlWKwgs4KhfgB8HDQLZ1Lzfgr16SJpdScsBqCjGgk cWdnBOX1z88eoF+bvb+5mFPxLh2OcKygKMpwcR3TyXCPcNMU7531fIcxTLG8VmW40DlT RmKQ== 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=jS8sEMpQyBc6Vu4fV5yk03Nt323TBBvz3N73kfCZ+DU=; b=LlckBzuwZ40jurU7r+dsN8Bkta+IXFjCkC97tQzcQay68KVpsPSFyxGpNyIJ0skag9 0vj/HpsazGHKuV7HkH7SsGdNw9UIzwPga7yUdZIPGQ7ARBBtunNNUiBv9mi9OgWqPZiP 1XA51HwfPtz0zQduzH+016bdNuywEdDQex805IGtvTjFqpJxdc2sBWF4eiNMlDVrqYQS w5kPfD8mOYKQuUUqBnMg30iTQd2+oULIcZVlso8ErLqIyE4DpE9V8UgDHK4qZifi82Fb rqR2bDP5ng/h4sQ+XEtsBLNsCNFJXCgdjg5CAxo10V38s/H9/SILTcV0AHupO6OnqmGr 359Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=nVIW56Va; 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 g8si9317165pgb.128.2019.02.11.07.28.28; Mon, 11 Feb 2019 07:28: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=nVIW56Va; 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 S2389536AbfBKPAe (ORCPT + 99 others); Mon, 11 Feb 2019 10:00:34 -0500 Received: from mail.kernel.org ([198.145.29.99]:48456 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390020AbfBKPAb (ORCPT ); Mon, 11 Feb 2019 10:00:31 -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 C831B222A4; Mon, 11 Feb 2019 15:00:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1549897230; bh=BdBLokrm1uZVI9yYwoDAsG7ugzIaRL2iKcZQfnQzsZ0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nVIW56VaFPAHVDTPIW9ztn/zauunxV/DwzcuwjMJdyWQNR93OMvfY5MLNvE+zBKO2 p8MP/SNxKF4vK3EF16GKaxu/uLjMiJp4HTt5HjciC3gaqCDhLhbwJ0MTfcHyxXoc+o Og4rm+vhK2qvnMxCRyULADU8+ghco9bkguYlQkJM= 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.14 134/205] kvm: Change offset in kvm_write_guest_offset_cached to unsigned Date: Mon, 11 Feb 2019 15:18:52 +0100 Message-Id: <20190211141837.170261228@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190211141827.214852402@linuxfoundation.org> References: <20190211141827.214852402@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.14-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 b6962ae6237e..4f7f19c1dc0a 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -685,7 +685,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 4f35f0dfe681..bbc34e87d88f 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -1962,7 +1962,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