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 18178C433EF for ; Fri, 8 Jul 2022 08:34:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237856AbiGHIew (ORCPT ); Fri, 8 Jul 2022 04:34:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38208 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237206AbiGHIev (ORCPT ); Fri, 8 Jul 2022 04:34:51 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 0AFFC12615 for ; Fri, 8 Jul 2022 01:34:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1657269290; 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=OP4X7LUwgicK2Z8iBMF1E87pgvSh5qnsKOoxYGUrQZE=; b=dgT4PZDXP4at7xbMiDKB+8vMPo2GJC58YRyd9baWCa6nvxXkDpX3kALKYFWnWcexBPa2iD NmGBc/vplfYf+KnVFfOK2ec24bqSzMBRISxK6SNwrh9ryVNir5hq8VJIwb9QPq6RzTCuha DMcNNOr+uO5FEy33m78JjexDIO1aZqk= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-655-YLkXHmJ7MkK83y7yYijfCw-1; Fri, 08 Jul 2022 04:34:48 -0400 X-MC-Unique: YLkXHmJ7MkK83y7yYijfCw-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C18123C0ED4C; Fri, 8 Jul 2022 08:34:47 +0000 (UTC) Received: from localhost (ovpn-12-169.pek2.redhat.com [10.72.12.169]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 17E662166B26; Fri, 8 Jul 2022 08:34:46 +0000 (UTC) Date: Fri, 8 Jul 2022 16:34:43 +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: References: <20220704081839.2232996-1-niejianglei2021@163.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220704081839.2232996-1-niejianglei2021@163.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 > > 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); > 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; > } > fs_initcall(vmcore_init); > -- > 2.25.1 >