Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp3076564imw; Mon, 11 Jul 2022 00:55:07 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vju1wT2eYxeehJ3Q2T5plk8yjYOXZgd81ArJkUeZWWhOKgs9AFGC6fAh3Xjfk3DOU2G8FO X-Received: by 2002:aa7:dd4b:0:b0:43a:d508:7cb9 with SMTP id o11-20020aa7dd4b000000b0043ad5087cb9mr5246244edw.218.1657526107448; Mon, 11 Jul 2022 00:55:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657526107; cv=none; d=google.com; s=arc-20160816; b=afpqvI2tHbr0Z6RbweLzvzJ8Mdb1Q71ewR2It0FoQLeL1P8ztz5hhDKsHGVAcxTb10 gj1D0L3IzH4e+63uMhyq6CmP/2OtQiP+AKGWn0D67REQ1ufajCg9L2I/t8fwBUs2Km0w oK+4Kp49DGWqy1kMbGG7ivncCVNJlh553ehIKMftOF2ygmV0ZMzyeCWr2/V8T9tWi+bu 65vcBPlHMDyJKjtnKDAcBICKRDI2K7jcC2mMV2mr1engdDBTRyrZ6ydV6jjqeXcDe4z0 mwiyG51RgEbjaBcsjnbX3htXTcscxmibrHK3aY1Vnxf0z6xCBlcjAc7NTlEcqa9QA6BQ 1lvw== 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=Cj/Rb6wa9GFxUQqhUdh2NDMpVy+s4rRoTrJKhdx+R5k=; b=X4zdCDFxCEhO55eTh+EP/CWeHrWC6wL3Id/jEkEY45tEXbpyidLf7euoRUFE5ABba4 CAgsArP6Gx9MG3IZgrwTF7cZZ7Jc4bJkXH8/cGaJEbejDR76K6BDyZF42mc2PwS4sIv0 srkyWe7Nt5l7+5lCg58UdlWLHqyq1pwkYLLbOeyXOY2iXx1e5fhuoy7criW8i0K6yYGO bzDSc0UNhqZWyJUvHlMfP/tB5Oq8kWSpFrQrci1F89uzUBu4gNTUpfYYG6Nf4R38BZJ8 WhX/eIVoLESnErPbyei5HZdS6DagpAde6PiFSsFWQUxnrVjU+8s98zipwmcllXwI99nZ x+TQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=Kaw7MUWj; 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 c10-20020a170906924a00b0072a63775cd2si8204092ejx.431.2022.07.11.00.54.43; Mon, 11 Jul 2022 00:55:07 -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=Kaw7MUWj; 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 S230162AbiGKHfP (ORCPT + 99 others); Mon, 11 Jul 2022 03:35:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54138 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230166AbiGKHfN (ORCPT ); Mon, 11 Jul 2022 03:35:13 -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 87A7F1BEAF; Mon, 11 Jul 2022 00:35:11 -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=Cj/Rb 6wa9GFxUQqhUdh2NDMpVy+s4rRoTrJKhdx+R5k=; b=Kaw7MUWjV/9FhP0wKMv1y J7FdyTKnUHsOOrQAx6FUpGNRz9Vjljp4Pv0tL27WOa6KrI3fZLMZXmPVt2FGnHx2 dH5fGdkzMSMBedQRUdSovOj83dy9CVuPSmhSBFA2k7aJeBH2q05IVTFhGAn1ZfPh Hyb8IkgCJ3TmrSIojgPr3o= Received: from localhost.localdomain (unknown [123.112.69.106]) by smtp1 (Coremail) with SMTP id GdxpCgDnPZGa0stioLW2Ng--.8571S4; Mon, 11 Jul 2022 15:34:58 +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 v3] proc/vmcore: fix potential memory leak in vmcore_init() Date: Mon, 11 Jul 2022 15:34:49 +0800 Message-Id: <20220711073449.2319585-1-niejianglei2021@163.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: GdxpCgDnPZGa0stioLW2Ng--.8571S4 X-Coremail-Antispam: 1Uf129KBjvdXoWrKrWUtFyDCr1xAr1rCryUJrb_yoWkurb_uF 4UKr4xX3yrGa1fGr4UKryrJw42kr1j9rs8Xr1xCF9rJa4rKwsxWrZ7urZ3Ar9xJrsY9345 uw4FkFy29ry5KjkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUvcSsGvfC2KfnxnUUI43ZEXa7xREWrW3UUUUU== X-Originating-IP: [123.112.69.106] X-CM-SenderInfo: xqlhyxxdqjzvrlsqjii6rwjhhfrp/1tbiQwg7jFc7ajRQVQAAsL 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 | 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; } elfcorehdr_free(elfcorehdr_addr); 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; +fail: + elfcorehdr_free(elfcorehdr_addr); + return rc; } fs_initcall(vmcore_init); -- 2.25.1