Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp3080695imw; Mon, 11 Jul 2022 01:02:37 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tuD0CCj/E9lEXWwqdD/2UyfJvtFEv6nYryhjHNCyg6cnKdII+NRqs6PTz3grH406c5PBx3 X-Received: by 2002:a05:6402:248c:b0:437:afe7:818b with SMTP id q12-20020a056402248c00b00437afe7818bmr22818549eda.239.1657526557336; Mon, 11 Jul 2022 01:02:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657526557; cv=none; d=google.com; s=arc-20160816; b=wZo+NZ3mHnTvv9aqV+EfMdCVGxyLwPzNEN+EEa4REJC4BOh3RV8gz9pJzMyISJq4D3 5HnxZXUNECI6UsfSQT/tZqJhS5h8+r7Upoh6u4mGFNwdGkdIcZXhgH8ew+htPv67b3av wnebFJR/BLx4WSzzbiWeyeNfItYhVowtd234ntV/ANwG4eLRGyd85QQ9Q3u3UJ6B2zQY ngeUywkqFGy2JW/BJ/A6LGbqsKYLWQ+cKsuhLkAT+ntwml1hkkkozKfXRq6kbUElowAA 2Fbdg5aVi+YRX6RvCYYUTtKSvMVVonARFi+whaLil85MVx+Ln+GyFwes8pLwHkNvJk62 4K1g== 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=65+qN8d8sGZSpzbvLfg3emL2uyMu+GmRHRjSzDdv/js=; b=xw4xTlw2gBVbXVO4vjxcUY9yBlagGYEvJ10bt2Qe0PfEZSNIJ3Rxc6YZ5xOf5X2115 PoKbpRfaizikV/O2hp4jffVTmdxUroCWLWEh3eQGPECOpETSZ8uz134fpdUXmrGnqHoj Ers62HUTY4Q4lA+nk5sFfgL3zbEsuPCuENxSm1ueF8bkURPUgWhYuaK+o4yiowyZsUAV UM/1nEWVo3Y/uq02X0SRm0LnIMsnz1GSAWXS6QGQD8HfmxfBMn4d1deRcetjoHIlKUVG LLgR/s0LK7+8VHfFWbX773YF21DpX94lhLEOdCfJSykdSiKwHr1FlirOTiyebwM7bUQ9 MPcg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="LpG/tNwf"; 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 ss1-20020a170907038100b0072aa15584f8si7611624ejb.756.2022.07.11.01.02.13; Mon, 11 Jul 2022 01:02:37 -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="LpG/tNwf"; 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 S230202AbiGKHuB (ORCPT + 99 others); Mon, 11 Jul 2022 03:50:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33516 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230198AbiGKHuA (ORCPT ); Mon, 11 Jul 2022 03:50:00 -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 21F421B7A3 for ; Mon, 11 Jul 2022 00:49:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1657525798; 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=65+qN8d8sGZSpzbvLfg3emL2uyMu+GmRHRjSzDdv/js=; b=LpG/tNwfj5EM1z5qpvYVCkGzyy9Lap6xAb1VcVjFhhFeX6LrIlbGsXNf37OA1/9JSRWYqe LRKfIFEAH0Is7uTz27Kf+tkyLNLwl8Amq7ydTeXyCHyP0g0vOQz8GnTibAuxuJAoMG69Ob pGPZD2xFJXxMBUsvBEefJMBOKzm98sA= 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-630-PcKH02_GNmyyAY5EzywamA-1; Mon, 11 Jul 2022 03:49:55 -0400 X-MC-Unique: PcKH02_GNmyyAY5EzywamA-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 8D5D6804197; Mon, 11 Jul 2022 07:49:55 +0000 (UTC) Received: from localhost (ovpn-12-204.pek2.redhat.com [10.72.12.204]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E0E9140CF8EA; Mon, 11 Jul 2022 07:49:54 +0000 (UTC) Date: Mon, 11 Jul 2022 15:49:51 +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 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: <20220711073449.2319585-1-niejianglei2021@163.com> X-Scanned-By: MIMEDefang 2.84 on 10.11.54.1 X-Spam-Status: No, score=-2.7 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/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? > } > elfcorehdr_free(elfcorehdr_addr); Remove above line. > elfcorehdr_addr = ELFCORE_ADDR_ERR; > @@ -1578,6 +1578,9 @@ static int __init vmcore_init(void) > if (proc_vmcore) > proc_vmcore->size = vmcore_size; > return 0; Remove above line too. > +fail: > + elfcorehdr_free(elfcorehdr_addr); > + return rc; > } > fs_initcall(vmcore_init); > > -- > 2.25.1 >