Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp4311053imu; Mon, 14 Jan 2019 20:10:47 -0800 (PST) X-Google-Smtp-Source: ALg8bN5NeVzhEEHzEvbmun8xx4yl96OiU2nY2tBCTflCmKnSPF3fAGhqIzklizLgxn13KV+k2gkp X-Received: by 2002:a17:902:50e3:: with SMTP id c32mr2052944plj.318.1547525447539; Mon, 14 Jan 2019 20:10:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547525447; cv=none; d=google.com; s=arc-20160816; b=GDusnaB54bj5b63+xuS/6SpdhF0hjVeG5Z4psc2do4L8pH+WJkJsZqYDiXfBP+154x 46Deynljgi1dthbN5DisVwmy/9on4Bm7mTxvqaFeVHn7KLFsuqoblCT3ALgZFlLdqsTR uab0fRP6tuALVUo3wnOohJ+kabr40P+eVlNGdwe941CwJ/uL54T3UwDXKmDqNnqCrllD eNeFBlmFkLkugNONDa5YGDhPwYs5A3u4i/1MQDssIYFU1SIh7WWG8y2gp6dFpvL3yTVP sMlqYE9iG2NO1/SnSC8IZ9Oa7m3DSL0QdKFtRWa6DaELlZnXXO7xzqjMNlGNgg2uNySG yVSA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=0cUgv3T/9wLodZNSLKrcZlsb+xBK6VKMYufFi7gqt+4=; b=p9uqpJIoxLlfUd7CQ7Wu/7+1cTEL+DQrKgfeuKNc0sZL4CquTPwgB79H44z9kS7ks3 bpHbqTRNP6dDPDtWFEHfxaX0zLIYtkIaxB8AjVoujJ56F0Y3jTfo4ujqbNHVNiJ0+Lox 7MWny2YZOmTVNSUDDb/NzxfWBxrza5TiNJQG1x7/NfTD+3kcEFIVbcjspiTyWIijs3Ac qEu0w3oFSvuxNXiq8U56aoQ0VxO6KhP5w0DQjvbBS9Yo3+ve46OQj7+EM6Tv2ENU1GAo 3J+gq+wM+ouzQekQ4rYBmP6/dMLeJxMrF7qCligyaAyBf81Ta1HUMZTAcgMxLnm4F0qV JxPw== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a6si2206246pgc.137.2019.01.14.20.10.31; Mon, 14 Jan 2019 20:10:47 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727932AbfAOCnG (ORCPT + 99 others); Mon, 14 Jan 2019 21:43:06 -0500 Received: from mga06.intel.com ([134.134.136.31]:22269 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727200AbfAOCnG (ORCPT ); Mon, 14 Jan 2019 21:43:06 -0500 X-Amp-Result: UNSCANNABLE X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 14 Jan 2019 18:43:05 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,480,1539673200"; d="scan'208";a="114715134" Received: from sjchrist-coffee.jf.intel.com (HELO linux.intel.com) ([10.54.74.154]) by fmsmga007.fm.intel.com with ESMTP; 14 Jan 2019 18:43:05 -0800 Date: Mon, 14 Jan 2019 18:43:04 -0800 From: Sean Christopherson To: Tom Roeder Cc: Paolo Bonzini , Radim =?utf-8?B?S3LEjW3DocWZ?= , Liran Alon , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H . Peter Anvin" , x86@kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, syzbot+ded1696f6b50b615b630@syzkaller.appspotmail.com Subject: Re: [RFC PATCH] kvm: x86/vmx: Use kzalloc for cached_vmcs12 Message-ID: <20190115024304.GD5141@linux.intel.com> References: <6f79d9be-fa76-3a06-2612-f44f3a18ece7@redhat.com> <20190114234728.49239-1-tmroeder@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190114234728.49239-1-tmroeder@google.com> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jan 14, 2019 at 03:47:28PM -0800, Tom Roeder wrote: > 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. Is the leak specific to vmx_set_nested_state(), e.g. can we zero out the memory if copy_from_user() fails instead of taking the hit on every allocation? > The email from Syszkaller led to a discussion about a patch in early > November on the KVM list (I've made this a reply to that thread), but > the current upstream kernel still has kmalloc instead of kzalloc for > cached_vmcs12 and cached_shadow_vmcs12. This RFC proposes changing to > kzalloc for defense in depth. > > Tested: rebuilt but not tested, since this is an RFC > > Reported-by: syzbot+ded1696f6b50b615b630@syzkaller.appspotmail.com > Signed-off-by: Tom Roeder > --- > arch/x86/kvm/vmx/nested.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c > index 2616bd2c7f2c7..ad46667042c7a 100644 > --- a/arch/x86/kvm/vmx/nested.c > +++ b/arch/x86/kvm/vmx/nested.c > @@ -4140,11 +4140,11 @@ static int enter_vmx_operation(struct kvm_vcpu *vcpu) > 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; Obviously not your code, but why do we allocate VMCS12_SIZE instead of sizeof(struct vmcs12)? I get why we require userspace to reserve the full 4k, but I don't understand why KVM needs to allocate the reserved bytes internally. > - 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; > > -- > 2.20.1.97.g81188d93c3-goog >