linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] perf kmem: Fix memory leak in compact_gfp_flags()
@ 2019-10-16  8:38 Yunfeng Ye
  2019-10-16 13:04 ` Arnaldo Carvalho de Melo
  2019-10-21  6:26 ` [tip: perf/urgent] " tip-bot2 for Yunfeng Ye
  0 siblings, 2 replies; 7+ messages in thread
From: Yunfeng Ye @ 2019-10-16  8:38 UTC (permalink / raw)
  To: peterz, mingo, acme, mark.rutland, alexander.shishkin, jolsa, namhyung
  Cc: linux-kernel, hushiyuan, linfeilong

The memory @orig_flags is allocated by strdup(), it is freed on the
normal path, but leak to free on the error path.

Fix this by adding free(orig_flags) on the error path.

Signed-off-by: Yunfeng Ye <yeyunfeng@huawei.com>
---
 tools/perf/builtin-kmem.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/tools/perf/builtin-kmem.c b/tools/perf/builtin-kmem.c
index 1e61e353f579..9661671cc26e 100644
--- a/tools/perf/builtin-kmem.c
+++ b/tools/perf/builtin-kmem.c
@@ -691,6 +691,7 @@ static char *compact_gfp_flags(char *gfp_flags)
 			new = realloc(new_flags, len + strlen(cpt) + 2);
 			if (new == NULL) {
 				free(new_flags);
+				free(orig_flags);
 				return NULL;
 			}

-- 
2.7.4.3


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH] perf kmem: Fix memory leak in compact_gfp_flags()
  2019-10-16  8:38 [PATCH] perf kmem: Fix memory leak in compact_gfp_flags() Yunfeng Ye
@ 2019-10-16 13:04 ` Arnaldo Carvalho de Melo
  2019-10-16 13:09   ` Arnaldo Carvalho de Melo
  2019-10-21  6:26 ` [tip: perf/urgent] " tip-bot2 for Yunfeng Ye
  1 sibling, 1 reply; 7+ messages in thread
From: Arnaldo Carvalho de Melo @ 2019-10-16 13:04 UTC (permalink / raw)
  To: Yunfeng Ye
  Cc: peterz, mingo, mark.rutland, alexander.shishkin, jolsa, namhyung,
	linux-kernel, hushiyuan, linfeilong

Em Wed, Oct 16, 2019 at 04:38:45PM +0800, Yunfeng Ye escreveu:
> The memory @orig_flags is allocated by strdup(), it is freed on the
> normal path, but leak to free on the error path.

Are you using some tool to find out these problems? Or is it just visual
inspection?

- Arnaldo
 
> Fix this by adding free(orig_flags) on the error path.
> 
> Signed-off-by: Yunfeng Ye <yeyunfeng@huawei.com>
> ---
>  tools/perf/builtin-kmem.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/tools/perf/builtin-kmem.c b/tools/perf/builtin-kmem.c
> index 1e61e353f579..9661671cc26e 100644
> --- a/tools/perf/builtin-kmem.c
> +++ b/tools/perf/builtin-kmem.c
> @@ -691,6 +691,7 @@ static char *compact_gfp_flags(char *gfp_flags)
>  			new = realloc(new_flags, len + strlen(cpt) + 2);
>  			if (new == NULL) {
>  				free(new_flags);
> +				free(orig_flags);
>  				return NULL;
>  			}
> 
> -- 
> 2.7.4.3

-- 

- Arnaldo

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] perf kmem: Fix memory leak in compact_gfp_flags()
  2019-10-16 13:04 ` Arnaldo Carvalho de Melo
@ 2019-10-16 13:09   ` Arnaldo Carvalho de Melo
  2019-10-16 13:19     ` Yunfeng Ye
  0 siblings, 1 reply; 7+ messages in thread
From: Arnaldo Carvalho de Melo @ 2019-10-16 13:09 UTC (permalink / raw)
  To: Yunfeng Ye
  Cc: peterz, mingo, mark.rutland, alexander.shishkin, jolsa, namhyung,
	linux-kernel, hushiyuan, linfeilong

Em Wed, Oct 16, 2019 at 10:04:03AM -0300, Arnaldo Carvalho de Melo escreveu:
> Em Wed, Oct 16, 2019 at 04:38:45PM +0800, Yunfeng Ye escreveu:
> > The memory @orig_flags is allocated by strdup(), it is freed on the
> > normal path, but leak to free on the error path.
> 
> Are you using some tool to find out these problems? Or is it just visual
> inspection?

