Received: by 2002:ac0:de83:0:0:0:0:0 with SMTP id b3csp1202920imk; Sun, 3 Jul 2022 20:28:54 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uvA+mJJWcI1QQZAPAPQKZB0o0s3PcNEHqQyuqLx+XNl+c1dtXIBPxZMAhW/jheFK2phdjp X-Received: by 2002:a17:906:5a71:b0:72a:47b2:408 with SMTP id my49-20020a1709065a7100b0072a47b20408mr24457262ejc.477.1656905333789; Sun, 03 Jul 2022 20:28:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656905333; cv=none; d=google.com; s=arc-20160816; b=TlgqTIhsooebQe7eDSPhLjc7Bao5u+dRiMRNUtR+wXxSlN5CESDp36255XCCrZcDdd b0vq2sE8rvi9+iSdFxCFn6hGQyKI53/7dN2vvINd3bw6g4MFav/a+w9g5wdlWpz+SWB3 uMfz4noznn5MSoKtXZjHzbibIkveZPRPemjk/LxMvc7y6ZnPs/nE42p2B1RZTk9H3l5y H23wF9MF3T3Y/kHv8MT9TJf5wtf4Qugb7iw1UOooh2zsAkVyXgb3yc8xgy5DVSQn9N5U 16sS+lptURTJO+6f7eoOUWT/tHYtfYwLExfbnOeUUqxS+lPbuc/XfIvCRDig2Uia0oW2 f7pA== 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=1P+Z0NPfnwQi7DbmZ8kWxij8Re3KK3gRyK0ayDPLp8E=; b=ajajnnDBlJpt1HBZ+u0gtk5GRR756KibuQfzLCGjMh1HcYtVL9vuPljPd1+9RuFJWT geRD4CGIA1J+e3yAAPjtO0d8EjwFfGEmFDoF8QwTLs9llZhSl3e5BRcgoCes/ktHxqxt bPykwry3CsaxmD2aD3iVm2GNufILhfxzjo7fCTpq6Y6oTPU4RVHjARv23WVclQBTdAsG Dk8C32tWoip5Lk500BgXrMj2dJUP8ZCZktTGYuazXRtJTrTlwCnQc+CboZRrGFGqBkhP 3L1jnTLdw3qQrJqYjKk4V8fwiqdtvt9OsFv8ubBSfO+0uqk100jcC8pUko/Jm0sRwkfe ZN/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=PfZJPrko; 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 hr6-20020a1709073f8600b006f40efd4b88si38362258ejc.812.2022.07.03.20.28.28; Sun, 03 Jul 2022 20:28:53 -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=PfZJPrko; 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 S232238AbiGDCyU (ORCPT + 99 others); Sun, 3 Jul 2022 22:54:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39100 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229473AbiGDCyR (ORCPT ); Sun, 3 Jul 2022 22:54:17 -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 6CFC3BC5 for ; Sun, 3 Jul 2022 19:54:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1656903255; 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=1P+Z0NPfnwQi7DbmZ8kWxij8Re3KK3gRyK0ayDPLp8E=; b=PfZJPrkoghe6EHCBavINgGRIxJY2Nwi7pe9PSvg68tJSPdbsjPMY8JfqeTB1W++5BiidIv mHYMA0FwY95oBGW4fe7VqbKhvEyyDULE0KgNpyQYRs5QJJges4obWmJnCd+R5wlqjyvTR9 X3OW2M76lDTZgHuepbL4hqTvZnJUh3w= 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-375-3Y-jYpWXPkaCqKBkgi_BZA-1; Sun, 03 Jul 2022 22:54:10 -0400 X-MC-Unique: 3Y-jYpWXPkaCqKBkgi_BZA-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9B27A185A7B2; Mon, 4 Jul 2022 02:54:09 +0000 (UTC) Received: from localhost (ovpn-13-121.pek2.redhat.com [10.72.13.121]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C36A1400DFD0; Mon, 4 Jul 2022 02:54:08 +0000 (UTC) Date: Mon, 4 Jul 2022 10:54:05 +0800 From: Baoquan He To: Jianglei Nie Cc: vgoyal@redhat.com, dyoung@redhat.com, kexec@lists.infradead.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Andrew Morton Subject: Re: [PATCH] proc/vmcore: fix potential memory leak in vmcore_init() Message-ID: References: <20220629165216.2161430-1-niejianglei2021@163.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220629165216.2161430-1-niejianglei2021@163.com> X-Scanned-By: MIMEDefang 2.84 on 10.11.54.1 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=unavailable 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 06/30/22 at 12:52am, 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 | 1 + > 1 file changed, 1 insertion(+) > > diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c > index 4eaeb645e759..7e028cd1e59d 100644 > --- a/fs/proc/vmcore.c > +++ b/fs/proc/vmcore.c > @@ -1568,6 +1568,7 @@ static int __init vmcore_init(void) > return rc; > rc = parse_crash_elf_headers(); > if (rc) { > + elfcorehdr_free(elfcorehdr_addr); > pr_warn("Kdump: vmcore not initialized\n"); > return rc; Guess it's found by code inspecting since if vmcore_init() failed, kdump kernel won't do anyting meaningful and reboot, then nobody notice or care about this leak. If so, is this better? diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c index 7e028cd1e59d..ea2f44d77786 100644 --- a/fs/proc/vmcore.c +++ b/fs/proc/vmcore.c @@ -1568,16 +1568,16 @@ static int __init vmcore_init(void) return rc; rc = parse_crash_elf_headers(); if (rc) { - elfcorehdr_free(elfcorehdr_addr); 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; +fail: + elfcorehdr_free(elfcorehdr_addr); return 0; } fs_initcall(vmcore_init); > } > -- > 2.25.1 > > > _______________________________________________ > kexec mailing list > kexec@lists.infradead.org > http://lists.infradead.org/mailman/listinfo/kexec >