From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3236EC43334 for ; Sat, 9 Jul 2022 00:17:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229617AbiGIARY (ORCPT ); Fri, 8 Jul 2022 20:17:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41396 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229530AbiGIARU (ORCPT ); Fri, 8 Jul 2022 20:17:20 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id D2CBD691DD for ; Fri, 8 Jul 2022 17:17:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1657325838; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=4ko4GkJU0Tn8zbLKOIgGsmDKDvugLe86WnU6pUPW6HE=; b=Li3pFMOWaMNsqo7Bbf6Jf0+kq5zZ8sxysLoTUVbVF+hcCrO+lxhjQpCyhDTzrgHRjkrMkS FjDSv7/08+xzqcuT15+ozTYW1Dok3DYt8MFLsHtbWzax6kgsOqgiTFIeEVu/27JfgBYxcH k5l63tXzVhCuqLHaa7cASONrhF56ebk= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-358-Qq9SNVonNPKWeLsxs3H5wQ-1; Fri, 08 Jul 2022 20:17:09 -0400 X-MC-Unique: Qq9SNVonNPKWeLsxs3H5wQ-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 7EB45101A54E; Sat, 9 Jul 2022 00:17:09 +0000 (UTC) Received: from localhost (ovpn-12-42.pek2.redhat.com [10.72.12.42]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A579AC35979; Sat, 9 Jul 2022 00:17:08 +0000 (UTC) Date: Sat, 9 Jul 2022 08:17:04 +0800 From: Baoquan He To: Jianglei Nie , akpm@linux-foundation.org Cc: vgoyal@redhat.com, dyoung@redhat.com, kexec@lists.infradead.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: Re: [PATCH v2] proc/vmcore: fix potential memory leak in vmcore_init() Message-ID: <20220709001704.GA342876@MiWiFi-R3L-srv> References: <20220704081839.2232996-1-niejianglei2021@163.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Scanned-By: MIMEDefang 2.85 on 10.11.54.8 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 07/08/22 at 04:34pm, Baoquan He wrote: > On 07/04/22 at 04:18pm, Jianglei Nie wrote: > > elfcorehdr_alloc() allocates a memory chunk for elfcorehdr_addr with > > kzalloc(). If is_vmcore_usable() returns false, elfcorehdr_addr is a > > predefined value. If parse_crash_elf_headers() occurs some error and > > returns a negetive value, the elfcorehdr_addr should be released with > > elfcorehdr_free(). > > > > We can fix by calling elfcorehdr_free() when parse_crash_elf_headers() > > fails. > > LGTM, > > Acked-by: Baoquan He Sorry, I didn't check the code change carefully. This v2 is not right. I thought Jianglei took my suggested code change directly. Seems he mistakenly took part of them and caused error. > > > > > Signed-off-by: Jianglei Nie > > --- > > fs/proc/vmcore.c | 5 ++++- > > 1 file changed, 4 insertions(+), 1 deletion(-) > > > > diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c > > index 4eaeb645e759..86887bd90263 100644 > > --- a/fs/proc/vmcore.c > > +++ b/fs/proc/vmcore.c > > @@ -1569,7 +1569,7 @@ static int __init vmcore_init(void) > > rc = parse_crash_elf_headers(); > > if (rc) { > > pr_warn("Kdump: vmcore not initialized\n"); > > - return rc; > > + goto fail; > > } > > elfcorehdr_free(elfcorehdr_addr); ~~ this line should be removed. > > elfcorehdr_addr = ELFCORE_ADDR_ERR; > > @@ -1577,6 +1577,9 @@ static int __init vmcore_init(void) > > proc_vmcore = proc_create("vmcore", S_IRUSR, NULL, &vmcore_proc_ops); > > if (proc_vmcore) > > proc_vmcore->size = vmcore_size; > > + > > +fail: > > + elfcorehdr_free(elfcorehdr_addr); > > return 0; ^ return rc; the returned value is wrong with v2. What I suggested is as below. Andrew, please drop the one merged into mm-unstable branch. Hi Jianglei, Can you post v3 with below correct change and add Andrew to CC? diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c index 4eaeb645e759..390515c249dd 100644 --- a/fs/proc/vmcore.c +++ b/fs/proc/vmcore.c @@ -1569,15 +1569,16 @@ static int __init vmcore_init(void) rc = parse_crash_elf_headers(); if (rc) { pr_warn("Kdump: vmcore not initialized\n"); - return rc; + goto fail; } - elfcorehdr_free(elfcorehdr_addr); elfcorehdr_addr = ELFCORE_ADDR_ERR; proc_vmcore = proc_create("vmcore", S_IRUSR, NULL, &vmcore_proc_ops); if (proc_vmcore) proc_vmcore->size = vmcore_size; - return 0; +fail: + elfcorehdr_free(elfcorehdr_addr); + return rc; } fs_initcall(vmcore_init);