Anyway, applied after adding this to the commit log message:

Fixes: 0e11115644b3 ("perf kmem: Print gfp flags in human readable string")

- Arnaldo
 
> - Arnaldo
>  
> > Fix this by adding free(orig_flags) on the error path.
> > 
> > Signed-off-by: Yunfeng Ye <yeyunfeng@huawei.com>
> > ---
> >  tools/perf/builtin-kmem.c | 1 +
> >  1 file changed, 1 insertion(+)
> > 
> > diff --git a/tools/perf/builtin-kmem.c b/tools/perf/builtin-kmem.c
> > index 1e61e353f579..9661671cc26e 100644
> > --- a/tools/perf/builtin-kmem.c
> > +++ b/tools/perf/builtin-kmem.c
> > @@ -691,6 +691,7 @@ static char *compact_gfp_flags(char *gfp_flags)
> >  			new = realloc(new_flags, len + strlen(cpt) + 2);
> >  			if (new == NULL) {
> >  				free(new_flags);
> > +				free(orig_flags);
> >  				return NULL;
> >  			}
> > 
> > -- 
> > 2.7.4.3
> 
> -- 
> 
> - Arnaldo

-- 

- Arnaldo

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] perf kmem: Fix memory leak in compact_gfp_flags()
  2019-10-16 13:09   ` Arnaldo Carvalho de Melo
@ 2019-10-16 13:19     ` Yunfeng Ye
  2019-10-16 14:08       ` Arnaldo Carvalho de Melo
  0 siblings, 1 reply; 7+ messages in thread
From: Yunfeng Ye @ 2019-10-16 13:19 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: peterz, mingo, mark.rutland, alexander.shishkin, jolsa, namhyung,
	linux-kernel, hushiyuan, linfeilong



On 2019/10/16 21:09, Arnaldo Carvalho de Melo wrote:
> Em Wed, Oct 16, 2019 at 10:04:03AM -0300, Arnaldo Carvalho de Melo escreveu:
>> Em Wed, Oct 16, 2019 at 04:38:45PM +0800, Yunfeng Ye escreveu:
>>> The memory @orig_flags is allocated by strdup(), it is freed on the
>>> normal path, but leak to free on the error path.
>>
>> Are you using some tool to find out these problems? Or is it just visual
>> inspection?
> 
By a static code anaylsis tool which not an open source tool. thanks.

> Anyway, applied after adding this to the commit log message:
> 
> Fixes: 0e11115644b3 ("perf kmem: Print gfp flags in human readable string")
> 
ok, thanks.

> - Arnaldo
>  
>> - Arnaldo
>>  
>>> Fix this by adding free(orig_flags) on the error path.
>>>
>>> Signed-off-by: Yunfeng Ye <yeyunfeng@huawei.com>
>>> ---
>>>  tools/perf/builtin-kmem.c | 1 +
>>>  1 file changed, 1 insertion(+)
>>>
>>> diff --git a/tools/perf/builtin-kmem.c b/tools/perf/builtin-kmem.c
>>> index 1e61e353f579..9661671cc26e 100644
>>> --- a/tools/perf/builtin-kmem.c
>>> +++ b/tools/perf/builtin-kmem.c
>>> @@ -691,6 +691,7 @@ static char *compact_gfp_flags(char *gfp_flags)
>>>  			new = realloc(new_flags, len + strlen(cpt) + 2);
>>>  			if (new == NULL) {
>>>  				free(new_flags);
>>> +				free(orig_flags);
>>>  				return NULL;
>>>  			}
>>>
>>> -- 
>>> 2.7.4.3
>>
>> -- 
>>
>> - Arnaldo
> 


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] perf kmem: Fix memory leak in compact_gfp_flags()
  2019-10-16 13:19     ` Yunfeng Ye
@ 2019-10-16 14:08       ` Arnaldo Carvalho de Melo
  2019-10-16 14:17         ` Yunfeng Ye
  0 siblings, 1 reply; 7+ messages in thread
From: Arnaldo Carvalho de Melo @ 2019-10-16 14:08 UTC (permalink / raw)
  To: Yunfeng Ye
  Cc: Arnaldo Carvalho de Melo, peterz, mingo, mark.rutland,
	alexander.shishkin, jolsa, namhyung, linux-kernel, hushiyuan,
	linfeilong

