Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1361316 > unrolled thread
| Started by | Leon Yu <chianglungyu@gmail.com> |
|---|---|
| First post | 2016-03-20 17:00 +0100 |
| Last post | 2016-03-31 11:30 +0200 |
| Articles | 4 — 3 participants |
Back to article view | Back to linux.kernel
[PATCH] perf: fix event leak when perf_event_open() failed to create event_file Leon Yu <chianglungyu@gmail.com> - 2016-03-20 17:00 +0100
Re: [PATCH] perf: fix event leak when perf_event_open() failed to create event_file Alexander Shishkin <alexander.shishkin@linux.intel.com> - 2016-03-21 09:10 +0100
Re: [PATCH] perf: fix event leak when perf_event_open() failed to create event_file Leon Yu <chianglungyu@gmail.com> - 2016-03-21 16:30 +0100
[tip:perf/core] perf/core: Don't leak event in the syscall error path tip-bot for Alexander Shishkin <tipbot@zytor.com> - 2016-03-31 11:30 +0200
| From | Leon Yu <chianglungyu@gmail.com> |
|---|---|
| Date | 2016-03-20 17:00 +0100 |
| Subject | [PATCH] perf: fix event leak when perf_event_open() failed to create event_file |
| Message-ID | <reNVM-sU-19@gated-at.bofh.it> |
If something went wrong in anon_inode_getfile, event_file will be set to
non-zero error number and able to bypass the NULL test afterward.
Consolidate the error path by testing event_file with handly
IS_ERR_OR_NULL() helper since we do want to free event in both cases.
Signed-off-by: Leon Yu <chianglungyu@gmail.com>
Fixes: 130056275ade ("perf: Do not double free")
Cc: <stable@vger.kernel.org> # v4.5
---
kernel/events/core.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/kernel/events/core.c b/kernel/events/core.c
index 6146148..5f2e19f 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -8617,7 +8617,7 @@ err_alloc:
* If event_file is set, the fput() above will have called ->release()
* and that will take care of freeing the event.
*/
- if (!event_file)
+ if (IS_ERR_OR_NULL(event_file))
free_event(event);
err_cpus:
put_online_cpus();
--
2.7.1
[toc] | [next] | [standalone]
| From | Alexander Shishkin <alexander.shishkin@linux.intel.com> |
|---|---|
| Date | 2016-03-21 09:10 +0100 |
| Message-ID | <rf34u-2NK-11@gated-at.bofh.it> |
| In reply to | #1361316 |
Leon Yu <chianglungyu@gmail.com> writes:
> If something went wrong in anon_inode_getfile, event_file will be set to
> non-zero error number and able to bypass the NULL test afterward.
>
> Consolidate the error path by testing event_file with handly
> IS_ERR_OR_NULL() helper since we do want to free event in both cases.
>
> Signed-off-by: Leon Yu <chianglungyu@gmail.com>
> Fixes: 130056275ade ("perf: Do not double free")
> Cc: <stable@vger.kernel.org> # v4.5
> ---
> kernel/events/core.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/kernel/events/core.c b/kernel/events/core.c
> index 6146148..5f2e19f 100644
> --- a/kernel/events/core.c
> +++ b/kernel/events/core.c
> @@ -8617,7 +8617,7 @@ err_alloc:
> * If event_file is set, the fput() above will have called ->release()
> * and that will take care of freeing the event.
> */
> - if (!event_file)
> + if (IS_ERR_OR_NULL(event_file))
> free_event(event);
By this time, we have already checked for IS_ERR(event_file) once, why
not just fix it up there like so:
---
From: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Date: Mon, 21 Mar 2016 09:55:09 +0200
Subject: perf: Don't leak event in the syscall error path
In the error path, event_file not being NULL is used to determine
whether the event itself still needs to be free'd, so fix it up to avoid
leaking.
Reported-by: Leon Yu <chianglungyu@gmail.com>
Fixes: 130056275ade ("perf: Do not double free")
Signed-off-by: Alexander Shishkin <alexander.shishkin@linux.intel.com>
---
kernel/events/core.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/kernel/events/core.c b/kernel/events/core.c
index ab83640a50..cc34d55f1e 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -9414,6 +9414,7 @@ SYSCALL_DEFINE5(perf_event_open,
f_flags);
if (IS_ERR(event_file)) {
err = PTR_ERR(event_file);
+ event_file = NULL;
goto err_context;
}
--
2.7.0
[toc] | [prev] | [next] | [standalone]
| From | Leon Yu <chianglungyu@gmail.com> |
|---|---|
| Date | 2016-03-21 16:30 +0100 |
| Subject | Re: [PATCH] perf: fix event leak when perf_event_open() failed to create event_file |
| Message-ID | <rf9Wi-7Az-19@gated-at.bofh.it> |
| In reply to | #1361571 |
On Mon, Mar 21, 2016 at 4:02 PM, Alexander Shishkin
<alexander.shishkin@linux.intel.com> wrote:
> Leon Yu <chianglungyu@gmail.com> writes:
>
>> If something went wrong in anon_inode_getfile, event_file will be set to
>> non-zero error number and able to bypass the NULL test afterward.
>>
>> Consolidate the error path by testing event_file with handly
>> IS_ERR_OR_NULL() helper since we do want to free event in both cases.
>>
>> Signed-off-by: Leon Yu <chianglungyu@gmail.com>
>> Fixes: 130056275ade ("perf: Do not double free")
>> Cc: <stable@vger.kernel.org> # v4.5
>> ---
>> kernel/events/core.c | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/kernel/events/core.c b/kernel/events/core.c
>> index 6146148..5f2e19f 100644
>> --- a/kernel/events/core.c
>> +++ b/kernel/events/core.c
>> @@ -8617,7 +8617,7 @@ err_alloc:
>> * If event_file is set, the fput() above will have called ->release()
>> * and that will take care of freeing the event.
>> */
>> - if (!event_file)
>> + if (IS_ERR_OR_NULL(event_file))
>> free_event(event);
>
> By this time, we have already checked for IS_ERR(event_file) once, why
> not just fix it up there like so:
My patch is more straightforward, isn't it? :p
Anyway I don't mind which one will get merged as long as the problem is fixed.
(sorry forgot to CC all recipients)
-Leon
> @@ -9414,6 +9414,7 @@ SYSCALL_DEFINE5(perf_event_open,
> f_flags);
> if (IS_ERR(event_file)) {
> err = PTR_ERR(event_file);
> + event_file = NULL;
> goto err_context;
> }
>
> --
> 2.7.0
>
[toc] | [prev] | [next] | [standalone]
| From | tip-bot for Alexander Shishkin <tipbot@zytor.com> |
|---|---|
| Date | 2016-03-31 11:30 +0200 |
| Subject | [tip:perf/core] perf/core: Don't leak event in the syscall error path |
| Message-ID | <riH5q-2PS-61@gated-at.bofh.it> |
| In reply to | #1361571 |
Commit-ID: 201c2f85bd0bc13b712d9c0b3d11251b182e06ae
Gitweb: http://git.kernel.org/tip/201c2f85bd0bc13b712d9c0b3d11251b182e06ae
Author: Alexander Shishkin <alexander.shishkin@linux.intel.com>
AuthorDate: Mon, 21 Mar 2016 10:02:42 +0200
Committer: Ingo Molnar <mingo@kernel.org>
CommitDate: Thu, 31 Mar 2016 09:54:07 +0200
perf/core: Don't leak event in the syscall error path
In the error path, event_file not being NULL is used to determine
whether the event itself still needs to be free'd, so fix it up to
avoid leaking.
Reported-by: Leon Yu <chianglungyu@gmail.com>
Signed-off-by: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Vince Weaver <vincent.weaver@maine.edu>
Fixes: 130056275ade ("perf: Do not double free")
Link: http://lkml.kernel.org/r/87twk06yxp.fsf@ashishki-desk.ger.corp.intel.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
kernel/events/core.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/kernel/events/core.c b/kernel/events/core.c
index 8c11388..52bedc5 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -8542,6 +8542,7 @@ SYSCALL_DEFINE5(perf_event_open,
f_flags);
if (IS_ERR(event_file)) {
err = PTR_ERR(event_file);
+ event_file = NULL;
goto err_context;
}
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web