From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 61B5AC04A95 for ; Thu, 29 Sep 2022 04:30:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234726AbiI2E36 (ORCPT ); Thu, 29 Sep 2022 00:29:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36338 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234606AbiI2E3x (ORCPT ); Thu, 29 Sep 2022 00:29:53 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C047D43636 for ; Wed, 28 Sep 2022 21:29:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1664425790; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=MQ6eVGHIuPCxsfzLZ7r6f4XtIMBx2hQBbA300A4TTy0=; b=NYTIFQxTl+b50fag2hWlA+xvS68UGO8lxn7E3ag95wvrR4O3RY1R9B9fLDoFWcVVkRShIj v9xHGCSRH5jECSekq0Pg/3z5MAadmXQFlogAKb7Shczj4gL6Av6DP/sWCT0dVYM5t1f7mL WB/EJfoqJ7MTjgtsrbBfsUo9lvik3+Y= 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-663-x6xpR9HsPlutFSmX5-z1XQ-1; Thu, 29 Sep 2022 00:29:48 -0400 X-MC-Unique: x6xpR9HsPlutFSmX5-z1XQ-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3071981172A; Thu, 29 Sep 2022 04:29:48 +0000 (UTC) Received: from MiWiFi-R3L-srv.redhat.com (ovpn-13-179.pek2.redhat.com [10.72.13.179]) by smtp.corp.redhat.com (Postfix) with ESMTP id 206E87AE5; Thu, 29 Sep 2022 04:29:44 +0000 (UTC) From: Baoquan He To: linux-kernel@vger.kernel.org, akpm@linux-foundation.org Cc: kexec@lists.infradead.org, ebiederm@xmission.com, Jianglei Nie , Baoquan He Subject: [PATCH RESEND 1/4] proc/vmcore: fix potential memory leak in vmcore_init() Date: Thu, 29 Sep 2022 12:29:33 +0800 Message-Id: <20220929042936.22012-2-bhe@redhat.com> In-Reply-To: <20220929042936.22012-1-bhe@redhat.com> References: <20220929042936.22012-1-bhe@redhat.com> MIME-Version: 1.0 Content-type: text/plain Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jianglei Nie 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. Signed-off-by: Jianglei Nie Acked-by: Baoquan He Signed-off-by: Baoquan He --- 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.34.1