Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp278911imm; Fri, 1 Jun 2018 00:13:59 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIL7MbYSH3Lqo1h13qSXe4Qn8pOAegfu5lZaSz/vR75TO99Iy7kA8x36jN0HbBLHvpEnSZp X-Received: by 2002:a63:9b19:: with SMTP id r25-v6mr7831830pgd.197.1527837239837; Fri, 01 Jun 2018 00:13:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527837239; cv=none; d=google.com; s=arc-20160816; b=YwW/1PgfyC598a1DtbUjxkEoqDIO/+PtlARcHgoVUasTJBXjDr/XK6zzO73gy6Qnto iyfWyvi3lvF0RVNmvnHeJI5r6ilRqInsXc4c1qx8ddNTXfHOCzQDACIRYD8rdkj1KqP8 rhXrBjohDkgLTdvufkd7GcD4D35PneB/i2s21LOZae35dii6q9R8I/5n6fpshlo2/PDY xRyonBgabWUC/wGcUgT32IRhfnps0ZMhGYSA10V9CBJP2S0RALxc/RP6uwf01aBCHZQJ o5IKWnlPpWr7nZmicwH4SnTcdeNsWLx90ZqF1NJZFQztEpsKGAmyEXVxIsyEcUP2ncSd LB2w== 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:arc-authentication-results; bh=NjF/cpOrQOwuPbIR/LQIWBKzNldf9lLDmpOQWtI+Qyo=; b=R7B7K2yOve4X+2dFqJ0po+h7mst+TjToH8U8B8uyhtFifipfsxOWS7buzJ8D8a785j caLxzvdTzxn6mC9aBJYYKm/rC05De0PzlJxt5O92Y+LYfo9IcOhXDxHDIJnZsjXDf4Eq Pva3wejwsHxQgLQt1ok0rz2ErQhuLVfK6QtKaDNdbFxPgW5+Sc0abYcXpjk19HXavYDZ QgZL879Poddpfik2YsSQ34yzFTGzuP0A+emkSdSlBl7CxVajA6VgoQThCxsH1u0DsW57 JpzfXIY0pnMVSrNrfaNh04gagOMqJPfP2RZV2WG1c4YEe3P/zWpjhSaaVBgZfnWrESXs FAmg== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j12-v6si2933633pgv.574.2018.06.01.00.13.45; Fri, 01 Jun 2018 00:13:59 -0700 (PDT) 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751357AbeFAHL6 (ORCPT + 99 others); Fri, 1 Jun 2018 03:11:58 -0400 Received: from mail.skyhub.de ([5.9.137.197]:34304 "EHLO mail.skyhub.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750760AbeFAHL5 (ORCPT ); Fri, 1 Jun 2018 03:11:57 -0400 X-Virus-Scanned: Nedap ESD1 at mail.skyhub.de Received: from mail.skyhub.de ([127.0.0.1]) by localhost (blast.alien8.de [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id MzxGX9lRcJvZ; Fri, 1 Jun 2018 09:11:55 +0200 (CEST) Received: from nazgul.tnic (188-23-149-244.adsl.highway.telekom.at [188.23.149.244]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.skyhub.de (SuperMail on ZX Spectrum 128k) with ESMTPSA id 8C35F1EC0316; Fri, 1 Jun 2018 09:11:55 +0200 (CEST) Date: Fri, 1 Jun 2018 09:12:15 +0200 From: Borislav Petkov To: Zhenzhong Duan Cc: linux-kernel@vger.kernel.org, mingo@redhat.com, tglx@linutronix.de, Srinivas REDDY Eeda , hpa@zytor.com Subject: Re: [PATCH] x86/microcode/intel: Fix memleak in save_microcode_patch Message-ID: <20180601071215.GD17783@nazgul.tnic> References: <888102f0-fd22-459d-b090-a1bd8a00cb2b@default> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <888102f0-fd22-459d-b090-a1bd8a00cb2b@default> User-Agent: Mutt/1.6.0 (2016-04-01) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, May 31, 2018 at 09:51:05PM -0700, Zhenzhong Duan wrote: > Free useless ucode_patch entry when it's replaced. > > Signed-off-by: Zhenzhong Duan > --- > arch/x86/kernel/cpu/microcode/intel.c | 10 +++++++++- > 1 files changed, 9 insertions(+), 1 deletions(-) > > diff --git a/arch/x86/kernel/cpu/microcode/intel.c b/arch/x86/kernel/cpu/microcode/intel.c > index 1c2cfa0..461e315 100644 > --- a/arch/x86/kernel/cpu/microcode/intel.c > +++ b/arch/x86/kernel/cpu/microcode/intel.c > @@ -150,6 +150,12 @@ static bool microcode_matches(struct microcode_header_intel *mc_header, > return false; > } > > +static void memfree_patch(struct ucode_patch *p) > +{ > + kfree(p->data); > + kfree(p); > +} > + > static struct ucode_patch *memdup_patch(void *data, unsigned int size) > { > struct ucode_patch *p; > @@ -190,8 +196,10 @@ static void save_microcode_patch(void *data, unsigned int size) > p = memdup_patch(data, size); > if (!p) > pr_err("Error allocating buffer %p\n", data); > - else > + else { > list_replace(&iter->plist, &p->plist); > + memfree_patch(iter); Looks correct. I've dropped the memfree_patch() two-liner though and made it do kfree() directly. Thx. -- Regards/Gruss, Boris. ECO tip #101: Trim your mails when you reply. --