Em Wed, Oct 16, 2019 at 09:19:54PM +0800, Yunfeng Ye escreveu:
> 
> 
> On 2019/10/16 21:09, Arnaldo Carvalho de Melo wrote:
> > Em Wed, Oct 16, 2019 at 10:04:03AM -0300, Arnaldo Carvalho de Melo escreveu:
> >> Em Wed, Oct 16, 2019 at 04:38:45PM +0800, Yunfeng Ye escreveu:
> >>> The memory @orig_flags is allocated by strdup(), it is freed on the
> >>> normal path, but leak to free on the error path.
> >>
> >> Are you using some tool to find out these problems? Or is it just visual
> >> inspection?
> > 
> By a static code anaylsis tool which not an open source tool. thanks.

Ok, so please state that next time, just for the fullest possible
disclosure and for people to realize to what extent problems in the
kernel and in tooling hosted in the kernel is being fixed by such tools.

I.e. you don't need to release the tool, not even give out its name,
just something like:

"Found by internal static analysis tool."

Thanks,

- Arnaldo
 
> > Anyway, applied after adding this to the commit log message:
> > 
> > Fixes: 0e11115644b3 ("perf kmem: Print gfp flags in human readable string")
> > 
> ok, thanks.
> 
> > - Arnaldo
> >  
> >> - Arnaldo
> >>  
> >>> Fix this by adding free(orig_flags) on the error path.
> >>>
> >>> Signed-off-by: Yunfeng Ye <yeyunfeng@huawei.com>
> >>> ---
> >>>  tools/perf/builtin-kmem.c | 1 +
> >>>  1 file changed, 1 insertion(+)
> >>>
> >>> diff --git a/tools/perf/builtin-kmem.c b/tools/perf/builtin-kmem.c
> >>> index 1e61e353f579..9661671cc26e 100644
> >>> --- a/tools/perf/builtin-kmem.c
> >>> +++ b/tools/perf/builtin-kmem.c
> >>> @@ -691,6 +691,7 @@ static char *compact_gfp_flags(char *gfp_flags)
> >>>  			new = realloc(new_flags, len + strlen(cpt) + 2);
> >>>  			if (new == NULL) {
> >>>  				free(new_flags);
> >>> +				free(orig_flags);
> >>>  				return NULL;
> >>>  			}
> >>>
> >>> -- 
> >>> 2.7.4.3
> >>
> >> -- 
> >>
> >> - Arnaldo
> > 

-- 

- Arnaldo

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] perf kmem: Fix memory leak in compact_gfp_flags()
  2019-10-16 14:08       ` Arnaldo Carvalho de Melo
@ 2019-10-16 14:17         ` Yunfeng Ye
  0 siblings, 0 replies; 7+ messages in thread
From: Yunfeng Ye @ 2019-10-16 14:17 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: peterz, mingo, mark.rutland, alexander.shishkin, jolsa, namhyung,
	linux-kernel, hushiyuan, linfeilong



On 2019/10/16 22:08, Arnaldo Carvalho de Melo wrote:
> Em Wed, Oct 16, 2019 at 09:19:54PM +0800, Yunfeng Ye escreveu:
>>
>>
>> On 2019/10/16 21:09, Arnaldo Carvalho de Melo wrote:
>>> Em Wed, Oct 16, 2019 at 10:04:03AM -0300, Arnaldo Carvalho de Melo escreveu:
>>>> Em Wed, Oct 16, 2019 at 04:38:45PM +0800, Yunfeng Ye escreveu:
>>>>> The memory @orig_flags is allocated by strdup(), it is freed on the
>>>>> normal path, but leak to free on the error path.
>>>>
>>>> Are you using some tool to find out these problems? Or is it just visual
>>>> inspection?
>>>
>> By a static code anaylsis tool which not an open source tool. thanks.
> 
> Ok, so please state that next time, just for the fullest possible
> disclosure and for people to realize to what extent problems in the
> kernel and in tooling hosted in the kernel is being fixed by such tools.
> 
> I.e. you don't need to release the tool, not even give out its name,
> just something like:
> 
> "Found by internal static analysis tool."
> 
ok, thanks.

