Skip to contentSkip to conversation

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

PATCH Applied Baptiste Lepers 3 participants 3 messages Sep 6, 2021 – Sep 16, 2021 perf events

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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")
---
 kernel/events/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/events/core.c +1 -1
index 744e8726c5b2..0c000cb01eeb 100644
@@ -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;
 
Signature · 1 line
2.17.1
maintainer
#1 lore raw
Quoted 9 lines · Baptiste Lepers

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

Thanks!

#2 lore raw
In reply to Baptiste Lepers
The following commit has been merged into the perf/urgent branch of tip:

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 <[email protected]>
AuthorDate:    Mon, 06 Sep 2021 11:53:10 +10:00
Committer:     Peter Zijlstra <[email protected]>
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")
---
 kernel/events/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/events/core.c +1 -1
index 744e872..0c000cb 100644
@@ -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;