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

Subsystems: performance events subsystem, the rest

STALE1820d

2 messages, 2 authors, 2021-09-10 · open the first message on its own page

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

From: Baptiste Lepers <hidden>
Date: 2021-09-06 01:53:23

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 <redacted>
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

Re: [PATCH] events: Reuse value read using READ_ONCE instead of re-reading it

From: Peter Zijlstra <peterz@infradead.org>
Date: 2021-09-10 16:21:21

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 <redacted>
Fixes: 375637bc52495 ("perf/core: Introduce address range filtering")
Thanks!
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help