Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp6186997rwn; Mon, 12 Sep 2022 23:35:54 -0700 (PDT) X-Google-Smtp-Source: AA6agR6mBTjiqNNw2dWjh0PlwhuHXogFDQStG+aE5prn98UEsUvD5l1VS8eBiU5FHVWV8lUKwD9c X-Received: by 2002:a17:907:1b1f:b0:72f:56db:cce9 with SMTP id mp31-20020a1709071b1f00b0072f56dbcce9mr20276822ejc.605.1663050953912; Mon, 12 Sep 2022 23:35:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663050953; cv=none; d=google.com; s=arc-20160816; b=r/dR1xoDcp3SFDnDGxwR329JW2q668OJIasI+i0zelgMSHw0qafTOZTa6YtKwETjB3 EaO9CXdsxxLifiJlJIvOvzfLu3V15pFdOmle2nch1JEWiJLyywECOz5RmwLf6hXF91Cb Bub1p6oJQMmpRb6qYqHa1stOXvkYNsns6vSjLYLnzT99HMCd7t5BORe6sWP61ViHlcBf IfZUJngQDkXbvBIm8w+dK+sW8dV9Hpkw1pCDm+03Qq3AqZQg8zAOgPDuBVo8LPSVJNS5 xrDV5ogbHUG78PJqPq2I3F3Q1n5F1XZBkbkd0OXGfsWhp1Fj2ig9rxVdYVd5ZtGuW4tg e49w== 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=dUKqH1exOk0lpXq/SvhuwXEQkuHHI1k0zmxmjV1BOdc=; b=lQbf0UH8ARoFd7sHnxbT4SYObK5JqZhFavBPduDYM+AloO81VVMgs8iAVdQPVOHSal VhyjqpMdW08D8k6seFT8RYiFnTHyX3l65I0xiK6tcMDr5N+oNHfxwbUPc0Z8xoVDHjMr QRxMNLfWkcG9Z2NMxl0mWLZbgE7SpjwC1Cc0GjH18PXnG+/4aK8ZgANPTUM7+bzStd63 yCMG8CxmGrbHFT1H5K5Y/klfJq7pCUNcfbrFOaIpANa1pGzf9DnwTn1zYxmQwzViv6xm 0yFVj8pGH2D643qENeEEmT7Umya9LEX2kWcqCAkbugN2aCmhv675v/5P8t0EBrgW+Q50 W20g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=IpzwCIgH; 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 hc39-20020a17090716a700b0077b08d909fbsi11034657ejc.53.2022.09.12.23.35.28; Mon, 12 Sep 2022 23:35: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=@163.com header.s=s110527 header.b=IpzwCIgH; 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 S230322AbiIMGZ5 (ORCPT + 99 others); Tue, 13 Sep 2022 02:25:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42950 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229611AbiIMGZk (ORCPT ); Tue, 13 Sep 2022 02:25:40 -0400 Received: from mail-m974.mail.163.com (mail-m974.mail.163.com [123.126.97.4]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id ACD6846D88; Mon, 12 Sep 2022 23:25:36 -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=dUKqH 1exOk0lpXq/SvhuwXEQkuHHI1k0zmxmjV1BOdc=; b=IpzwCIgHxLNhDNGMlaSp2 QTStWigvTg7MrDACTCpH7HDS8v14HLeL5/Go8rYzk4duPiGvLYEdZutCIvbpTU2C tjpHpd7eV4XtXAC/xzxd8LCpsjFotx1IXL97zS8Cnsd6eFhyjHKd4aIfYcnpK+QB 0IEM2uBcG93YA2Kvkr+32I= Received: from localhost.localdomain (unknown [36.112.3.164]) by smtp4 (Coremail) with SMTP id HNxpCgBHzLU_IiBjHTGQcg--.34490S4; Tue, 13 Sep 2022 14:25:11 +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] proc/vmcore: fix potential memory leak in vmcore_init() Date: Tue, 13 Sep 2022 14:25:01 +0800 Message-Id: <20220913062501.82546-1-niejianglei2021@163.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: HNxpCgBHzLU_IiBjHTGQcg--.34490S4 X-Coremail-Antispam: 1Uf129KBjvJXoWrKrWUtFW5Gw4xXFWfXr17Awb_yoW8Jry5pF 18Gw48CrykWrn7ur48Jw47Zrn5Aa1UXayjqry7CF4ayrnxWw4vyrWYkFWF9F1Yvr10ga98 XFWkua13Aa98WaUanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0zR0PfJUUUUU= X-Originating-IP: [36.112.3.164] X-CM-SenderInfo: xqlhyxxdqjzvrlsqjii6rwjhhfrp/1tbiPgd7jFxBuB+RyAAAst 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() gets some error and returns a negetive value, the elfcorehdr_addr should be released with elfcorehdr_free(). Fix it by calling elfcorehdr_free() when parse_crash_elf_headers() fails. Acked-by: Baoquan He Signed-off-by: Jianglei Nie --- fs/proc/vmcore.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c index f2aa86c421f2..163cb266f5fd 100644 --- a/fs/proc/vmcore.c +++ b/fs/proc/vmcore.c @@ -1568,15 +1568,17 @@ 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