Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp226922imw; Fri, 8 Jul 2022 01:40:35 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vDoxZjFL6a4CVvDZedjEoAgL3i8rdoPTmcBvFcdrtBfGj6VJK66Sdn9vqeSOcFYElD1QjX X-Received: by 2002:a17:902:ce8f:b0:16b:fbc1:9529 with SMTP id f15-20020a170902ce8f00b0016bfbc19529mr2508199plg.159.1657269635051; Fri, 08 Jul 2022 01:40:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657269635; cv=none; d=google.com; s=arc-20160816; b=Z3mlZp7vwKLs78HZXWlXr7P9fmePFGRiXNPXf0EkWIP0MNl4drXzYl1QONjiGZn71D JyBuDT0ZazurNZWaKO/ntG6U0Y8Sevs8CnoPoYHUwkZPi5V0iOnBup1lGgdbCu0OqiVA uEG1tLE/D0Qzj/CfE2J47RHF4FrM2OEPzy1zgtesH4dgZpMZ0iW6l1MJF5PCJ23aDbfs C52dhL57N+tqZqsBNRBwjSfqjKTfdIVAVuhuOFcDjgtC9sKcN0ZSUIsG1v7oEyS54LWU UcHMtflwSITatlbP/lanuW8xjUKGRLPdyeSQWBhwVHYGPdvL6omnT55VVAwLfK7SqvUU E3WA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=OP4X7LUwgicK2Z8iBMF1E87pgvSh5qnsKOoxYGUrQZE=; b=GRYsVrR6aapS2opjmRSi+eXpMhE5i8GglDSlhhCgoMqXq0+rHi05aRnu3OVR0JNKeM 1omyD3AIwlb1sQW8ZpVGOMC+ObJbSlHjmxxPO0zXxzJa7Sj+xeAmt309AF0cF8HaEMdG ky7wod9YWyF3UAL/qUAExOCDlCd3hbh9I3juJ2+ZLpZwdiyq2/r4xwgFTP3oQu82Occb jleL1n1XSN5OeL9FkEi0gvQW8xzNyR6JngUiiZgwftWcaUNSf7oPmhfcdGvg2PQXu/QS oWIeahhenxPM2BRfLpwxmHbFT/RXsYpcBm3DNYPuWuRbCKiwLbq/SdEVVSDN2TJg5eQi 4VvQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=dgT4PZDX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 65-20020a630244000000b0040d95162737si47209437pgc.234.2022.07.08.01.40.20; Fri, 08 Jul 2022 01:40:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=dgT4PZDX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237824AbiGHIew (ORCPT + 99 others); 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 X-Spam-Status: No, score=-3.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 >