Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp1053929imw; Fri, 8 Jul 2022 17:40:20 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tRr/LFeL2VMd/RLLMNsOsQRWajHSoUEJ/wRXHfEOyGIX8XkVqo0tCjUVjcmP74nCXG3/1g X-Received: by 2002:a05:6402:328f:b0:43a:8488:1000 with SMTP id f15-20020a056402328f00b0043a84881000mr8238267eda.105.1657327220756; Fri, 08 Jul 2022 17:40:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657327220; cv=none; d=google.com; s=arc-20160816; b=oNoALpeKKdH9fmXjEjZTPYYk8pJawS5ricXyff5NUXZ8Z5ZZ8YAwMZ4fKXh988B+Dc HcVEdKBD92bjfKtbTXWMGlM3bNTuVvQR4W8UxyuMi2HvH6+5qAv9YaLWe9Zcy+OYx0Zy JzGX/CV0SmxGmKeAIyb/t5uM1MCLoTMNYrflKoY6uIaBsmCCx6ady81QU2QZysIjvCKq VzlZloojGIbdBz6nhxmOxIW8gOKb+04d38APDwrVgrapIbcDm1GLP2ScvSY7jBngHowC aJ9yd3nWAloyXUgQ22WfYPTdRzhzpVybhjpzve9obfMBj6LmeKWV1nn5qBbItUu8UjzF HrIg== 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=4ko4GkJU0Tn8zbLKOIgGsmDKDvugLe86WnU6pUPW6HE=; b=Coi3Jkgh9rz+OqrEwYIxW1I0bQXjc/hxUIf4Zsl9gY4alQ+dgFBKr/+2qKgQOTLHRG BIZFb3Om5c0stcltG/6nqordm4OiCiT03cg18Eg/FTCnRIvtR71x4mFoC+vhuk8bXnMg pJ1p7JV5vR2IFskUn3RRePxDlV/j5bGe2HHgQ1uQJLeRU/Mrvt4Y268sKO8sXwezmZGX SJBrtnvkNgjNkrfT42wKR/RwvKNTAf97SSEt5TaHBIGlp7qZXJ/S6ENPNxA0DjGxG3aA Vlz75gI9L+hWhywjcxDDLpZZdNfKxa8ZQOc9Uzh2c4ulm9GBsplJl0KFhb/EmEdzkobb /wVQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Li3pFMOW; 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 z20-20020a05640240d400b0043a8fb8c0a9si269689edb.452.2022.07.08.17.39.53; Fri, 08 Jul 2022 17:40:20 -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=Li3pFMOW; 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 S229834AbiGIARX (ORCPT + 99 others); Fri, 8 Jul 2022 20:17:23 -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 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, 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/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);