From patchwork Mon Aug 19 01:25:15 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chao Gao X-Patchwork-Id: 11100095 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 99F2114F7 for ; Mon, 19 Aug 2019 01:22:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8242D28587 for ; Mon, 19 Aug 2019 01:22:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 71EA728590; Mon, 19 Aug 2019 01:22:57 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 10FF028587 for ; Mon, 19 Aug 2019 01:22:56 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hzWMX-00013j-6Q; Mon, 19 Aug 2019 01:21:33 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hzWMW-00013W-4K for xen-devel@lists.xenproject.org; Mon, 19 Aug 2019 01:21:32 +0000 X-Inumbo-ID: ad189712-c21f-11e9-8be3-12813bfff9fa Received: from mga03.intel.com (unknown [134.134.136.65]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id ad189712-c21f-11e9-8be3-12813bfff9fa; Mon, 19 Aug 2019 01:21:31 +0000 (UTC) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 18 Aug 2019 18:21:31 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,403,1559545200"; d="scan'208";a="261683837" Received: from gao-cwp.sh.intel.com ([10.239.159.26]) by orsmga001.jf.intel.com with ESMTP; 18 Aug 2019 18:21:29 -0700 From: Chao Gao To: xen-devel@lists.xenproject.org Date: Mon, 19 Aug 2019 09:25:15 +0800 Message-Id: <1566177928-19114-3-git-send-email-chao.gao@intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1566177928-19114-1-git-send-email-chao.gao@intel.com> References: <1566177928-19114-1-git-send-email-chao.gao@intel.com> Subject: [Xen-devel] [PATCH v9 02/15] microcode/amd: fix memory leak X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Ashok Raj , Wei Liu , Andrew Cooper , Jan Beulich , Chao Gao , =?utf-8?q?Roger_Pau_Monn=C3=A9?= MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP Two buffers, '->equiv_cpu_table' and '->mpb', inside 'mc_amd' might be allocated and in the error-handing path they are not freed properly. Signed-off-by: Chao Gao Reviewed-by: Jan Beulich --- Changes in v9: - use xzalloc() to get rid of explicitly initializing some fields to NULL/0. changes in v8: - new - it is found by reading code. No test is done. --- xen/arch/x86/microcode_amd.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/xen/arch/x86/microcode_amd.c b/xen/arch/x86/microcode_amd.c index 7a854c0..3069784 100644 --- a/xen/arch/x86/microcode_amd.c +++ b/xen/arch/x86/microcode_amd.c @@ -425,7 +425,7 @@ static int cpu_request_microcode(unsigned int cpu, const void *buf, goto out; } - mc_amd = xmalloc(struct microcode_amd); + mc_amd = xzalloc(struct microcode_amd); if ( !mc_amd ) { printk(KERN_ERR "microcode: Cannot allocate memory for microcode patch\n"); @@ -479,6 +479,7 @@ static int cpu_request_microcode(unsigned int cpu, const void *buf, if ( error ) { + xfree(mc_amd->equiv_cpu_table); xfree(mc_amd); goto out; } @@ -491,8 +492,6 @@ static int cpu_request_microcode(unsigned int cpu, const void *buf, * It's possible the data file has multiple matching ucode, * lets keep searching till the latest version */ - mc_amd->mpb = NULL; - mc_amd->mpb_size = 0; last_offset = offset; while ( (error = get_ucode_from_buffer_amd(mc_amd, buf, bufsize, &offset)) == 0 ) @@ -549,11 +548,13 @@ static int cpu_request_microcode(unsigned int cpu, const void *buf, if ( save_error ) { - xfree(mc_amd); uci->mc.mc_amd = mc_old; + mc_old = mc_amd; } - else - xfree(mc_old); + + xfree(mc_old->mpb); + xfree(mc_old->equiv_cpu_table); + xfree(mc_old); out: #if CONFIG_HVM