Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp7327515rwn; Tue, 13 Sep 2022 18:40:26 -0700 (PDT) X-Google-Smtp-Source: AMsMyM69sVK+8D8AIzs4QumXvo9NMyVj0yySwX+BgPqacRrznlJXUaPjTKgqytITURCxNEgV/xB5 X-Received: by 2002:a17:90a:c258:b0:202:b93b:cb89 with SMTP id d24-20020a17090ac25800b00202b93bcb89mr2094793pjx.126.1663119626620; Tue, 13 Sep 2022 18:40:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663119626; cv=none; d=google.com; s=arc-20160816; b=ldswwLkYIHbR4YK81x/849gfm6IxKiqmMwBtNeongd0DzFEudyZZdyxeVrXK+v4bk1 5kumsnNvNAqlQDc92nn/apQG4pMFuSpDdGOKBVl5Yw44QEm9eE4mvCOTZO4JvqOoS6/2 1YbaMhhE35nhn/8WRNcYsxShX2H+d+1UEWrS1c6LkHoIVC903xl2ZzO5EenzFdlQgIRE uJop5riEWEoW93pXyKR+5LL2R40llIZea6IXxk+U+BAvVLvGzln249ufEW+bBAp2aGYi xVPkLsPXsoFQoaCE3OhG+1d3b6k1QJIcXEt04aVk8iS/X9bImCxIsL0YagkUUeu6flGY RmOg== 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=KqodMYrOFpEVlmPN5U59wZd+Mb7IJb+e/Mld+L/PKCU=; b=hHmvj06K+fuk9ZaXYzHM3P61wTfrDtj4TZ8vCnjNyc7Vkx6yiy9Z+o7bDzDpl4Vn56 fp54wz4QfZJt5qbOdqhc/w5h78e9hOkmp1IUFee5XFHlzDajXhAF/FqpTBX2qC4nJmww NBKuZGoFNog1hX3MZDDB4FvrvIKkLvitw1hlX/tuInpeah/qb0neZAJ6AOoE0VE1E7WS yaigiH+crbmhPGennBgFCYkcLXlgUzG7fXaSlbXuYwtD9Zv+p8lw6SxBmzVT+c00OV1J UUVcehahe9sFH2Sf14pmekUkJxUXaUA/bttWIJst3GPLZIWz2TfDYDe9Yg4Sr/n004Gl +eUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=CPZrAAyh; 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 d18-20020a170902ced200b0016c00834dd5si8374191plg.18.2022.09.13.18.40.14; Tue, 13 Sep 2022 18:40:26 -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=CPZrAAyh; 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 S229902AbiINBdl (ORCPT + 99 others); Tue, 13 Sep 2022 21:33:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39680 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229599AbiINBdj (ORCPT ); Tue, 13 Sep 2022 21:33:39 -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 DD6056B8DF; Tue, 13 Sep 2022 18:33:37 -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=KqodM YrOFpEVlmPN5U59wZd+Mb7IJb+e/Mld+L/PKCU=; b=CPZrAAyhnjpBuCstJMvKh ZWhHoSdrtYuYC0g6TuPzYYyQUsQ1YKD2qcroJOZJm2tIrpIh+IbeAbDipJzDSblJ DVeRAG88NcK0/hEtbhRUFKjmG+Bg3soE576TdBTIlXBKoZxfFiNj5mqHayfwqJfr 7mzrcEbwn97/q2ym+oqxME= Received: from localhost.localdomain (unknown [36.112.3.106]) by smtp1 (Coremail) with SMTP id GdxpCgDnUuVXLyFjD05gcg--.57701S4; Wed, 14 Sep 2022 09:33:25 +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 v2] proc/vmcore: fix potential memory leak in vmcore_init() Date: Wed, 14 Sep 2022 09:33:10 +0800 Message-Id: <20220914013310.6386-1-niejianglei2021@163.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: GdxpCgDnUuVXLyFjD05gcg--.57701S4 X-Coremail-Antispam: 1Uf129KBjvdXoWrKrWUtFW5Gw4xXFWfXr17Awb_yoWfZwb_Aa 18tF4xXw4rJan3GrWUKFy5tw4akr1j9rs8XF1fGF9rGFyrtwsxW3s7ZrZ3Ar97XrsYvry5 uwsakFy2934rGjkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUvcSsGvfC2KfnxnUUI43ZEXa7xR_sqWUUUUUU== X-Originating-IP: [36.112.3.106] X-CM-SenderInfo: xqlhyxxdqjzvrlsqjii6rwjhhfrp/1tbiFQZ8jF5mMjllDAAAs5 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 | 1 + 1 file changed, 1 insertion(+) diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c index f2aa86c421f2..74747571d58e 100644 --- a/fs/proc/vmcore.c +++ b/fs/proc/vmcore.c @@ -1567,6 +1567,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; } -- 2.25.1