Message ID | 20230202151411.2308576-1-gregkh@linuxfoundation.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp300411wrn; Thu, 2 Feb 2023 07:22:12 -0800 (PST) X-Google-Smtp-Source: AK7set+OM+jd8fsz40gEc+TnRUGW6TMoDUMXe9Sx9HhiAJMxhaTY0vBBTPCYhugnGQ2Qsrvatiia X-Received: by 2002:a05:6a20:1592:b0:bc:f336:98ed with SMTP id h18-20020a056a20159200b000bcf33698edmr8992738pzj.45.1675351332523; Thu, 02 Feb 2023 07:22:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675351332; cv=none; d=google.com; s=arc-20160816; b=XWg9ZSVPf5HAczVXNuuQsZ45ydJlybHPdsLxIm1QSsxXZUbl4H4g8fuROyqisEDpNm JDs+CKTbia2GqziLyD23LnGSF53DLqwAXDlBL3n57BmuDu1aZSDMZq/a3ACvQIuXllcR 7+mf1O/+yjSIBIWWZK6U/qlCt7rNQOXc/OOSG46aWDbt7pSGyxYNKcAtkOP1YlaKJEHH jl93j4khXMepHiUbz+Zv9Oz/q/iX+STpLn6x234Spit1uRhamlspoZt1pQexkRBnDGis Yce0VD2fBXE9MOzp+X6HX2b/FP0lIEBX94NKFkRDZHSXPPZEAEXxRtbiKmsrk9xVaPCi 6drw== 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=He4N0mQ8FTRsQ3cnKDmZqt0mXJQK8M8TmQHqpvglSSM=; b=P3mJO7ojpvMIPxwaM3y6JznlLC1qBjfZ+QHTW+zcpbf/4G3nT5PB7HmKc2vSG9RHn7 3HA3j1Ryqgv3ZqjWB+NqiSnBs4Fts9jLZKygUH1qo/UYn6ECCGh1VVTZA3GUKaVQJdgM OYvmPGYyIEzttNh54kC4zHyUjAu3p0r5KRPNAmr/0G3ujO76kmGaLVVfO2THG79PP6U0 1j0gQrf1p5U4O7Iw9m1nfaQa4GiDRmFYOrJ8HAlHLwFsBrSZiIbBcAjThV2ptYKvfQDT nN3UNc2pqdV5RU+T9c8L7i5Xad0Gt5lxpjhRxkYYmhD3EwiccatHQwJKSTdIYBRLjtbX gZaA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=YZHnWClZ; 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=linuxfoundation.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u1-20020a170902e5c100b0017f59ed2dfasi26477541plf.63.2023.02.02.07.21.59; Thu, 02 Feb 2023 07:22:12 -0800 (PST) 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=@linuxfoundation.org header.s=korg header.b=YZHnWClZ; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232605AbjBBPOZ (ORCPT <rfc822;il.mystafa@gmail.com> + 99 others); Thu, 2 Feb 2023 10:14:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58012 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229972AbjBBPOV (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 2 Feb 2023 10:14:21 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1392140C7 for <linux-kernel@vger.kernel.org>; Thu, 2 Feb 2023 07:14:20 -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 ams.source.kernel.org (Postfix) with ESMTPS id BB4E9B8268F for <linux-kernel@vger.kernel.org>; Thu, 2 Feb 2023 15:14:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0FDCDC433D2; Thu, 2 Feb 2023 15:14:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1675350857; bh=PUTozbY7ITrcSJ91h8ZeqAGIKgz32oJvRkMU4DQE528=; h=From:To:Cc:Subject:Date:From; b=YZHnWClZfzooZfXNcIM4b5fTYzgWngMeBrOjM5tzdnwNLvtxtGMmQSUFGNNGd/FDn Ju7iC1LFOFEnbw1s6COIqXcNCnsET17sfZhJzT6SZMClOhO9XgL3LWLrPRu7GrBEAI A2FrjoGxCAW98XmojnyEywelfnuNIvPUGtEbbQBE= From: Greg Kroah-Hartman <gregkh@linuxfoundation.org> To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>, Chris Down <chris@chrisdown.name>, Petr Mladek <pmladek@suse.com>, Sergey Senozhatsky <senozhatsky@chromium.org>, Steven Rostedt <rostedt@goodmis.org>, John Ogness <john.ogness@linutronix.de> Subject: [PATCH] kernel/printk/index.c: fix memory leak with using debugfs_lookup() Date: Thu, 2 Feb 2023 16:14:11 +0100 Message-Id: <20230202151411.2308576-1-gregkh@linuxfoundation.org> X-Mailer: git-send-email 2.39.1 MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1164; i=gregkh@linuxfoundation.org; h=from:subject; bh=PUTozbY7ITrcSJ91h8ZeqAGIKgz32oJvRkMU4DQE528=; b=owGbwMvMwCRo6H6F97bub03G02pJDMm3LzsXq1lWH1ee0z7r5pPTm9KfPnvxPE16Ju/ujQYLTmbx ncnU6ohlYRBkYpAVU2T5so3n6P6KQ4pehranYeawMoEMYeDiFICJ8HswLLjwTWj1o8Qva505157j2M rUk1xo9oxhfv32udFSMY5M01czTe0K5DFryc8yBQA= X-Developer-Key: i=gregkh@linuxfoundation.org; a=openpgp; fpr=F4B60CC5BF78C2214A313DCB3147D40DDB2DFB29 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756733198974622875?= X-GMAIL-MSGID: =?utf-8?q?1756733198974622875?= |
Series |
kernel/printk/index.c: fix memory leak with using debugfs_lookup()
|
|
Commit Message
Greg KH
Feb. 2, 2023, 3:14 p.m. UTC
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 <chris@chrisdown.name>
Cc: Petr Mladek <pmladek@suse.com>
Cc: Sergey Senozhatsky <senozhatsky@chromium.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: John Ogness <john.ogness@linutronix.de>
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
kernel/printk/index.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
Comments
On (23/02/02 16:14), Greg Kroah-Hartman wrote: > > 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 <chris@chrisdown.name> > Cc: Petr Mladek <pmladek@suse.com> > Cc: Sergey Senozhatsky <senozhatsky@chromium.org> > Cc: Steven Rostedt <rostedt@goodmis.org> > Cc: John Ogness <john.ogness@linutronix.de> > Cc: linux-kernel@vger.kernel.org > Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Reviewed-by: Sergey Senozhatsky <senozhatsky@chromium.org>
On 2023-02-02, Greg Kroah-Hartman <gregkh@linuxfoundation.org> wrote: > 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 <chris@chrisdown.name> > Cc: Petr Mladek <pmladek@suse.com> > Cc: Sergey Senozhatsky <senozhatsky@chromium.org> > Cc: Steven Rostedt <rostedt@goodmis.org> > Cc: John Ogness <john.ogness@linutronix.de> > Cc: linux-kernel@vger.kernel.org > Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Reviewed-by: John Ogness <john.ogness@linutronix.de>
On Thu 2023-02-02 16:14:11, Greg Kroah-Hartman wrote: > 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 <chris@chrisdown.name> > Cc: Petr Mladek <pmladek@suse.com> > Cc: Sergey Senozhatsky <senozhatsky@chromium.org> > Cc: Steven Rostedt <rostedt@goodmis.org> > Cc: John Ogness <john.ogness@linutronix.de> > Cc: linux-kernel@vger.kernel.org > Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Reviewed-by: Petr Mladek <pmladek@suse.com> Best Regards, Petr
On Thu 2023-02-02 16:14:11, Greg Kroah-Hartman wrote: > 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 <chris@chrisdown.name> > Cc: Petr Mladek <pmladek@suse.com> > Cc: Sergey Senozhatsky <senozhatsky@chromium.org> > Cc: Steven Rostedt <rostedt@goodmis.org> > Cc: John Ogness <john.ogness@linutronix.de> > Cc: linux-kernel@vger.kernel.org > Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> JFYI, the patch has been committed into printk/linux.git, branch for-6.3. Best Regards, Petr
On Fri, Feb 03, 2023 at 11:16:17AM +0100, Petr Mladek wrote: > On Thu 2023-02-02 16:14:11, Greg Kroah-Hartman wrote: > > 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 <chris@chrisdown.name> > > Cc: Petr Mladek <pmladek@suse.com> > > Cc: Sergey Senozhatsky <senozhatsky@chromium.org> > > Cc: Steven Rostedt <rostedt@goodmis.org> > > Cc: John Ogness <john.ogness@linutronix.de> > > Cc: linux-kernel@vger.kernel.org > > Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> > > JFYI, the patch has been committed into printk/linux.git, branch for-6.3. Wonderful, thank you! greg k-h
diff --git a/kernel/printk/index.c b/kernel/printk/index.c index c85be186a783..a6b27526baaf 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,