From patchwork Fri Jan 23 14:32:32 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Dan Carpenter X-Patchwork-Id: 5694471 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 3A9AFC058D for ; Fri, 23 Jan 2015 14:32:15 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 770CC202B8 for ; Fri, 23 Jan 2015 14:32:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4D20120268 for ; Fri, 23 Jan 2015 14:32:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751464AbbAWOcJ (ORCPT ); Fri, 23 Jan 2015 09:32:09 -0500 Received: from userp1040.oracle.com ([156.151.31.81]:18631 "EHLO userp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750930AbbAWOcH (ORCPT ); Fri, 23 Jan 2015 09:32:07 -0500 Received: from acsinet21.oracle.com (acsinet21.oracle.com [141.146.126.237]) by userp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id t0NEVsWY014385 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 23 Jan 2015 14:31:55 GMT Received: from aserz7021.oracle.com (aserz7021.oracle.com [141.146.126.230]) by acsinet21.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id t0NEVra2012966 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL); Fri, 23 Jan 2015 14:31:54 GMT Received: from abhmp0012.oracle.com (abhmp0012.oracle.com [141.146.116.18]) by aserz7021.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id t0NEVrdZ012956; Fri, 23 Jan 2015 14:31:53 GMT Received: from mwanda (/154.0.139.178) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 23 Jan 2015 06:31:52 -0800 Date: Fri, 23 Jan 2015 17:32:32 +0300 From: Dan Carpenter To: Gleb Natapov Cc: Paolo Bonzini , Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , x86@kernel.org, kvm@vger.kernel.org, kernel-janitors@vger.kernel.org Subject: [patch] KVM: always initialize *pdata in get_msr() Message-ID: <20150123143232.GA4298@mwanda> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-Source-IP: acsinet21.oracle.com [141.146.126.237] Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Smatch complains that there are some paths where we use uninitialized data in em_sysenter(). arch/x86/kvm/emulate.c:2410 em_sysenter() error: potentially using uninitialized 'msr_data'. A couple examples of paths which don't set "pdata" are found in get_msr_hyperv() and kvm_x2apic_msr_read(). I looked at this code and it seems like setting it to zero is a common default behaviour. Signed-off-by: Dan Carpenter Reviewed-by: Radim Kr?má? --- From static analysis only, not from real life. -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c index a17d848..f0e30d2 100644 --- a/arch/x86/kvm/svm.c +++ b/arch/x86/kvm/svm.c @@ -3063,6 +3063,8 @@ static int svm_get_msr(struct kvm_vcpu *vcpu, unsigned ecx, u64 *data) { struct vcpu_svm *svm = to_svm(vcpu); + *data = 0; + switch (ecx) { case MSR_IA32_TSC: { *data = svm->vmcb->control.tsc_offset + diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c index ce35071..3bdb9ca 100644 --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c @@ -2544,6 +2544,7 @@ static int vmx_get_msr(struct kvm_vcpu *vcpu, u32 msr_index, u64 *pdata) printk(KERN_ERR "BUG: get_msr called with NULL pdata\n"); return -EINVAL; } + *pdata = 0; switch (msr_index) { #ifdef CONFIG_X86_64