2023-02-02 15:14:29

by Greg Kroah-Hartman

[permalink] [raw]
Subject: [PATCH] kernel/printk/index.c: fix memory leak with using debugfs_lookup()

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 <[email protected]>
Cc: Petr Mladek <[email protected]>
Cc: Sergey Senozhatsky <[email protected]>
Cc: Steven Rostedt <[email protected]>
Cc: John Ogness <[email protected]>
Cc: [email protected]
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
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 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,
--
2.39.1



2023-02-03 02:54:16

by Sergey Senozhatsky

[permalink] [raw]
Subject: Re: [PATCH] kernel/printk/index.c: fix memory leak with using debugfs_lookup()

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 <[email protected]>
> Cc: Petr Mladek <[email protected]>
> Cc: Sergey Senozhatsky <[email protected]>
> Cc: Steven Rostedt <[email protected]>
> Cc: John Ogness <[email protected]>
> Cc: [email protected]
> Signed-off-by: Greg Kroah-Hartman <[email protected]>

Reviewed-by: Sergey Senozhatsky <[email protected]>

2023-02-03 09:12:19

by John Ogness

[permalink] [raw]
Subject: Re: [PATCH] kernel/printk/index.c: fix memory leak with using debugfs_lookup()

On 2023-02-02, Greg Kroah-Hartman <[email protected]> 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 <[email protected]>
> Cc: Petr Mladek <[email protected]>
> Cc: Sergey Senozhatsky <[email protected]>
> Cc: Steven Rostedt <[email protected]>
> Cc: John Ogness <[email protected]>
> Cc: [email protected]
> Signed-off-by: Greg Kroah-Hartman <[email protected]>

Reviewed-by: John Ogness <[email protected]>

2023-02-03 09:41:31

by Petr Mladek

[permalink] [raw]
Subject: Re: [PATCH] kernel/printk/index.c: fix memory leak with using debugfs_lookup()

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 <[email protected]>
> Cc: Petr Mladek <[email protected]>
> Cc: Sergey Senozhatsky <[email protected]>
> Cc: Steven Rostedt <[email protected]>
> Cc: John Ogness <[email protected]>
> Cc: [email protected]
> Signed-off-by: Greg Kroah-Hartman <[email protected]>

Reviewed-by: Petr Mladek <[email protected]>

Best Regards,
Petr


2023-02-03 10:16:44

by Petr Mladek

[permalink] [raw]
Subject: Re: [PATCH] kernel/printk/index.c: fix memory leak with using debugfs_lookup()

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 <[email protected]>
> Cc: Petr Mladek <[email protected]>
> Cc: Sergey Senozhatsky <[email protected]>
> Cc: Steven Rostedt <[email protected]>
> Cc: John Ogness <[email protected]>
> Cc: [email protected]
> Signed-off-by: Greg Kroah-Hartman <[email protected]>

JFYI, the patch has been committed into printk/linux.git, branch for-6.3.

Best Regards,
Petr

2023-02-08 12:21:11

by Greg Kroah-Hartman

[permalink] [raw]
Subject: Re: [PATCH] kernel/printk/index.c: fix memory leak with using debugfs_lookup()

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 <[email protected]>
> > Cc: Petr Mladek <[email protected]>
> > Cc: Sergey Senozhatsky <[email protected]>
> > Cc: Steven Rostedt <[email protected]>
> > Cc: John Ogness <[email protected]>
> > Cc: [email protected]
> > Signed-off-by: Greg Kroah-Hartman <[email protected]>
>
> JFYI, the patch has been committed into printk/linux.git, branch for-6.3.

Wonderful, thank you!

greg k-h