Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp3268365imw; Mon, 11 Jul 2022 05:32:32 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tfUsUNWzjij3vRB4IaAv+8eHCiS++xzxEEDGZVhAejzCYU+coe72/6Im9Jr4m0LFZz6PE0 X-Received: by 2002:a17:907:271a:b0:72b:4ef4:2d8e with SMTP id w26-20020a170907271a00b0072b4ef42d8emr6744959ejk.634.1657542751836; Mon, 11 Jul 2022 05:32:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657542751; cv=none; d=google.com; s=arc-20160816; b=CiI5336XIuMj8pXn9QZQkKd26ZFKtWS8sDAM/a5gQpye9giOUAyZ1NuE6+VbR0hCBG p6ptNKmKBL0J+rJFrb1nJWhUoHmJsKbRt9SA6dquHZZ52E9fO2KlOsywYryXJhogtdI8 CcPZTng2nJg2j82oVnOvIxX56Cvzv2tmt3FSDFFzg4bgAHuQAN0dVk/LlVSv2R8arQJV 59au5xqhf7CMe/OsDcUJSemFwZ5IghPQLEkZyJV0uKt6VD9vLm0nrq39Bf66yCUcsoEx 6F6PdicYcYDY/RzPFWIVxKjS1TB77FGT2tkYZjO5qXa9DxKCBdYKkVzxnQQz39b5pemU 2t+Q== 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=PWKdgytGuJS/GqF7wkUB921LDsDRCbl9WqcuwqS4VyU=; b=ld4JpnnG5aYGgLiuvBERKgi6WcZ07VZuLR1OjzDPN4rxbJWymrl3uGz6RC2Txen6Zd d1T/zMY+hawFuYSUpHsvqeIkMpyR99/8jHcpViJHvgUzab0EMIVhmEDbQioeLHMKBYQd Gsgutj8ZRXbEdG022tSq7RzDDbEQOYlkDgcdfnLOBnuT7KI8Xl5iWk4tAq3sQUBfKfWZ HMCgDkKFiUHsZI3XCALznkb/9cgR7G2SlnlZB7mVlr32iUC9VJGgs2FQCVtnzoBL7hux 1qgKvhYYgjaiDKVC3ePNBkdgJ4iRXGtoyPvCmlZUX2dWPd0IMF5Z3y0IBusVwxrpxSJ2 4HyQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=WLBkkmsb; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y21-20020a50e615000000b0043a3a5d641fsi6963151edm.525.2022.07.11.05.31.51; Mon, 11 Jul 2022 05:32:31 -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=@infradead.org header.s=casper.20170209 header.b=WLBkkmsb; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230178AbiGKMSy (ORCPT + 99 others); Mon, 11 Jul 2022 08:18:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45574 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229543AbiGKMSw (ORCPT ); Mon, 11 Jul 2022 08:18:52 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3274DA8; Mon, 11 Jul 2022 05:18:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=PWKdgytGuJS/GqF7wkUB921LDsDRCbl9WqcuwqS4VyU=; b=WLBkkmsbL8JR/wP9knKzTxAJfu zgidLq04zQgTBURaH79ibOAB22d4EsQ4Bn7bPht4FFI6EFzIdXcuYGlbs7EFFAYnux/beYf/Itsor SdTXk/wJ9u8qT3cg5LSuaJ//YbNjdesxvxujy7rGIxjHLj+kft15iP8xYhVEpoud7awjayUdX3Ukk 3nfaf5zL8hmCUNb3uHbPhEd2fMz57lYDqjU8SSYxjvMeTECWxdif2FL9ylYAwbpN3/RpHj2rsBxJ5 JRAYco9YpARjcDLsprngrurBdRSY82Z9dqla/E6KhYGU48ZJCYkB+9z4UqW1p4S98pIOUx9ikOm8S K/PPxyXA==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1oAsN2-005waR-QO; Mon, 11 Jul 2022 12:18:36 +0000 Date: Mon, 11 Jul 2022 13:18:36 +0100 From: Matthew Wilcox To: Baoquan He Cc: Jianglei Nie , vgoyal@redhat.com, dyoung@redhat.com, kexec@lists.infradead.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: Re: [PATCH v3] proc/vmcore: fix potential memory leak in vmcore_init() Message-ID: References: <20220711073449.2319585-1-niejianglei2021@163.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,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 Mon, Jul 11, 2022 at 03:49:51PM +0800, Baoquan He wrote: > On 07/11/22 at 03:34pm, 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. > > > > 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..125efe63f281 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; > > Sigh. Why don't you copy my suggested code directly? I think at this point, you should just submit your own patch and credit this person with Reported-by: