Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp3866130imw; Mon, 11 Jul 2022 18:13:16 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uUmc/UwHY5PAfZzoWzDZL4ZgkT4h3oYSHuA8jCnLDeLKeRx2uB4Lh52fBr+Fe39j52X94r X-Received: by 2002:a05:6402:1606:b0:43a:2204:8b5e with SMTP id f6-20020a056402160600b0043a22048b5emr27956192edv.316.1657588396581; Mon, 11 Jul 2022 18:13:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657588396; cv=none; d=google.com; s=arc-20160816; b=JErrTg8KUXlLzG91T8nVAOI3DnNLQRAGxjozlMtgxYg2z+6wFc3rQygwtTrh1EDmyH vAFdnvsNIoH47MJ0FlOi874IfjpTKnhlWam1Zc0Y1qkX0nhCMuWH+6YWZotizkpMveoH IM2wlSMpRX/suVe44ciA1FK06BeYXpdvEaYjRpg8S0nNd4ldLgVkJ4hnYGX/LTkB0tul RC+5DtmJQsqRgN1rHh2EnqBonPrQzp2XF9cvk65Zop72YfYpInEsniaW1aOX3I8HJ5sS l7HCE8AejBzS81FjbR67px78fhmA2ZFYOdtEKZA34inRQEYo3oHulllIX5TSoXSwRdiZ 1m4g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=3punIvIPkKlM/8SU3deWci59gXZoY5NLzvTD+3wQ/HI=; b=m3kT17ZDebV6vmXwwNGZAbsXAg+Fn2xHFoJqPiAwUiyWGMCEHqjhxQtD+4pkarC54a gYww5Hnsb9MkHfCD2BMkNFlfNO2VdhaRiWIVDyFw2AUHFqia33o1ftcaZXhY9/dHjYLQ CtH/QXjmnmy1inpgCPRKEQM3nWDDHthr72F1Rylv8OPbxfdYej9CbxOaNbc5pOE50P0E zQsShst2FyKlZKFcp7Wxvz91HJ7cpCShpzHSSBqwfU8tXwKHxdXFS0rM93BVyNFUILDw AhcdpcEty2+G/Ab2cM9/KbvV/TF3zdaMYhnqstSW84WeCXLHDOsWWhJkxI9FRImPMAIE JlPw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=jQ6ztP6l; 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=163.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hs4-20020a1709073e8400b0072b14352ab9si13183794ejc.95.2022.07.11.18.12.51; Mon, 11 Jul 2022 18:13:16 -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=@163.com header.s=s110527 header.b=jQ6ztP6l; 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=163.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232159AbiGLBBi (ORCPT + 99 others); Mon, 11 Jul 2022 21:01:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59054 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232154AbiGLBBd (ORCPT ); Mon, 11 Jul 2022 21:01:33 -0400 Received: from mail-m971.mail.163.com (mail-m971.mail.163.com [123.126.97.1]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E731E2E68B; Mon, 11 Jul 2022 18:01:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id:MIME-Version; bh=3punI vIPkKlM/8SU3deWci59gXZoY5NLzvTD+3wQ/HI=; b=jQ6ztP6l8lXtFdHuNcI8e my363dV1FP2DSjoPRiQ/KULXg4CxC6BdQ9HJnVmEQcVva6FHvpXaAlgJJMjZnmff 7wElftY53IZCdzRjwykHkuVas7T7nNAop4esWQ9bIeeB3b88yMnDcTtmGixIy1rL bR8rR7s0+svSjQPfAY1i7U= Received: from localhost.localdomain (unknown [123.112.69.106]) by smtp1 (Coremail) with SMTP id GdxpCgCXzonJx8xiSfUyNw--.11337S4; Tue, 12 Jul 2022 09:01:14 +0800 (CST) From: Jianglei Nie To: bhe@redhat.com, vgoyal@redhat.com, dyoung@redhat.com Cc: kexec@lists.infradead.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Jianglei Nie Subject: [PATCH v4] proc/vmcore: fix potential memory leak in vmcore_init() Date: Tue, 12 Jul 2022 09:00:55 +0800 Message-Id: <20220712010055.2328111-1-niejianglei2021@163.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: GdxpCgCXzonJx8xiSfUyNw--.11337S4 X-Coremail-Antispam: 1Uf129KBjvdXoWrKrWUtFyDCr1xAr1rCryUJrb_yoWkKrc_Cw 4UKr4xX3yrGa13Gr4UK3W5tw42kw1Y9rn8Xr1xCF9rJayrKwsxWrZ7urZ3Ar93JrsY9345 uw4SkrW7u345KjkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUvcSsGvfC2KfnxnUUI43ZEXa7xRibAwPUUUUU== X-Originating-IP: [123.112.69.106] X-CM-SenderInfo: xqlhyxxdqjzvrlsqjii6rwjhhfrp/1tbiFRo8jF5mLvq-eQAAsV X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, 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 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 | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) 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); -- 2.25.1