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 77783C7EE32 for ; Wed, 1 Mar 2023 16:30:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229907AbjCAQaE (ORCPT ); Wed, 1 Mar 2023 11:30:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49352 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229870AbjCAQ3q (ORCPT ); Wed, 1 Mar 2023 11:29:46 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EECC742BFA; Wed, 1 Mar 2023 08:29:44 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 7E14C61419; Wed, 1 Mar 2023 16:29:44 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 084A6C4339B; Wed, 1 Mar 2023 16:29:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1677688183; bh=QUVyWcpNPiRRb0YcbMLuwPP4ifg6zlz8Ly/SlacKjmk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IcEt2bi7F1NHZrxlU4C+XxJ3LTRt/c/sh9OE/VtfQM42C8tbMk2j+tI5sD76f4k1b BFa1Az3CJFoQ6fDyU1WAXvpVsO51skiJ8f0KqXmkhoofnfxbyxB4p5TZlNLsxxjYIh DowRGkkDH50gABD68AVDhNWp8DBt4PkGF+Zp++2DeLFdy58XOUTr0+YaRejTtob8Dt CoKEe5FURuPswcFk3UGxFsLinms0VN74Us6ej27QqdmgnDxQIARHU5fYlXJ5+J1usG AGC5gSEJjiZ2bemi+EHoHGU/CL2M1MfG6a7I022uCLqVaCCXHZ/uMGyGysfrclkhWv a2ItCjz7S0/Aw== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Greg Kroah-Hartman , Chris Down , Petr Mladek , Sergey Senozhatsky , Steven Rostedt , John Ogness , Sasha Levin Subject: [PATCH AUTOSEL 6.1 3/6] kernel/printk/index.c: fix memory leak with using debugfs_lookup() Date: Wed, 1 Mar 2023 11:29:35 -0500 Message-Id: <20230301162938.1302886-3-sashal@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230301162938.1302886-1-sashal@kernel.org> References: <20230301162938.1302886-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Greg Kroah-Hartman [ Upstream commit 55bf243c514553e907efcf2bda92ba090eca8c64 ] When calling debugfs_lookup() the result must have dput() called on it, otherwise the memory will leak over time. To make things simpler, just call debugfs_lookup_and_remove() instead which handles all of the logic at once. Cc: Chris Down Cc: Petr Mladek Cc: Sergey Senozhatsky Cc: Steven Rostedt Cc: John Ogness Cc: linux-kernel@vger.kernel.org Signed-off-by: Greg Kroah-Hartman Reviewed-by: Sergey Senozhatsky Reviewed-by: John Ogness Reviewed-by: Petr Mladek Signed-off-by: Petr Mladek Link: https://lore.kernel.org/r/20230202151411.2308576-1-gregkh@linuxfoundation.org Signed-off-by: Sasha Levin --- kernel/printk/index.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/printk/index.c b/kernel/printk/index.c index c85be186a7832..a6b27526baaf6 100644 --- a/kernel/printk/index.c +++ b/kernel/printk/index.c @@ -145,7 +145,7 @@ static void pi_create_file(struct module *mod) #ifdef CONFIG_MODULES static void pi_remove_file(struct module *mod) { - debugfs_remove(debugfs_lookup(pi_get_module_name(mod), dfs_index)); + debugfs_lookup_and_remove(pi_get_module_name(mod), dfs_index); } static int pi_module_notify(struct notifier_block *nb, unsigned long op, -- 2.39.2