linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] events: Reuse value read using READ_ONCE instead of re-reading it
@ 2021-09-06  1:53 Baptiste Lepers
  2021-09-10 16:21 ` Peter Zijlstra
  2021-09-16 11:59 ` [tip: perf/urgent] " tip-bot2 for Baptiste Lepers
  0 siblings, 2 replies; 3+ messages in thread
From: Baptiste Lepers @ 2021-09-06  1:53 UTC (permalink / raw)
  Cc: Baptiste Lepers, Peter Zijlstra, Ingo Molnar,
	Arnaldo Carvalho de Melo, Mark Rutland, Alexander Shishkin,
	Jiri Olsa, Namhyung Kim, Mathieu Poirier, linux-perf-users,
	linux-kernel

In perf_event_addr_filters_apply, the task associated with
the event (event->ctx->task) is read using READ_ONCE at the beginning
of the function, checked, and then re-read from event->ctx->task,
voiding all guarantees of the checks. Reuse the value that was read by
READ_ONCE to ensure the consistency of the task struct throughout the
function.

Signed-off-by: Baptiste Lepers <baptiste.lepers@gmail.com>
Fixes: 375637bc52495 ("perf/core: Introduce address range filtering")
---
 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 744e8726c5b2..0c000cb01eeb 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -10193,7 +10193,7 @@ static void perf_event_addr_filters_apply(struct perf_event *event)
 		return;
 
 	if (ifh->nr_file_filters) {
-		mm = get_task_mm(event->ctx->task);
+		mm = get_task_mm(task);
 		if (!mm)
 			goto restart;
 
-- 
2.17.1


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

* Re: [PATCH] events: Reuse value read using READ_ONCE instead of re-reading it
  2021-09-06  1:53 [PATCH] events: Reuse value read using READ_ONCE instead of re-reading it Baptiste Lepers
@ 2021-09-10 16:21 ` Peter Zijlstra
  2021-09-16 11:59 ` [tip: perf/urgent] " tip-bot2 for Baptiste Lepers
  1 sibling, 0 replies; 3+ messages in thread
From: Peter Zijlstra @ 2021-09-10 16:21 UTC (permalink / raw)
  To: Baptiste Lepers
  Cc: Ingo Molnar, Arnaldo Carvalho de Melo, Mark Rutland,
	Alexander Shishkin, Jiri Olsa, Namhyung Kim, Mathieu Poirier,
	linux-perf-users, linux-kernel

On Mon, Sep 06, 2021 at 11:53:10AM +1000, Baptiste Lepers wrote:
> In perf_event_addr_filters_apply, the task associated with
> the event (event->ctx->task) is read using READ_ONCE at the beginning
> of the function, checked, and then re-read from event->ctx->task,
> voiding all guarantees of the checks. Reuse the value that was read by
> READ_ONCE to ensure the consistency of the task struct throughout the
> function.
> 
> Signed-off-by: Baptiste Lepers <baptiste.lepers@gmail.com>
> Fixes: 375637bc52495 ("perf/core: Introduce address range filtering")

Thanks!

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

* [tip: perf/urgent] events: Reuse value read using READ_ONCE instead of re-reading it
  2021-09-06  1:53 [PATCH] events: Reuse value read using READ_ONCE instead of re-reading it Baptiste Lepers
  2021-09-10 16:21 ` Peter Zijlstra
@ 2021-09-16 11:59 ` tip-bot2 for Baptiste Lepers
  1 sibling, 0 replies; 3+ messages in thread
From: tip-bot2 for Baptiste Lepers @ 2021-09-16 11:59 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: Baptiste Lepers, Peter Zijlstra (Intel), x86, linux-kernel

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

Commit-ID:     b89a05b21f46150ac10a962aa50109250b56b03b
Gitweb:        https://git.kernel.org/tip/b89a05b21f46150ac10a962aa50109250b56b03b
Author:        Baptiste Lepers <baptiste.lepers@gmail.com>
AuthorDate:    Mon, 06 Sep 2021 11:53:10 +10:00
Committer:     Peter Zijlstra <peterz@infradead.org>
CommitterDate: Wed, 15 Sep 2021 17:49:06 +02:00

events: Reuse value read using READ_ONCE instead of re-reading it

In perf_event_addr_filters_apply, the task associated with
the event (event->ctx->task) is read using READ_ONCE at the beginning
of the function, checked, and then re-read from event->ctx->task,
voiding all guarantees of the checks. Reuse the value that was read by
READ_ONCE to ensure the consistency of the task struct throughout the
function.

Fixes: 375637bc52495 ("perf/core: Introduce address range filtering")
Signed-off-by: Baptiste Lepers <baptiste.lepers@gmail.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lkml.kernel.org/r/20210906015310.12802-1-baptiste.lepers@gmail.com
---
 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 744e872..0c000cb 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -10193,7 +10193,7 @@ static void perf_event_addr_filters_apply(struct perf_event *event)
 		return;
 
 	if (ifh->nr_file_filters) {
-		mm = get_task_mm(event->ctx->task);
+		mm = get_task_mm(task);
 		if (!mm)
 			goto restart;
 

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

end of thread, other threads:[~2021-09-16 11:59 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-06  1:53 [PATCH] events: Reuse value read using READ_ONCE instead of re-reading it Baptiste Lepers
2021-09-10 16:21 ` Peter Zijlstra
2021-09-16 11:59 ` [tip: perf/urgent] " tip-bot2 for Baptiste Lepers

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).