Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2570937yba; Mon, 6 May 2019 08:09:35 -0700 (PDT) X-Google-Smtp-Source: APXvYqwbVFv2VMjLBpMoD91BnnsRkf++EqLM4fjk92o0FjZXl7mzNOkAV7ayCEyoFH+T6DIRedJd X-Received: by 2002:aa7:8e14:: with SMTP id c20mr34044169pfr.14.1557155375550; Mon, 06 May 2019 08:09:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557155375; cv=none; d=google.com; s=arc-20160816; b=iapIWJd1mXO5fnZxcJOzKWydk7tVdH/XJSKhLmip2G0tEhGdQli3AZT8YDIdCVgHsa INwUgXBzqOHoPXjRhYMcMcVq/U6a6+LkgDZtyBda3Sq4mhk9c9RZ+4BsXPoImB+X0yfu 9asThKBGSd7e8DBlcdghh2I/ATuvEe0xBMhlG7vn7rpGkHEpcCkKrxKiwoOPTNR4lGXH t9drZrTjYCqzlWtxKFb7nQNvQxh/oOCr59KJypkx61ZCARM0LoGb0x7tBfVy1pDuq0Qz kT5HoGCDlO1me/CZvOcWaH8n+YzMKt1eKmd76PVuOe3mrlr0hK4H9bHfnqLTbyTX7JAn OTiQ== 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=hI0WC3xSh8c9jYKZtAyxWmxASCdYbEHzmc0Kcf2Dris=; b=AplZOsXZpUwp2vJzjF+3ANdwK54Cxu7vCATpPUDzyZbbbJy5IeJs7c4Lbd4PxTOarJ PrjW/IZldWA+oKLgnyOoKKD65/+FDFoKgqzwSfo+j5Ttu0uEw0/TUcxVTzOJ98iTqMEg ggLsaqKL2wAP9vdmsumc9eSgiyR7kfO9d04IMqLSVU6kZwOM5sn3KZH2ccRCeLOG6c4p q2LHyup2xriVcn+RTMXvHy9C6fHPiyqZ8304BD+9Rh2js3v2/skHcu9Aki0UPLtncEOJ kjgb7hQwlUpdUVRcY7dLKkuiYmx+K43/jlVTVdh4CHsy4fy8Tls+/cJfpNpV98nibR1u GD/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Ei++EUW5; 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 15si15039607pfp.44.2019.05.06.08.09.17; Mon, 06 May 2019 08:09:35 -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=Ei++EUW5; 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 S1727238AbfEFOgo (ORCPT + 99 others); Mon, 6 May 2019 10:36:44 -0400 Received: from mail.kernel.org ([198.145.29.99]:57172 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727224AbfEFOgo (ORCPT ); Mon, 6 May 2019 10:36:44 -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 D2C2820B7C; Mon, 6 May 2019 14:36:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1557153403; bh=twzR8Q0I0GB4/XJdHRqv2wG4hGGwxgBwJ7gzfKh5E9c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ei++EUW5HPdS8dNVMtpYYXFSm/HwuBPtksRqPYMOy96tUy48BqRQ5wZ7/5NxInGvM BOM9IxTA7NRtMNljke9/f1QU6AECNwbT9aRQmSx7C4NsiWU3JXt/YZvFESYPGTJFCb JW5bwRj18EuJ7bvCtkilzbB6/EOCKXj7y/GXNnpg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Cfir Cohen , David Rientjes , Paolo Bonzini , "Sasha Levin (Microsoft)" Subject: [PATCH 5.0 074/122] KVM: SVM: prevent DBG_DECRYPT and DBG_ENCRYPT overflow Date: Mon, 6 May 2019 16:32:12 +0200 Message-Id: <20190506143101.546803164@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190506143054.670334917@linuxfoundation.org> References: <20190506143054.670334917@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 b86bc2858b389255cd44555ce4b1e427b2b770c0 ] This ensures that the address and length provided to DBG_DECRYPT and DBG_ENCRYPT do not cause an overflow. At the same time, pass the actual number of pages pinned in memory to sev_unpin_memory() as a cleanup. Reported-by: Cfir Cohen Signed-off-by: David Rientjes Signed-off-by: Paolo Bonzini Signed-off-by: Sasha Levin (Microsoft) --- arch/x86/kvm/svm.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c index e544cec812f9..2a07e43ee666 100644 --- a/arch/x86/kvm/svm.c +++ b/arch/x86/kvm/svm.c @@ -6815,7 +6815,8 @@ static int sev_dbg_crypt(struct kvm *kvm, struct kvm_sev_cmd *argp, bool dec) struct page **src_p, **dst_p; struct kvm_sev_dbg debug; unsigned long n; - int ret, size; + unsigned int size; + int ret; if (!sev_guest(kvm)) return -ENOTTY; @@ -6823,6 +6824,11 @@ static int sev_dbg_crypt(struct kvm *kvm, struct kvm_sev_cmd *argp, bool dec) if (copy_from_user(&debug, (void __user *)(uintptr_t)argp->data, sizeof(debug))) return -EFAULT; + if (!debug.len || debug.src_uaddr + debug.len < debug.src_uaddr) + return -EINVAL; + if (!debug.dst_uaddr) + return -EINVAL; + vaddr = debug.src_uaddr; size = debug.len; vaddr_end = vaddr + size; @@ -6873,8 +6879,8 @@ static int sev_dbg_crypt(struct kvm *kvm, struct kvm_sev_cmd *argp, bool dec) dst_vaddr, len, &argp->error); - sev_unpin_memory(kvm, src_p, 1); - sev_unpin_memory(kvm, dst_p, 1); + sev_unpin_memory(kvm, src_p, n); + sev_unpin_memory(kvm, dst_p, n); if (ret) goto err; -- 2.20.1