Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp4559002imu; Tue, 29 Jan 2019 03:47:34 -0800 (PST) X-Google-Smtp-Source: ALg8bN55fshbRRAmnGAWHNTUJcXfL9CZCJmIPDyhUUUMvVoFYnl+/RT3L/k8iTg1DFZ/nwDu9YyA X-Received: by 2002:a63:c141:: with SMTP id p1mr23411721pgi.424.1548762454169; Tue, 29 Jan 2019 03:47:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548762454; cv=none; d=google.com; s=arc-20160816; b=s0QP7bCdmLlph6DHqhxhBGBc1rCVM1aidPHn8D075GXO+RORJalydi9RpKPCjEFTuO EEukqbxlkEvLCgxTAbOTL6aalgZ0oS7/k2MLHPPA+01nJDkvXGDZlQSIcLc5C+N8heoQ lc9L1dYbs1uEcBq3kwyzi8VrHiVwndVAsnp0F0tkGQHy0BNbkOSIZbzfOLL7t0bFu0hJ aLzAsYh9gQODX89DZK8L0xJghhG1YtL2c84m4oXhAo6P5ORO3kKGXkdO1Z4/COw7MFC+ e0wUnciJf5JhMiWhrSsw/LKr+psswdpZps/bs2IhMNDijbYA7SAbe4IbbzNcbOa+XCH6 mWmA== 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=4dEQRdFTVkIIS43TCz5+UF3LwL4MJOgr1CqEAuH8OeA=; b=zrigc9R9+qhpk08a36qjdzfPRxmD6hvH509WaJICmfSbWFTLx7TfIo4kpSkp7uqpMV 7q/bpmFH5XrT9S0+kGZFQM2sVz5qW9d3EZlwq6Y2PmfA6IiM4KB0lHYL1TE47ZJtp3/+ ma/oUHuwNTdF4+LKz6YYDTW8LIkMIo4tgKbsj4jZfK68VfhnfghEiqv7JJy6cETJwKbr ETnis46zFvJ2ELhg79TNdq6NVWWcnElVXqIrxiOi1WZN7XVcnUsV+iQhIK2cdBkk6VyO KgsaPjhpW+Mf+x2RNlekA46cacN+B8EO4tFMHc5qMVFHnwwih9NWZKPJ8ZfTzsu1+wtN aQvA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=CPNExKts; 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 t19si36794648pgk.163.2019.01.29.03.47.18; Tue, 29 Jan 2019 03:47:34 -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=CPNExKts; 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 S1730781AbfA2Lpb (ORCPT + 99 others); Tue, 29 Jan 2019 06:45:31 -0500 Received: from mail.kernel.org ([198.145.29.99]:35912 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730771AbfA2Lp2 (ORCPT ); Tue, 29 Jan 2019 06:45:28 -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 2C570214DA; Tue, 29 Jan 2019 11:45:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1548762327; bh=fGDkwQGhGqzn1maz9TOU/oI8unXySvt4eWGmLqA7f1g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CPNExKtsyz1pGSUH8eagtQAeGoHx0gKd7RPkdWTwuLeJXTyMfns246ObxT3bI4oZ1 YooLJHAeTtVfydJxhfZs8SSeUSI4H0CwTgJKeczWEnjn9BdYF3f4vqyE31u5Jgb3Zm Zj0KeRWQuh/W0OWKCD/M6gTTy55h7YMitKv8ow/o= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+ded1696f6b50b615b630@syzkaller.appspotmail.com, Tom Roeder , Paolo Bonzini Subject: [PATCH 4.19 070/103] kvm: x86/vmx: Use kzalloc for cached_vmcs12 Date: Tue, 29 Jan 2019 12:35:47 +0100 Message-Id: <20190129113204.848390406@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190129113159.567154026@linuxfoundation.org> References: <20190129113159.567154026@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. ------------------ From: Tom Roeder commit 3a33d030daaa7c507e1c12d5adcf828248429593 upstream. This changes the allocation of cached_vmcs12 to use kzalloc instead of kmalloc. This removes the information leak found by Syzkaller (see Reported-by) in this case and prevents similar leaks from happening based on cached_vmcs12. It also changes vmx_get_nested_state to copy out the full 4k VMCS12_SIZE in copy_to_user rather than only the size of the struct. Tested: rebuilt against head, booted, and ran the syszkaller repro https://syzkaller.appspot.com/text?tag=ReproC&x=174efca3400000 without observing any problems. Reported-by: syzbot+ded1696f6b50b615b630@syzkaller.appspotmail.com Fixes: 8fcc4b5923af5de58b80b53a069453b135693304 Cc: stable@vger.kernel.org Signed-off-by: Tom Roeder Signed-off-by: Paolo Bonzini Signed-off-by: Greg Kroah-Hartman --- arch/x86/kvm/vmx.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c @@ -8290,11 +8290,11 @@ static int enter_vmx_operation(struct kv if (r < 0) goto out_vmcs02; - vmx->nested.cached_vmcs12 = kmalloc(VMCS12_SIZE, GFP_KERNEL); + vmx->nested.cached_vmcs12 = kzalloc(VMCS12_SIZE, GFP_KERNEL); if (!vmx->nested.cached_vmcs12) goto out_cached_vmcs12; - vmx->nested.cached_shadow_vmcs12 = kmalloc(VMCS12_SIZE, GFP_KERNEL); + vmx->nested.cached_shadow_vmcs12 = kzalloc(VMCS12_SIZE, GFP_KERNEL); if (!vmx->nested.cached_shadow_vmcs12) goto out_cached_shadow_vmcs12; @@ -13984,13 +13984,17 @@ static int vmx_get_nested_state(struct k else if (enable_shadow_vmcs && !vmx->nested.sync_shadow_vmcs) copy_shadow_to_vmcs12(vmx); - if (copy_to_user(user_kvm_nested_state->data, vmcs12, sizeof(*vmcs12))) + /* + * Copy over the full allocated size of vmcs12 rather than just the size + * of the struct. + */ + if (copy_to_user(user_kvm_nested_state->data, vmcs12, VMCS12_SIZE)) return -EFAULT; if (nested_cpu_has_shadow_vmcs(vmcs12) && vmcs12->vmcs_link_pointer != -1ull) { if (copy_to_user(user_kvm_nested_state->data + VMCS12_SIZE, - get_shadow_vmcs12(vcpu), sizeof(*vmcs12))) + get_shadow_vmcs12(vcpu), VMCS12_SIZE)) return -EFAULT; }