From patchwork Thu Aug 1 10:22:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chao Gao X-Patchwork-Id: 11070447 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 BE597112C for ; Thu, 1 Aug 2019 10:20:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AF06C2854F for ; Thu, 1 Aug 2019 10:20:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 977B428553; Thu, 1 Aug 2019 10:20:29 +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 9D11222B27 for ; Thu, 1 Aug 2019 10:20:22 +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 1ht8Al-0001hW-IA; Thu, 01 Aug 2019 10:18:59 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ht8Ak-0001h3-7v for xen-devel@lists.xenproject.org; Thu, 01 Aug 2019 10:18:58 +0000 X-Inumbo-ID: c51c9332-b445-11e9-8980-bc764e045a96 Received: from mga17.intel.com (unknown [192.55.52.151]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id c51c9332-b445-11e9-8980-bc764e045a96; Thu, 01 Aug 2019 10:18:56 +0000 (UTC) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 01 Aug 2019 03:18:56 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,333,1559545200"; d="scan'208";a="175207884" Received: from gao-cwp.sh.intel.com ([10.239.159.26]) by orsmga003.jf.intel.com with ESMTP; 01 Aug 2019 03:18:54 -0700 From: Chao Gao To: xen-devel@lists.xenproject.org Date: Thu, 1 Aug 2019 18:22:39 +0800 Message-Id: <1564654971-31328-5-git-send-email-chao.gao@intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1564654971-31328-1-git-send-email-chao.gao@intel.com> References: <1564654971-31328-1-git-send-email-chao.gao@intel.com> Subject: [Xen-devel] [PATCH v8 04/16] 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 v8: - new - it is found by reading code. No test is done. --- xen/arch/x86/microcode_amd.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/xen/arch/x86/microcode_amd.c b/xen/arch/x86/microcode_amd.c index 7a854c0..afca51f 100644 --- a/xen/arch/x86/microcode_amd.c +++ b/xen/arch/x86/microcode_amd.c @@ -433,6 +433,9 @@ static int cpu_request_microcode(unsigned int cpu, const void *buf, goto out; } + mc_amd->equiv_cpu_table_size = 0; + mc_amd->equiv_cpu_table = NULL; + /* * Multiple container file support: * 1. check if this container file has equiv_cpu_id match @@ -479,6 +482,8 @@ static int cpu_request_microcode(unsigned int cpu, const void *buf, if ( error ) { + if ( mc_amd->equiv_cpu_table_size ) + xfree(mc_amd->equiv_cpu_table); xfree(mc_amd); goto out; } @@ -549,11 +554,14 @@ 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); + + if ( mc_old->mpb_size ) + xfree(mc_old->mpb); + xfree(mc_old->equiv_cpu_table); + xfree(mc_old); out: #if CONFIG_HVM