2022-11-15 02:55:07

by Xiu Jianfeng

[permalink] [raw]
Subject: [PATCH] tracing/user_events: Fix memory leak in user_event_create()

Before current_user_event_group(), it has allocated memory and save it
in @name, this should freed before return error.

Fixes: e5d271812e7a ("tracing/user_events: Move pages/locks into groups to prepare for namespaces")
Signed-off-by: Xiu Jianfeng <[email protected]>
---
kernel/trace/trace_events_user.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/kernel/trace/trace_events_user.c b/kernel/trace/trace_events_user.c
index ae78c2d53c8a..539b08ae7020 100644
--- a/kernel/trace/trace_events_user.c
+++ b/kernel/trace/trace_events_user.c
@@ -1100,8 +1100,10 @@ static int user_event_create(const char *raw_command)

group = current_user_event_group();

- if (!group)
+ if (!group) {
+ kfree(name);
return -ENOENT;
+ }

mutex_lock(&group->reg_mutex);

--
2.17.1



2022-11-15 15:18:58

by Masami Hiramatsu

[permalink] [raw]
Subject: Re: [PATCH] tracing/user_events: Fix memory leak in user_event_create()

On Tue, 15 Nov 2022 09:44:45 +0800
Xiu Jianfeng <[email protected]> wrote:

> Before current_user_event_group(), it has allocated memory and save it
> in @name, this should freed before return error.
>
> Fixes: e5d271812e7a ("tracing/user_events: Move pages/locks into groups to prepare for namespaces")
> Signed-off-by: Xiu Jianfeng <[email protected]>

This looks good to me.

Acked-by: Masami Hiramatsu (Google) <[email protected]>

Thanks,

> ---
> kernel/trace/trace_events_user.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/kernel/trace/trace_events_user.c b/kernel/trace/trace_events_user.c
> index ae78c2d53c8a..539b08ae7020 100644
> --- a/kernel/trace/trace_events_user.c
> +++ b/kernel/trace/trace_events_user.c
> @@ -1100,8 +1100,10 @@ static int user_event_create(const char *raw_command)
>
> group = current_user_event_group();
>
> - if (!group)
> + if (!group) {
> + kfree(name);
> return -ENOENT;
> + }
>
> mutex_lock(&group->reg_mutex);
>
> --
> 2.17.1
>


--
Masami Hiramatsu (Google) <[email protected]>

2022-11-15 17:19:28

by Beau Belgrave

[permalink] [raw]
Subject: Re: [PATCH] tracing/user_events: Fix memory leak in user_event_create()

On Wed, Nov 16, 2022 at 12:07:17AM +0900, Masami Hiramatsu wrote:
> On Tue, 15 Nov 2022 09:44:45 +0800
> Xiu Jianfeng <[email protected]> wrote:
>
> > Before current_user_event_group(), it has allocated memory and save it
> > in @name, this should freed before return error.
> >

Nice catch!

Acked-by: Beau Belgrave <[email protected]>

Thanks,
-Beau

> > Fixes: e5d271812e7a ("tracing/user_events: Move pages/locks into groups to prepare for namespaces")
> > Signed-off-by: Xiu Jianfeng <[email protected]>
>
> This looks good to me.
>
> Acked-by: Masami Hiramatsu (Google) <[email protected]>
>
> Thanks,
>
> > ---
> > kernel/trace/trace_events_user.c | 4 +++-
> > 1 file changed, 3 insertions(+), 1 deletion(-)
> >
> > diff --git a/kernel/trace/trace_events_user.c b/kernel/trace/trace_events_user.c
> > index ae78c2d53c8a..539b08ae7020 100644
> > --- a/kernel/trace/trace_events_user.c
> > +++ b/kernel/trace/trace_events_user.c
> > @@ -1100,8 +1100,10 @@ static int user_event_create(const char *raw_command)
> >
> > group = current_user_event_group();
> >
> > - if (!group)
> > + if (!group) {
> > + kfree(name);
> > return -ENOENT;
> > + }
> >
> > mutex_lock(&group->reg_mutex);
> >
> > --
> > 2.17.1
> >
>
>
> --
> Masami Hiramatsu (Google) <[email protected]>