> Thanks,
> 
> - Arnaldo
>  
>>> Anyway, applied after adding this to the commit log message:
>>>
>>> Fixes: 0e11115644b3 ("perf kmem: Print gfp flags in human readable string")
>>>
>> ok, thanks.
>>
>>> - Arnaldo
>>>  
>>>> - Arnaldo
>>>>  
>>>>> Fix this by adding free(orig_flags) on the error path.
>>>>>
>>>>> Signed-off-by: Yunfeng Ye <yeyunfeng@huawei.com>
>>>>> ---
>>>>>  tools/perf/builtin-kmem.c | 1 +
>>>>>  1 file changed, 1 insertion(+)
>>>>>
>>>>> diff --git a/tools/perf/builtin-kmem.c b/tools/perf/builtin-kmem.c
>>>>> index 1e61e353f579..9661671cc26e 100644
>>>>> --- a/tools/perf/builtin-kmem.c
>>>>> +++ b/tools/perf/builtin-kmem.c
>>>>> @@ -691,6 +691,7 @@ static char *compact_gfp_flags(char *gfp_flags)
>>>>>  			new = realloc(new_flags, len + strlen(cpt) + 2);
>>>>>  			if (new == NULL) {
>>>>>  				free(new_flags);
>>>>> +				free(orig_flags);
>>>>>  				return NULL;
>>>>>  			}
>>>>>
>>>>> -- 
>>>>> 2.7.4.3
>>>>
>>>> -- 
>>>>
>>>> - Arnaldo
>>>
> 


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [tip: perf/urgent] perf kmem: Fix memory leak in compact_gfp_flags()
  2019-10-16  8:38 [PATCH] perf kmem: Fix memory leak in compact_gfp_flags() Yunfeng Ye
  2019-10-16 13:04 ` Arnaldo Carvalho de Melo
@ 2019-10-21  6:26 ` tip-bot2 for Yunfeng Ye
  1 sibling, 0 replies; 7+ messages in thread
From: tip-bot2 for Yunfeng Ye @ 2019-10-21  6:26 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: Yunfeng Ye, Alexander Shishkin, Feilong Lin, Hu Shiyuan,
	Jiri Olsa, Mark Rutland, Namhyung Kim, Peter Zijlstra,
	Arnaldo Carvalho de Melo, Ingo Molnar, Borislav Petkov,
	linux-kernel

The following commit has been merged into the perf/urgent branch of tip:

Commit-ID:     1abecfcaa7bba21c9985e0136fa49836164dd8fd
Gitweb:        https://git.kernel.org/tip/1abecfcaa7bba21c9985e0136fa49836164dd8fd
Author:        Yunfeng Ye <yeyunfeng@huawei.com>
AuthorDate:    Wed, 16 Oct 2019 16:38:45 +08:00
Committer:     Arnaldo Carvalho de Melo <acme@redhat.com>
CommitterDate: Wed, 16 Oct 2019 10:08:32 -03:00

perf kmem: Fix memory leak in compact_gfp_flags()

The memory @orig_flags is allocated by strdup(), it is freed on the
normal path, but leak to free on the error path.

Fix this by adding free(orig_flags) on the error path.

Fixes: 0e11115644b3 ("perf kmem: Print gfp flags in human readable string")
Signed-off-by: Yunfeng Ye <yeyunfeng@huawei.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Feilong Lin <linfeilong@huawei.com>
Cc: Hu Shiyuan <hushiyuan@huawei.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lore.kernel.org/lkml/f9e9f458-96f3-4a97-a1d5-9feec2420e07@huawei.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/builtin-kmem.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/tools/perf/builtin-kmem.c b/tools/perf/builtin-kmem.c
index 1e61e35..9661671 100644
--- a/tools/perf/builtin-kmem.c
+++ b/tools/perf/builtin-kmem.c
@@ -691,6 +691,7 @@ static char *compact_gfp_flags(char *gfp_flags)
 			new = realloc(new_flags, len + strlen(cpt) + 2);
 			if (new == NULL) {
 				free(new_flags);
+				free(orig_flags);
 				return NULL;
 			}
 

^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2019-10-21  6:27 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-16  8:38 [PATCH] perf kmem: Fix memory leak in compact_gfp_flags() Yunfeng Ye
2019-10-16 13:04 ` Arnaldo Carvalho de Melo
2019-10-16 13:09   ` Arnaldo Carvalho de Melo
2019-10-16 13:19     ` Yunfeng Ye
2019-10-16 14:08       ` Arnaldo Carvalho de Melo
2019-10-16 14:17         ` Yunfeng Ye
2019-10-21  6:26 ` [tip: perf/urgent] " tip-bot2 for Yunfeng Ye

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).